Skip to content

Commit

Permalink
Merge branch 'fix-regression'
Browse files Browse the repository at this point in the history
* fix-regression:
  Fix bug with new remember token method

Conflicts:
	app/helpers/sessions_helper.rb
  • Loading branch information
mhartl committed Jul 4, 2013
2 parents 508e759 + f1bd829 commit 89b86e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class User < ActiveRecord::Base
has_secure_password
validates :password, length: { minimum: 6 }

def User.new_remember_token
SecureRandom.urlsafe_base64
end

def User.encrypt(token)
Digest::SHA1.hexdigest(token.to_s)
end

def feed
Micropost.from_users_followed_by(self)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/relationships_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:user) { FactoryGirl.create(:user) }
let(:other_user) { FactoryGirl.create(:user) }

before { sign_in user }
before { sign_in user, no_capybara: true }

describe "creating a relationship with Ajax" do

Expand Down
28 changes: 14 additions & 14 deletions spec/requests/authentication_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

describe "signin page" do
before { visit signin_path }

it { should have_content('Sign in') }
it { should have_title('Sign in') }
end

describe "signin" do
before { visit signin_path }

describe "with invalid information" do
before { click_button "Sign in" }

it { should have_title('Sign in') }
it { should have_error_message('Invalid') }

Expand All @@ -33,7 +33,7 @@
fill_in "Password", with: user.password
click_button "Sign in"
end

it { should have_title(user.name) }
it { should have_link('Users', href: users_path) }
it { should have_link('Profile', href: user_path(user)) }
Expand Down Expand Up @@ -62,7 +62,7 @@
end

describe "after signing in" do

it "should render the desired protected page" do
expect(page).to have_title('Edit user')
end
Expand Down Expand Up @@ -90,15 +90,15 @@
before { visit following_user_path(user) }
it { should have_title('Sign in') }
end

describe "visiting the followers page" do
before { visit followers_user_path(user) }
it { should have_title('Sign in') }
end
end

describe "in the Microposts controller" do

describe "submitting to the create action" do
before { post microposts_path }
specify { expect(response).to redirect_to(signin_path) }
Expand All @@ -118,15 +118,15 @@

describe "submitting to the destroy action" do
before { delete relationship_path(1) }
specify { expect(response).to redirect_to(signin_path) }
specify { expect(response).to redirect_to(signin_path) }
end
end
end

describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
before { sign_in user }
before { sign_in user, no_capybara: true }

describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
Expand All @@ -142,13 +142,13 @@
describe "as non-admin user" do
let(:user) { FactoryGirl.create(:user) }
let(:non_admin) { FactoryGirl.create(:user) }
before { sign_in non_admin }

before { sign_in non_admin, no_capybara: true }

describe "submitting a DELETE request to the Users#destroy action" do
before { delete user_path(user) }
specify { expect(response).to redirect_to(root_path) }
specify { expect(response).to redirect_to(root_path) }
end
end
end
end
end
19 changes: 12 additions & 7 deletions spec/support/utilities.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
include ApplicationHelper

def sign_in(user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
# Sign in when not using Capybara as well.
cookies[:remember_token] = user.remember_token
def sign_in(user, options={})
if options[:no_capybara]
# Sign in when not using Capybara as well.
remember_token = User.new_remember_token
cookies[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
else
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
end

RSpec::Matchers.define :have_error_message do |message|
Expand Down

0 comments on commit 89b86e0

Please sign in to comment.