Created
March 8, 2013 15:38
-
-
Save adamphillips/5117287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From bd8aa4106da1aa9f92aafceeac0701b7cf7962bd Mon Sep 17 00:00:00 2001 | |
From: Adam Phillips <[email protected]> | |
Date: Mon, 4 Mar 2013 09:46:49 +0000 | |
Subject: [PATCH 1/2] Modified as shared helper to reduce typing | |
Now that the as helper has had more use, it's become apparent that most | |
cases benefit from using the display_name parameter to describe the kind | |
of user being tested. Therefore, in order to reduce typing, the helper | |
has been changed so that if the second parameter passed is a string, it | |
is taken to be the display name. | |
It is worth noting however that in the cases where multiple keys are | |
used in the hash, for example pre-setting session data, it is then | |
necessary to specify the keys explicitly. See the examples in | |
test/support/helpers/ext/shared.rb for more information. | |
--- | |
.../admins/promo_admin_controller_test.rb | 2 +- | |
.../functional/admins/wizard_controller_test.rb | 2 +- | |
store/test/functional/customer_controller_test.rb | 4 +-- | |
.../functional/mgm/chatters_controller_test.rb | 2 +- | |
.../functional/mgm/magazines_controller_test.rb | 6 ++-- | |
.../functional/mgm/questions_controller_test.rb | 4 +-- | |
.../test/functional/mgm/search_controller_test.rb | 4 +-- | |
.../test/functional/mgm/videos_controller_test.rb | 4 +-- | |
.../test/functional/shops/cart_controller_test.rb | 4 +-- | |
.../functional/shops/open_order_controller_test.rb | 4 +-- | |
store/test/support/helpers/ext/shared.rb | 38 ++++++++++++++++++---- | |
11 files changed, 50 insertions(+), 24 deletions(-) | |
diff --git a/store/test/functional/admins/promo_admin_controller_test.rb b/store/test/functional/admins/promo_admin_controller_test.rb | |
index 979b056..d5101b3 100644 | |
--- a/store/test/functional/admins/promo_admin_controller_test.rb | |
+++ b/store/test/functional/admins/promo_admin_controller_test.rb | |
@@ -15,7 +15,7 @@ class Admins::PromoAdminControllerTest < ActionController::TestCase | |
on UK_SHOP_HOST do | |
action :exclusive do | |
- as :max, :display_name => 'an admin' do | |
+ as :max, 'an admin' do | |
should 'assign the exclusive promos to @promos' do | |
do_request | |
promos = assigns(:promos) | |
diff --git a/store/test/functional/admins/wizard_controller_test.rb b/store/test/functional/admins/wizard_controller_test.rb | |
index a22f264..d9f5198 100644 | |
--- a/store/test/functional/admins/wizard_controller_test.rb | |
+++ b/store/test/functional/admins/wizard_controller_test.rb | |
@@ -2,7 +2,7 @@ require 'test_helper' | |
class Admins::WizardControllerTest < ActionController::TestCase | |
on SCHOLASTIC_HOST do | |
- as :max, :display_name => 'an admin' do | |
+ as :max, 'an admin' do | |
action :destroy_question do | |
context 'when a valid question id is passed' do | |
setup do | |
diff --git a/store/test/functional/customer_controller_test.rb b/store/test/functional/customer_controller_test.rb | |
index b6b7fb1..e22a30e 100644 | |
--- a/store/test/functional/customer_controller_test.rb | |
+++ b/store/test/functional/customer_controller_test.rb | |
@@ -820,7 +820,7 @@ class CustomerControllerTest < ActionController::TestCase | |
on UK_SHOP_HOST do | |
action :remove_school do | |
- as :mildred, :display_name => 'a parent' do | |
+ as :mildred, 'a parent' do | |
setup do | |
assert @current_user.parent.schools.length > 1 | |
@school = @current_user.parent.schools.first | |
@@ -883,7 +883,7 @@ class CustomerControllerTest < ActionController::TestCase | |
end | |
end | |
- as :max, :display_name => 'a teacher' do | |
+ as :max, 'a teacher' do | |
setup do | |
@school = @current_user.schools.first | |
@preferred_school = schools(:eton_school) | |
diff --git a/store/test/functional/mgm/chatters_controller_test.rb b/store/test/functional/mgm/chatters_controller_test.rb | |
index f045f0d..8daeabd 100644 | |
--- a/store/test/functional/mgm/chatters_controller_test.rb | |
+++ b/store/test/functional/mgm/chatters_controller_test.rb | |
@@ -242,7 +242,7 @@ class Mgm::ChattersControllerTest < ActionController::TestCase | |
end | |
on MGM_EN_HOST do | |
- as :benny, :display_name => 'an mgm student' do | |
+ as :benny, 'an mgm student' do | |
setup do | |
@params = {:p_id => @current_user.username} | |
end | |
diff --git a/store/test/functional/mgm/magazines_controller_test.rb b/store/test/functional/mgm/magazines_controller_test.rb | |
index b2e594a..016872b 100644 | |
--- a/store/test/functional/mgm/magazines_controller_test.rb | |
+++ b/store/test/functional/mgm/magazines_controller_test.rb | |
@@ -33,7 +33,7 @@ class Mgm::MagazinesControllerTest < ActionController::TestCase | |
on MGM_EN_HOST do | |
action :show do | |
- as :dustin, :display_name => 'a teacher' do | |
+ as :dustin, 'a teacher' do | |
context 'when viewing a mag with issues and the year specified' do | |
setup do | |
@mag = mgm_mags(:mgm_click_product_mag) | |
@@ -110,7 +110,7 @@ class Mgm::MagazinesControllerTest < ActionController::TestCase | |
end | |
end | |
- as :max, :display_name => 'a student' do | |
+ as :max, 'a student' do | |
context 'when viewing a mag with issues and the year specified' do | |
setup do | |
@mag = mgm_mags(:mgm_click_product_mag) | |
@@ -161,7 +161,7 @@ class Mgm::MagazinesControllerTest < ActionController::TestCase | |
on MGM_ES_HOST do | |
action :show do | |
- as :dustin, :display_name => 'a teacher' do | |
+ as :dustin, 'a teacher' do | |
context 'when viewing a mag with issues and the year specified' do | |
setup do | |
@mag = mgm_mags(:mgm_click_product_mag) | |
diff --git a/store/test/functional/mgm/questions_controller_test.rb b/store/test/functional/mgm/questions_controller_test.rb | |
index e358145..05a6d8e 100644 | |
--- a/store/test/functional/mgm/questions_controller_test.rb | |
+++ b/store/test/functional/mgm/questions_controller_test.rb | |
@@ -34,7 +34,7 @@ class Mgm::QuestionsControllerTest < ActionController::TestCase | |
end | |
action :update, :method => :post do | |
- as :max, :display_name => 'a person with answers' do | |
+ as :max, 'a person with answers' do | |
context 'when answers are given to already answered questions' do | |
setup do | |
@params = {:p_id => @current_user.username, | |
@@ -53,7 +53,7 @@ class Mgm::QuestionsControllerTest < ActionController::TestCase | |
end | |
end | |
- as :benny, :display_name => 'a person without answers' do | |
+ as :benny, 'a person without answers' do | |
context 'when answers are given to unanswered questions' do | |
setup do | |
@params = {:p_id => @current_user.username, | |
diff --git a/store/test/functional/mgm/search_controller_test.rb b/store/test/functional/mgm/search_controller_test.rb | |
index eae4e5a..b120e8e 100644 | |
--- a/store/test/functional/mgm/search_controller_test.rb | |
+++ b/store/test/functional/mgm/search_controller_test.rb | |
@@ -117,7 +117,7 @@ class Mgm::SearchControllerTest < ActionController::TestCase | |
end | |
end | |
- as :dustin, :display_name => 'a teacher' do | |
+ as :dustin, 'a teacher' do | |
should 'display teacher links' do | |
do_request | |
assert_select 'div.resourceBox', 1 do |e| | |
@@ -129,7 +129,7 @@ class Mgm::SearchControllerTest < ActionController::TestCase | |
end | |
end | |
- as :nigel, :display_name => 'a student' do | |
+ as :nigel, 'a student' do | |
should 'display student links' do | |
do_request | |
assert_select 'div.resourceBox', 1 do | |
diff --git a/store/test/functional/mgm/videos_controller_test.rb b/store/test/functional/mgm/videos_controller_test.rb | |
index ae0cdb9..b539b1e 100644 | |
--- a/store/test/functional/mgm/videos_controller_test.rb | |
+++ b/store/test/functional/mgm/videos_controller_test.rb | |
@@ -69,7 +69,7 @@ class Mgm::VideosControllerTest < ActionController::TestCase | |
end | |
on MGM_EN_HOST do | |
- as :bob, :display_name => 'a teacher' do | |
+ as :bob, 'a teacher' do | |
should 'display the expected activities with teacher links' do | |
do_request | |
assert_response :success | |
@@ -170,7 +170,7 @@ class Mgm::VideosControllerTest < ActionController::TestCase | |
end | |
end | |
- as :englishcoach, :display_name => 'a language coach' do | |
+ as :englishcoach, 'a language coach' do | |
on MGM_EN_HOST do | |
setup do | |
@video = assets(:crazy_ryan_video) | |
diff --git a/store/test/functional/shops/cart_controller_test.rb b/store/test/functional/shops/cart_controller_test.rb | |
index 9aac900..a43824e 100644 | |
--- a/store/test/functional/shops/cart_controller_test.rb | |
+++ b/store/test/functional/shops/cart_controller_test.rb | |
@@ -70,7 +70,7 @@ class Shops::CartControllerTest < ActionController::TestCase | |
end | |
end | |
- as :max, :display_name => 'a teacher' do | |
+ as :max, 'a teacher' do | |
setup do | |
@cart = orders(:full_cart) | |
@@ -325,7 +325,7 @@ class Shops::CartControllerTest < ActionController::TestCase | |
end | |
end | |
- as :max, :display_name => 'a teacher' do | |
+ as :max, 'a teacher' do | |
context 'when the order item is commissionable' do | |
context 'when free quantity information is passed' do | |
setup do | |
diff --git a/store/test/functional/shops/open_order_controller_test.rb b/store/test/functional/shops/open_order_controller_test.rb | |
index 2e9aeb1..409eb1b 100644 | |
--- a/store/test/functional/shops/open_order_controller_test.rb | |
+++ b/store/test/functional/shops/open_order_controller_test.rb | |
@@ -65,11 +65,11 @@ class Shops::OpenOrderControllerTest < ActionController::TestCase | |
should_redirect :to => {:controller => '/customer', :action => :login, :return_to => "/open_order/add?open_order[catalogue_number]=9780439971904&open_order[quantity]=4&rewards=Use+Rewards"} | |
end | |
- as :mildred, :display_name => 'a user without a school' do | |
+ as :mildred, 'a user without a school' do | |
should_redirect :to => {:controller => '/shops/pickle_schools', :action => :find_school, :teacher => true, :return_to => "/open_order/add?open_order[catalogue_number]=9780439971904&open_order[quantity]=4&rewards=Use+Rewards"} | |
end | |
- as :max, :display_name => 'a user with a school' do | |
+ as :max, 'a user with a school' do | |
should_redirect :to => {:action => :new} | |
should 'have assigned the correct free quantity to the order' do | |
diff --git a/store/test/support/helpers/ext/shared.rb b/store/test/support/helpers/ext/shared.rb | |
index 46ea1ca..112bb6d 100644 | |
--- a/store/test/support/helpers/ext/shared.rb | |
+++ b/store/test/support/helpers/ext/shared.rb | |
@@ -9,9 +9,10 @@ module Helpers | |
# Shared Contexts that are applicable to both views and controllers | |
module Contexts | |
- # Signs in as the specified person | |
- # The details of the person are kept in the @session variable so this needs to be passed as the | |
- # third parameter when performing an HTTP request in a functional test | |
+ # Signs in as the specified person The details of the person are kept | |
+ # in the @session variable so this needs to be passed as the third | |
+ # parameter when performing an HTTP request in a functional test, | |
+ # however the do_request helper will take care of this | |
# | |
# @example | |
# as :max do | |
@@ -20,11 +21,36 @@ module Helpers | |
# end | |
# end | |
# | |
- # @param[Symbol|Person] person the person to sign in as | |
- # @param[Hash] opts possible options are | |
- # :shop_session hash of additional information to store in the shop session | |
+ # as :max, 'an admin user' do | |
+ # action :index do | |
+ # should 'work' do | |
+ # do_request | |
+ # end | |
+ # end | |
+ # end | |
+ # | |
+ # as :max, :display_name => 'an admin user', :shop_session => {:some_var => 'some_val'} do | |
+ # action :index do | |
+ # should 'work' do | |
+ # do_request | |
+ # end | |
+ # end | |
+ # end | |
+ # | |
+ # @param [Symbol|Person] person The person to sign in as | |
+ # @param [Hash|String] opts A hash of options. Alternatively a | |
+ # string can be passed and this will be used as the display name | |
# | |
+ # @option opts [String] :display_name A descriptive name of the user. | |
+ # This is used because often a test user is chosen as an example | |
+ # of a type of user. Eg an admin user, a banned user etc. If a | |
+ # display_name is set then the test output will say 'as an admin | |
+ # user' rather than 'as max' or 'as steve' | |
+ # @option opts [Hash] :session hash of session data to pre-set | |
+ # @option opts [Hash] :shop_session hash of additional information to | |
+ # store in the shop session | |
def as person, opts={}, &block | |
+ opts = {:display_name => opts} if opts.kind_of? String | |
display_name = opts[:display_name] | |
display_name ||= (person.respond_to?(:display_name)) ? person.display_name : person.to_s | |
-- | |
1.7.12.4 (Apple Git-37) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment