ruby on rails tutorial authorization -


i'm working through latest version of michael hartl's tutorial, , have following message:

failures:

1) userpages edit valid information failure/error: sign_in user nomethoderror: undefined method sign_in' #<rspec::core::examplegroup::nested_4::nested_4::nested_3:0x9f1b1bc> # ./spec/requests/user_pages_spec.rb:66:inblock (3 levels) in '

the same message 9 times.

i ran green until "updating users".

in 9.2 have changed following programs mention in tutorial. trying , trying more 10 hours , gave up. please, me.

juan carrillo

users.controller.rb  class userscontroller < applicationcontroller    before_filter :signed_in_user, only: [:edit, :update]    def new       @user = user.new   end    def show     @user = user.find(params[:id])   end    def create     @user = user.new(params[:user])     if @user.save       sign_in @user       flash[:success] = "welcome sample app!"       redirect_to @user     else       render 'new'     end   end    def show     @user = user.find(params[:id])   end    def edit      @user = user.find(params[:id])   end    def update      @user = user.find(params[:id])     if @user.update_attributes(params[:user])        flash[:success] = "profile updated"        sign_in @user        redirect_to @user      else        render 'edit'     end   end    private    def signed_in_user     redirect_to signin_url, notice: "please sign in." unless signed_in?   end end   authentication_pages_spec.rb 

require 'spec_helper'

describe "authentication" do

subject { page }

describe "signin page" before { visit signin_path }

it { should have_selector('h1', text: 'sign in') } { should have_selector('title', text: 'sign in') }  describe "with valid information"   let(:user){ factorygirl.create(:user) }   before     fill_in "email", with: user.email.upcase     fill_in "password", with: user.password     click_button"sign in"   end   { should have_selector('title', text: user.name) }   { should have_link('profile', href:user_path(user)) }   { should have_link('settings', href:edit_user_path(user)) }   { should have_link('sign out', href:signout_path) }   { should_not have_link('sign in', href:signin_path) }   describe "followed signout"     before { click_link("sign out") }     { should have_link('sign in') }   end end  describe "with invalid information"   before { click_button"sign in"}   { should have_selector('title', text:'sign in') }   { should have_selector('div.alert.alert-error',text: 'invalid') }    describe "after visiting page"     before { click_link"home" }     { should_not have_selector('div.alert.alert-error') }   end end 

end

describe "authorization"  describe "for non-signed-in users"   let(:user) { factorygirl.create(:user) }    describe "in users controller"      describe "visiting edit page"       before { visit edit_user_path(user) }       { should have_selector('title', text: 'sign in') }     end      describe "submitting update action"       before { put user_path(user) }       specify { response.should redirect_to(signin_path) }     end   end end 

end end

user_pages_spec.rb

require 'spec_helper'

describe "userpages" subject { page }

 describe "profile page"      let(:user) { factorygirl.create(:user) }     before { visit user_path(user) }      { should have_selector('h1', text: user.name) }      { should have_selector('title', text: user.name) }   end  describe "signup page"     before { visit signup_path }     { should have_selector('h1', text: 'sign up') }     { should have_selector('title', text: full_title('sign up')) } end  describe "signup"     before { visit signup_path }     let(:submit) { "create account" }      describe "with invalid information"         "should not create user"             expect { click_button submit }.not_to change(user, :count)         end          describe "after submission"             before { click_button submit }              { should have_selector('title', text: 'sign up') }             { should have_content('error') }         end     end      describe "with valid information"         before             fill_in "name", with: "example user"             fill_in "email", with: "user@example.com"             fill_in "password", with: "foobar"             fill_in "confirmation", with: "foobar"         end         "should create user"             expect { click_button submit }.to change(user, :count).by(1)         end          describe "after saving user"             before { click_button submit }             let(:user){ user.find_by_email('user@example.com') }             { should have_selector('title', text: user.name) }             { should have_selector('div.alert.alert-success', text: 'welcome') }              { should have_link('sign out') }          end     end 

end

  describe "edit"     let(:user) { factorygirl.create(:user) }     before         sign_in user         visit edit_user_path(user)     end      describe "page"       { should have_selector('h1',    text: "update profile") }       { should have_selector('title', text: "edit user") }       { should have_link('change', href: 'http://gravatar.com/emails') }     end      describe "with invalid information"       before { click_button "save changes" }        { should have_content('error') }     end      describe "with valid information"         let(:new_name) { "new name" }         let(:new_email) { "new@example.com" }         before             fill_in "name", with: new_name             fill_in "email", with: new_email             fill_in "password", with: user.password             fill_in "confirm password", with: user.password             click_button "save changes"         end         { should have_selector('title', text: new_name) }         { should have_selector('div.alert.alert-success') }         { should have_link('sign out', href:signout_path) }         specify { user.reload.name.should == new_name }         specify { user.reload.email.should == new_email }     end 

end

end

this telling sign_in method has not been defined. need add in in utilities.rb per 9.6 in tutorial


Comments