Skip to content

Commit

Permalink
Continue to work on applying new syntax for rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
oivoodoo committed Jul 28, 2015
1 parent 14309eb commit d31d71a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ group :test do
gem "bson_ext", "~> 1.3"
gem 'sqlite3'

gem 'test-unit'

gem 'pry'
gem 'pry-byebug'

Expand All @@ -18,6 +20,9 @@ group :test do
gem 'guard-cucumber'

gem 'rspec-rails'
gem 'rspec'
gem 'rspec-mocks'

gem 'shoulda'
gem 'rb-fsevent'
gem 'factory_girl_rails'
Expand All @@ -28,4 +33,3 @@ group :test do
gem 'capybara-webkit'
gem 'launchy'
end

5 changes: 2 additions & 3 deletions spec/controllers/admin/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Admin::DashboardController do
describe Admin::DashboardController, type: :controller do
context 'when logged in' do
before { admin_logged_in }

Expand All @@ -12,8 +12,7 @@
get :index, :masquerade => user.masquerade_key
end

it { current_admin_user.reload.should == user }
it { expect(current_admin_user.reload).to eq(user) }
end
end
end

5 changes: 2 additions & 3 deletions spec/controllers/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe DashboardController do
describe DashboardController, type: :controller do
context 'when logged in' do
before { logged_in }

Expand All @@ -13,8 +13,7 @@
get :index, :masquerade => user.masquerade_key
end

it { current_user.reload.should == user }
it { expect(current_user.reload).to eq(user) }
end
end
end

13 changes: 6 additions & 7 deletions spec/controllers/devise/masquerades_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Devise::MasqueradesController do
describe Devise::MasqueradesController, type: :controller do
context 'with configured devise app' do
before { @request.env['devise.mapping'] = Devise.mappings[:user] }

Expand All @@ -11,20 +11,20 @@
let(:mask) { create(:user) }

before do
SecureRandom.should_receive(:urlsafe_base64).and_return("secure_key")
expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" }
get :show, :id => mask.to_param
end

it { session.keys.should include('devise_masquerade_user') }
it { session["warden.user.user.key"].first.first.should == mask.id }
it { expect(session.keys).to include('devise_masquerade_user') }
it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
it { should redirect_to("/?masquerade=secure_key") }

context 'and back' do
before { get :back }

it { should redirect_to(masquerade_page) }
it { current_user.reload.should == @user }
it { session.keys.should_not include('devise_masquerade_user') }
it { expect(current_user.reload).to eq(@user) }
it { expect(session.keys).not_to include('devise_masquerade_user') }
end
end
end
Expand All @@ -41,4 +41,3 @@ def masquerade_page
"/"
end
end

15 changes: 7 additions & 8 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@

describe '#masquerade!' do
it 'should cache special key on masquerade' do
SecureRandom.should_receive(:urlsafe_base64).with(16).and_return("secure_key")
expect(SecureRandom).to receive(:urlsafe_base64).with(16) { "secure_key" }
user.masquerade!
end
end

describe '#remove_masquerade_key' do
before { SecureRandom.stub(:urlsafe_base64).and_return("secure_key") }
before { allow(SecureRandom).to receive(:urlsafe_base64) { "secure_key" } }

let(:key) { 'users:secure_key:masquerade' }

it 'should be possible to remove cached masquerade key' do
user.masquerade!
expect(Rails.cache.exist?(key)).to be_true
expect(Rails.cache.exist?(key)).to eq(true)

User.remove_masquerade_key!('secure_key')
expect(Rails.cache.exist?(key)).to be_false
expect(Rails.cache.exist?(key)).to eq(false)
end
end

describe '#find_by_masquerade_key' do
it 'should be possible to find user by generate masquerade key' do
user.masquerade!

Rails.cache.should_receive(:read).with("users:#{user.masquerade_key}:masquerade").and_return(user.id)
Rails.cache.should_receive(:delete).with("users:#{user.masquerade_key}:masquerade")
allow(Rails.cache).to receive(:read).with("users:#{user.masquerade_key}:masquerade") { user.id }
allow(Rails.cache).to receive(:delete).with("users:#{user.masquerade_key}:masquerade")

new_user = User.find_by_masquerade_key(user.masquerade_key)

new_user.should == user
expect(new_user).to eq(user)
end
end
end

3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
config.include FactoryGirl::Syntax::Methods
config.include Authentication

config.raise_errors_for_deprecations!

config.mock_with :rspec

config.before(:suite) do
Expand All @@ -38,4 +40,3 @@
DatabaseCleaner.clean
end
end

0 comments on commit d31d71a

Please sign in to comment.