Skip to content
Browse files

Made all authentication macros consistent. Now you just use refinery_…

…login_with :factory_name

This means we no longer need to add a new macro every time we add a new type of user.
You just supply the reference to the factory name and the currently logged in
user is available as logged_in_user.

Happy days!
  • Loading branch information...
1 parent 02e53fe commit 4cb87cf3b878a32b160c839ced796bc04c89abc7 @parndt parndt committed
View
10 authentication/spec/controllers/refinery/admin/users_controller_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
describe Refinery::Admin::UsersController do
- login_refinery_superuser
+ refinery_login_with :refinery_superuser
shared_examples_for "new, create, update, edit and update actions" do
it "loads roles" do
@@ -51,7 +51,7 @@
describe "#edit" do
it "renders the edit template" do
- get :edit, :id => "1"
+ get :edit, :id => logged_in_user.id
response.should be_success
response.should render_template("refinery/admin/users/edit")
end
@@ -60,10 +60,10 @@
end
describe "#update" do
+ let(:additional_user) { FactoryGirl.create :refinery_user }
it "updates a user" do
- user = FactoryGirl.create(:refinery_user)
- Refinery::User.should_receive(:find).at_least(1).times{ user }
- put "update", :id => user.id.to_s, :user => {}
+ Refinery::User.should_receive(:find).at_least(1).times{ additional_user }
+ put "update", :id => additional_user.id.to_s, :user => {}
response.should be_redirect
end
View
2 authentication/spec/requests/refinery/admin/users_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
describe "User admin page" do
- login_refinery_superuser
+ refinery_login_with :refinery_superuser
describe "new/create" do
def visit_and_fill_form
View
2 ...tors/refinery/engine/templates/spec/requests/refinery/namespace/admin/plural_name_spec.rb
@@ -5,7 +5,7 @@
describe "<%= namespacing %>" do
describe "Admin" do
describe "<%= plural_name %>" do
- login_refinery_user
+ refinery_login_with :refinery_user
<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
describe "<%= plural_name %> list" do
before(:each) do
View
7 core/spec/controllers/refinery/admin/refinery_core_controller_spec.rb
@@ -3,15 +3,14 @@
module Refinery
module Admin
describe RefineryCoreController do
- login_refinery_user
+ refinery_login_with :refinery_user
it "should update the plugin positions" do
- plugins = @refinery_user.plugins.reverse.collect {|p| p.name}
+ plugins = logged_in_user.plugins.reverse.map(&:name)
post 'update_plugin_positions', :menu => plugins
- @refinery_user.plugins.reload
- @refinery_user.plugins.each_with_index do |plugin, idx|
+ logged_in_user.plugins.reload.each_with_index do |plugin, idx|
plugin.name.should eql(plugins[idx])
end
end
View
2 core/spec/controllers/refinery/sitemap_controller_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe SitemapController do
- login_refinery_user
+ refinery_login_with :refinery_user
before (:each) do
@request.env['HTTP_ACCEPT'] = 'application/xml'
View
2 core/spec/requests/refinery/admin/custom_assets_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe "custom" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "javascripts" do
before(:each) do
View
2 core/spec/requests/refinery/admin/dialogs_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe "dialog" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "links" do
it "have iframe src" do
View
2 core/spec/requests/refinery/search_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe "search" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "when searched item exists" do
describe "image extension" do
View
2 core/spec/requests/refinery/site_bar_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe "site bar" do
- login_refinery_user
+ refinery_login_with :refinery_user
it "have logout link" do
visit refinery.admin_dashboard_path
View
9 dashboard/spec/requests/refinery/admin/dashboard_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
describe "dashboard" do
- login_refinery_user
+ refinery_login_with :refinery_user
describe "quick tasks" do
specify "buttons" do
@@ -33,15 +33,14 @@
describe "latest activity" do
before(:each) do
- 3.times { |n| FactoryGirl.create(:refinery_user, :username => "ugisozols#{n}") }
- 3.times { |n| FactoryGirl.create(:page, :title => "Refinery CMS #{n}") }
+ 3.times { |n| FactoryGirl.create :refinery_user, :username => "ugisozols#{n}" }
+ 3.times { |n| FactoryGirl.create :page, :title => "Refinery CMS #{n}" }
end
- it "shows 7 recent actions" do
+ it "shows created tracked objects" do
visit refinery.admin_dashboard_path
page.should have_content("Latest Activity")
- page.should have_content("#{logged_in_user.username.capitalize} user was updated")
3.times { |n| page.should have_content("Ugisozols#{n} user was added") }
3.times { |n| page.should have_content("Refinery cms #{n} page was added") }
end
View
2 images/spec/requests/refinery/admin/images_spec.rb
@@ -2,7 +2,7 @@
module Refinery
describe "AdminImages" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "when no images" do
it "invites to add one" do
View
4 pages/spec/requests/refinery/admin/pages_spec.rb
@@ -11,7 +11,7 @@ def new_window_should_have_content(content)
module Refinery
module Admin
describe "Pages" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "when no pages" do
it "invites to create one" do
@@ -500,7 +500,7 @@ module Admin
end
describe "TranslatePages" do
- login_refinery_translator
+ refinery_login_with :refinery_translator
describe "add page to main locale" do
it "doesn't succeed" do
View
2 resources/spec/requests/refinery/admin/resources_spec.rb
@@ -4,7 +4,7 @@
module Refinery
module Admin
describe "Resources" do
- login_refinery_user
+ refinery_login_with :refinery_user
context "when no files" do
it "invites to upload file" do
View
32 testing/lib/refinery/testing/controller_macros/authentication.rb
@@ -6,36 +6,32 @@ def self.extended(base)
base.send(:include, Devise::TestHelpers)
end
- def login_user
+ def refinery_login_with(factory)
+ let(:logged_in_user) { FactoryGirl.create factory }
before(:each) do
- @user = FactoryGirl.create(:user)
@request.env["devise.mapping"] = Devise.mappings[:admin]
- sign_in @user
+ sign_in logged_in_user
end
end
+ def login_user
+ Refinery.deprecate(:login_user, :when => '2.2', :replacement => 'refinery_login_with :user')
+ refinery_login_with :user
+ end
+
def login_refinery_user
- before(:each) do
- @refinery_user = FactoryGirl.create(:refinery_user)
- @request.env["devise.mapping"] = Devise.mappings[:admin]
- sign_in @refinery_user
- end
+ Refinery.deprecate(:login_refinery_user, :when => '2.2', :replacement => 'refinery_login_with :refinery_user')
+ refinery_login_with :refinery_user
end
def login_refinery_superuser
- before(:each) do
- @refinery_superuser = FactoryGirl.create(:refinery_superuser)
- @request.env["devise.mapping"] = Devise.mappings[:admin]
- sign_in @refinery_superuser
- end
+ Refinery.deprecate(:login_refinery_superuser, :when => '2.2', :replacement => 'refinery_login_with :refinery_superuser')
+ refinery_login_with :refinery_superuser
end
def login_refinery_translator
- before(:each) do
- @refinery_translator = FactoryGirl.create(:refinery_translator)
- @request.env["devise.mapping"] = Devise.mappings[:admin]
- sign_in @refinery_translator
- end
+ Refinery.deprecate(:login_refinery_translator, :when => '2.2', :replacement => 'refinery_login_with :refinery_translator')
+ refinery_login_with :refinery_translator
end
end
end
View
11 testing/lib/refinery/testing/request_macros/authentication.rb
@@ -2,7 +2,7 @@ module Refinery
module Testing
module RequestMacros
module Authentication
- def login_with(factory)
+ def refinery_login_with(factory)
let!(:logged_in_user) { Factory.create(factory) }
before do
@@ -11,15 +11,18 @@ def login_with(factory)
end
def login_refinery_user
- login_with(:refinery_user)
+ Refinery.deprecate(:login_refinery_user, :when => '2.2', :replacement => 'refinery_login_with :refinery_user')
+ refinery_login_with(:refinery_user)
end
def login_refinery_superuser
- login_with(:refinery_superuser)
+ Refinery.deprecate(:login_refinery_superuser, :when => '2.2', :replacement => 'refinery_login_with :refinery_superuser')
+ refinery_login_with(:refinery_superuser)
end
def login_refinery_translator
- login_with(:refinery_translator)
+ Refinery.deprecate(:login_refinery_translator, :when => '2.2', :replacement => 'refinery_login_with :refinery_translator')
+ refinery_login_with(:refinery_translator)
end
end
end

0 comments on commit 4cb87cf

Please sign in to comment.
Something went wrong with that request. Please try again.