janova-clearance 0.8.8 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG.md +11 -2
  2. data/README.md +34 -35
  3. data/Rakefile +79 -33
  4. data/VERSION +1 -1
  5. data/app/controllers/clearance/confirmations_controller.rb +0 -2
  6. data/app/controllers/clearance/passwords_controller.rb +1 -2
  7. data/app/controllers/clearance/sessions_controller.rb +1 -2
  8. data/app/controllers/clearance/users_controller.rb +0 -1
  9. data/app/models/clearance_mailer.rb +4 -4
  10. data/app/views/passwords/edit.html.erb +1 -1
  11. data/app/views/passwords/new.html.erb +2 -2
  12. data/app/views/sessions/new.html.erb +1 -1
  13. data/app/views/users/_form.html.erb +1 -1
  14. data/app/views/users/new.html.erb +1 -1
  15. data/clearance.gemspec +207 -0
  16. data/config/routes.rb +23 -0
  17. data/cucumber.yml +4 -0
  18. data/{rails/init.rb → init.rb} +0 -0
  19. data/lib/clearance.rb +2 -1
  20. data/lib/clearance/authentication.rb +2 -2
  21. data/lib/clearance/configuration.rb +10 -3
  22. data/lib/clearance/engine.rb +10 -0
  23. data/{shoulda_macros/clearance.rb → lib/clearance/shoulda_macros.rb} +11 -23
  24. data/lib/clearance/user.rb +5 -6
  25. data/lib/rails/generators/clearance_features_generator.rb +20 -0
  26. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/password_reset.feature +1 -1
  27. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_in.feature +0 -0
  28. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_out.feature +0 -0
  29. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_up.feature +0 -0
  30. data/lib/rails/generators/clearance_features_templates/features/step_definitions/clearance_steps.rb +138 -0
  31. data/lib/rails/generators/clearance_generator.rb +72 -0
  32. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/README +0 -0
  33. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/clearance.rb +0 -0
  34. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/factories.rb +0 -0
  35. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/create_users.rb +0 -1
  36. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/update_users.rb +0 -1
  37. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/user.rb +0 -0
  38. data/lib/rails/generators/clearance_views_generator.rb +14 -0
  39. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/edit.html.erb +3 -3
  40. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/new.html.erb +3 -3
  41. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/sessions/new.html.erb +3 -3
  42. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/_inputs.html.erb +1 -1
  43. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/new.html.erb +2 -2
  44. data/spec/rails_root/Gemfile +15 -0
  45. data/spec/rails_root/README +244 -0
  46. data/spec/rails_root/Rakefile +10 -0
  47. data/spec/rails_root/app/controllers/accounts_controller.rb +10 -0
  48. data/spec/rails_root/app/controllers/application_controller.rb +6 -0
  49. data/spec/rails_root/app/helpers/application_helper.rb +2 -0
  50. data/spec/rails_root/app/models/user.rb +3 -0
  51. data/{generators/clearance_views/USAGE → spec/rails_root/app/views/accounts/edit.html.erb} +0 -0
  52. data/spec/rails_root/app/views/layouts/application.html.erb +24 -0
  53. data/spec/rails_root/config.ru +4 -0
  54. data/spec/rails_root/config/application.rb +46 -0
  55. data/spec/rails_root/config/boot.rb +6 -0
  56. data/spec/rails_root/config/cucumber.yml +8 -0
  57. data/spec/rails_root/config/database.yml +25 -0
  58. data/spec/rails_root/config/environment.rb +7 -0
  59. data/spec/rails_root/config/environments/development.rb +21 -0
  60. data/spec/rails_root/config/environments/production.rb +42 -0
  61. data/spec/rails_root/config/environments/test.rb +34 -0
  62. data/spec/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/rails_root/config/initializers/clearance.rb +3 -0
  64. data/spec/rails_root/config/initializers/inflections.rb +10 -0
  65. data/spec/rails_root/config/initializers/mime_types.rb +5 -0
  66. data/spec/rails_root/config/initializers/secret_token.rb +7 -0
  67. data/spec/rails_root/config/initializers/session_store.rb +8 -0
  68. data/spec/rails_root/config/locales/en.yml +5 -0
  69. data/spec/rails_root/config/routes.rb +61 -0
  70. data/spec/rails_root/db/schema.rb +29 -0
  71. data/spec/rails_root/doc/README_FOR_APP +2 -0
  72. data/spec/rails_root/features/password_reset.feature +33 -0
  73. data/spec/rails_root/features/sign_in.feature +35 -0
  74. data/spec/rails_root/features/sign_out.feature +15 -0
  75. data/spec/rails_root/features/sign_up.feature +45 -0
  76. data/{generators/clearance_features/templates → spec/rails_root}/features/step_definitions/clearance_steps.rb +18 -7
  77. data/spec/rails_root/features/step_definitions/web_steps.rb +219 -0
  78. data/spec/rails_root/features/support/env.rb +57 -0
  79. data/spec/rails_root/features/support/paths.rb +45 -0
  80. data/spec/rails_root/lib/tasks/cucumber.rake +53 -0
  81. data/spec/rails_root/public/404.html +26 -0
  82. data/spec/rails_root/public/422.html +26 -0
  83. data/spec/rails_root/public/500.html +26 -0
  84. data/spec/rails_root/public/favicon.ico +0 -0
  85. data/spec/rails_root/public/images/rails.png +0 -0
  86. data/spec/rails_root/public/javascripts/application.js +2 -0
  87. data/spec/rails_root/public/javascripts/controls.js +965 -0
  88. data/spec/rails_root/public/javascripts/dragdrop.js +974 -0
  89. data/spec/rails_root/public/javascripts/effects.js +1123 -0
  90. data/spec/rails_root/public/javascripts/prototype.js +4874 -0
  91. data/spec/rails_root/public/javascripts/rails.js +118 -0
  92. data/spec/rails_root/public/robots.txt +5 -0
  93. data/spec/rails_root/script/cucumber +10 -0
  94. data/spec/rails_root/script/rails +9 -0
  95. data/spec/rails_root/spec/factories/clearance.rb +13 -0
  96. data/spec/rails_root/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
  97. data/spec/rails_root/vendor/plugins/dynamic_form/README +13 -0
  98. data/spec/rails_root/vendor/plugins/dynamic_form/Rakefile +10 -0
  99. data/spec/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
  100. data/spec/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
  101. data/spec/rails_root/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
  102. data/spec/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
  103. data/spec/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
  104. data/spec/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
  105. data/test/controllers/confirmations_controller_test.rb +10 -7
  106. data/test/controllers/passwords_controller_test.rb +16 -20
  107. data/test/controllers/sessions_controller_test.rb +59 -20
  108. data/test/controllers/users_controller_test.rb +19 -16
  109. data/test/models/clearance_mailer_test.rb +2 -2
  110. data/test/models/user_test.rb +14 -13
  111. data/test/rails_root/Gemfile +17 -0
  112. data/test/rails_root/README +244 -0
  113. data/test/rails_root/Rakefile +10 -0
  114. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  115. data/test/rails_root/app/models/user.rb +3 -0
  116. data/test/rails_root/app/views/accounts/edit.html.erb +0 -0
  117. data/test/rails_root/app/views/layouts/application.html.erb +24 -0
  118. data/test/rails_root/config.ru +4 -0
  119. data/test/rails_root/config/application.rb +46 -0
  120. data/test/rails_root/config/boot.rb +5 -109
  121. data/test/rails_root/config/cucumber.yml +8 -0
  122. data/test/rails_root/config/database.yml +25 -0
  123. data/test/rails_root/config/environment.rb +5 -15
  124. data/test/rails_root/config/environments/development.rb +16 -14
  125. data/test/rails_root/config/environments/production.rb +42 -1
  126. data/test/rails_root/config/environments/test.rb +34 -36
  127. data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  128. data/test/rails_root/config/initializers/inflections.rb +1 -1
  129. data/test/rails_root/config/initializers/secret_token.rb +7 -0
  130. data/test/rails_root/config/initializers/session_store.rb +8 -0
  131. data/test/rails_root/config/locales/en.yml +5 -0
  132. data/test/rails_root/config/routes.rb +59 -4
  133. data/test/rails_root/doc/README_FOR_APP +2 -0
  134. data/test/rails_root/features/step_definitions/web_steps.rb +125 -165
  135. data/test/rails_root/features/support/env.rb +24 -14
  136. data/test/rails_root/features/support/paths.rb +45 -0
  137. data/test/rails_root/lib/tasks/cucumber.rake +53 -0
  138. data/test/rails_root/public/404.html +26 -0
  139. data/test/rails_root/public/422.html +26 -0
  140. data/test/rails_root/public/500.html +26 -0
  141. data/test/rails_root/public/favicon.ico +0 -0
  142. data/test/rails_root/public/images/rails.png +0 -0
  143. data/test/rails_root/public/javascripts/application.js +2 -0
  144. data/test/rails_root/public/javascripts/controls.js +965 -0
  145. data/test/rails_root/public/javascripts/dragdrop.js +974 -0
  146. data/test/rails_root/public/javascripts/effects.js +1123 -0
  147. data/test/rails_root/public/javascripts/prototype.js +4874 -0
  148. data/test/rails_root/public/javascripts/rails.js +118 -0
  149. data/test/rails_root/public/robots.txt +5 -0
  150. data/test/rails_root/script/cucumber +10 -0
  151. data/test/rails_root/script/rails +9 -0
  152. data/test/rails_root/test/factories/clearance.rb +13 -0
  153. data/test/rails_root/test/functional/accounts_controller_test.rb +0 -1
  154. data/test/rails_root/test/performance/browsing_test.rb +9 -0
  155. data/test/rails_root/test/test_helper.rb +13 -0
  156. data/test/rails_root/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
  157. data/test/rails_root/vendor/plugins/dynamic_form/README +13 -0
  158. data/test/rails_root/vendor/plugins/dynamic_form/Rakefile +10 -0
  159. data/test/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
  160. data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
  161. data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
  162. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
  163. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
  164. data/test/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
  165. data/test/test_helper.rb +31 -2
  166. metadata +273 -61
  167. data/generators/clearance/USAGE +0 -1
  168. data/generators/clearance/clearance_generator.rb +0 -68
  169. data/generators/clearance/lib/insert_commands.rb +0 -33
  170. data/generators/clearance/lib/rake_commands.rb +0 -22
  171. data/generators/clearance_features/USAGE +0 -1
  172. data/generators/clearance_features/clearance_features_generator.rb +0 -19
  173. data/generators/clearance_features/templates/features/support/paths.rb +0 -23
  174. data/generators/clearance_views/clearance_views_generator.rb +0 -27
  175. data/lib/clearance/routes.rb +0 -49
  176. data/test/rails_root/app/helpers/confirmations_helper.rb +0 -2
  177. data/test/rails_root/app/helpers/passwords_helper.rb +0 -2
  178. data/test/rails_root/config/initializers/requires.rb +0 -13
  179. data/test/rails_root/config/initializers/time_formats.rb +0 -4
  180. data/test/rails_root/public/dispatch.rb +0 -10
  181. data/test/rails_root/script/create_project.rb +0 -52
  182. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +0 -21
  183. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +0 -1236
  184. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +0 -10
  185. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +0 -3
  186. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +0 -2900
  187. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +0 -14
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Rails.application.config.secret_token = 'b0a71f62c3707fe6874a435909a597203110c418dc3022773b5131e2a26a99b304010089bd3ebb92e206b3b94a883aeefa571a8a52a45160f8663d163786610c'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, :key => '_rails3_root_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rake db:sessions:create")
8
+ # Rails.application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -1,6 +1,61 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- map.resource :account
3
- map.root :controller => 'accounts', :action => 'edit'
1
+ Rails3Root::Application.routes.draw do
2
+ resource :account
3
+ root :to => 'accounts#edit'
4
4
 
5
- Clearance::Routes.draw(map)
5
+ # The priority is based upon order of creation:
6
+ # first created -> highest priority.
7
+
8
+ # Sample of regular route:
9
+ # match 'products/:id' => 'catalog#view'
10
+ # Keep in mind you can assign values other than :controller and :action
11
+
12
+ # Sample of named route:
13
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
14
+ # This route can be invoked with purchase_url(:id => product.id)
15
+
16
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
17
+ # resources :products
18
+
19
+ # Sample resource route with options:
20
+ # resources :products do
21
+ # member do
22
+ # get :short
23
+ # post :toggle
24
+ # end
25
+ #
26
+ # collection do
27
+ # get :sold
28
+ # end
29
+ # end
30
+
31
+ # Sample resource route with sub-resources:
32
+ # resources :products do
33
+ # resources :comments, :sales
34
+ # resource :seller
35
+ # end
36
+
37
+ # Sample resource route with more complex sub-resources
38
+ # resources :products do
39
+ # resources :comments
40
+ # resources :sales do
41
+ # get :recent, :on => :collection
42
+ # end
43
+ # end
44
+
45
+ # Sample resource route within a namespace:
46
+ # namespace :admin do
47
+ # # Directs /admin/products/* to Admin::ProductsController
48
+ # # (app/controllers/admin/products_controller.rb)
49
+ # resources :products
50
+ # end
51
+
52
+ # You can have the root of your site routed with "root"
53
+ # just remember to delete public/index.html.
54
+ # root :to => "welcome#index"
55
+
56
+ # See how all your routes lay out with "rake routes"
57
+
58
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
59
+ # Note: This route will make all actions in every controller accessible via GET requests.
60
+ # match ':controller(/:action(/:id(.:format)))'
6
61
  end
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
@@ -1,14 +1,20 @@
1
1
  # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
7
7
 
8
+ require 'uri'
9
+ require 'cgi'
8
10
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
9
11
 
10
- # Commonly used webrat steps
11
- # http://github.com/brynary/webrat
12
+ module WithinHelpers
13
+ def with_scope(locator)
14
+ locator ? within(locator) { yield } : yield
15
+ end
16
+ end
17
+ World(WithinHelpers)
12
18
 
13
19
  Given /^(?:|I )am on (.+)$/ do |page_name|
14
20
  visit path_to(page_name)
@@ -18,24 +24,28 @@ When /^(?:|I )go to (.+)$/ do |page_name|
18
24
  visit path_to(page_name)
19
25
  end
20
26
 
21
- When /^(?:|I )press "([^\"]*)"$/ do |button|
22
- click_button(button)
23
- end
24
-
25
- When /^(?:|I )follow "([^\"]*)"$/ do |link|
26
- click_link(link)
27
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
28
+ with_scope(selector) do
29
+ click_button(button)
30
+ end
27
31
  end
28
32
 
29
- When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
30
- click_link_within(parent, link)
33
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
34
+ with_scope(selector) do
35
+ click_link(link)
36
+ end
31
37
  end
32
38
 
33
- When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
34
- fill_in(field, :with => value)
39
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
40
+ with_scope(selector) do
41
+ fill_in(field, :with => value)
42
+ end
35
43
  end
36
44
 
37
- When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
38
- fill_in(field, :with => value)
45
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
46
+ with_scope(selector) do
47
+ fill_in(field, :with => value)
48
+ end
39
49
  end
40
50
 
41
51
  # Use this to fill in an entire form with data from a table. Example:
@@ -49,211 +59,161 @@ end
49
59
  # TODO: Add support for checkbox, select og option
50
60
  # based on naming conventions.
51
61
  #
52
- When /^(?:|I )fill in the following:$/ do |fields|
53
- fields.rows_hash.each do |name, value|
54
- When %{I fill in "#{name}" with "#{value}"}
62
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
63
+ with_scope(selector) do
64
+ fields.rows_hash.each do |name, value|
65
+ When %{I fill in "#{name}" with "#{value}"}
66
+ end
55
67
  end
56
68
  end
57
69
 
58
- When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
59
- select(value, :from => field)
60
- end
61
-
62
- # Use this step in conjunction with Rail's datetime_select helper. For example:
63
- # When I select "December 25, 2008 10:00" as the date and time
64
- When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
65
- select_datetime(time)
66
- end
67
-
68
- # Use this step when using multiple datetime_select helpers on a page or
69
- # you want to specify which datetime to select. Given the following view:
70
- # <%= f.label :preferred %><br />
71
- # <%= f.datetime_select :preferred %>
72
- # <%= f.label :alternative %><br />
73
- # <%= f.datetime_select :alternative %>
74
- # The following steps would fill out the form:
75
- # When I select "November 23, 2004 11:20" as the "Preferred" date and time
76
- # And I select "November 25, 2004 10:30" as the "Alternative" date and time
77
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
78
- select_datetime(datetime, :from => datetime_label)
79
- end
80
-
81
- # Use this step in conjunction with Rail's time_select helper. For example:
82
- # When I select "2:20PM" as the time
83
- # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
84
- # will convert the 2:20PM to 14:20 and then select it.
85
- When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
86
- select_time(time)
87
- end
88
-
89
- # Use this step when using multiple time_select helpers on a page or you want to
90
- # specify the name of the time on the form. For example:
91
- # When I select "7:30AM" as the "Gym" time
92
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
93
- select_time(time, :from => time_label)
94
- end
95
-
96
- # Use this step in conjunction with Rail's date_select helper. For example:
97
- # When I select "February 20, 1981" as the date
98
- When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
99
- select_date(date)
100
- end
101
-
102
- # Use this step when using multiple date_select helpers on one page or
103
- # you want to specify the name of the date on the form. For example:
104
- # When I select "April 26, 1982" as the "Date of Birth" date
105
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
106
- select_date(date, :from => date_label)
70
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
71
+ with_scope(selector) do
72
+ select(value, :from => field)
73
+ end
107
74
  end
108
75
 
109
- When /^(?:|I )check "([^\"]*)"$/ do |field|
110
- check(field)
76
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
77
+ with_scope(selector) do
78
+ check(field)
79
+ end
111
80
  end
112
81
 
113
- When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
114
- uncheck(field)
82
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
83
+ with_scope(selector) do
84
+ uncheck(field)
85
+ end
115
86
  end
116
87
 
117
- When /^(?:|I )choose "([^\"]*)"$/ do |field|
118
- choose(field)
88
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
89
+ with_scope(selector) do
90
+ choose(field)
91
+ end
119
92
  end
120
93
 
121
- # Adds support for validates_attachment_content_type. Without the mime-type getting
122
- # passed to attach_file() you will get a "Photo file is not one of the allowed file types."
123
- # error message
124
- When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
125
- type = path.split(".")[1]
126
-
127
- case type
128
- when "jpg"
129
- type = "image/jpg"
130
- when "jpeg"
131
- type = "image/jpeg"
132
- when "png"
133
- type = "image/png"
134
- when "gif"
135
- type = "image/gif"
94
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
95
+ with_scope(selector) do
96
+ attach_file(field, path)
136
97
  end
137
-
138
- attach_file(field, path, type)
139
98
  end
140
99
 
141
- Then /^(?:|I )should see "([^\"]*)"$/ do |text|
142
- if defined?(Spec::Rails::Matchers)
143
- response.should contain(text)
144
- else
145
- assert_contain text
146
- end
100
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
101
+ require 'json'
102
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
103
+ actual = JSON.pretty_generate(JSON.parse(response.body))
104
+ expected.should == actual
147
105
  end
148
106
 
149
- Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
150
- within(selector) do |content|
151
- if defined?(Spec::Rails::Matchers)
152
- content.should contain(text)
107
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
108
+ with_scope(selector) do
109
+ if page.respond_to? :should
110
+ page.should have_content(text)
153
111
  else
154
- assert content.include?(text)
112
+ assert page.has_content?(text)
155
113
  end
156
114
  end
157
115
  end
158
116
 
159
- Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
117
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
160
118
  regexp = Regexp.new(regexp)
161
- if defined?(Spec::Rails::Matchers)
162
- response.should contain(regexp)
163
- else
164
- assert_contain regexp
165
- end
166
- end
167
-
168
- Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
169
- within(selector) do |content|
170
- regexp = Regexp.new(regexp)
171
- if defined?(Spec::Rails::Matchers)
172
- content.should contain(regexp)
119
+ with_scope(selector) do
120
+ if page.respond_to? :should
121
+ page.should have_xpath('//*', :text => regexp)
173
122
  else
174
- assert content =~ regexp
123
+ assert page.has_xpath?('//*', :text => regexp)
175
124
  end
176
125
  end
177
126
  end
178
127
 
179
- Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
180
- if defined?(Spec::Rails::Matchers)
181
- response.should_not contain(text)
182
- else
183
- assert_not_contain text
184
- end
185
- end
186
-
187
- Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
188
- within(selector) do |content|
189
- if defined?(Spec::Rails::Matchers)
190
- content.should_not contain(text)
128
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
129
+ with_scope(selector) do
130
+ if page.respond_to? :should
131
+ page.should have_no_content(text)
191
132
  else
192
- assert !content.include?(text)
133
+ assert page.has_no_content?(text)
193
134
  end
194
135
  end
195
136
  end
196
137
 
197
- Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
138
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
198
139
  regexp = Regexp.new(regexp)
199
- if defined?(Spec::Rails::Matchers)
200
- response.should_not contain(regexp)
201
- else
202
- assert_not_contain regexp
140
+ with_scope(selector) do
141
+ if page.respond_to? :should
142
+ page.should have_no_xpath('//*', :text => regexp)
143
+ else
144
+ assert page.has_no_xpath?('//*', :text => regexp)
145
+ end
203
146
  end
204
147
  end
205
148
 
206
- Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
207
- within(selector) do |content|
208
- regexp = Regexp.new(regexp)
209
- if defined?(Spec::Rails::Matchers)
210
- content.should_not contain(regexp)
149
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
150
+ with_scope(selector) do
151
+ field = find_field(field)
152
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
153
+ if field_value.respond_to? :should
154
+ field_value.should =~ /#{value}/
211
155
  else
212
- assert content !~ regexp
156
+ assert_match(/#{value}/, field_value)
213
157
  end
214
158
  end
215
159
  end
216
160
 
217
- Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
218
- if defined?(Spec::Rails::Matchers)
219
- field_labeled(field).value.should =~ /#{value}/
220
- else
221
- assert_match(/#{value}/, field_labeled(field).value)
161
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
162
+ with_scope(selector) do
163
+ field = find_field(field)
164
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
165
+ if field_value.respond_to? :should_not
166
+ field_value.should_not =~ /#{value}/
167
+ else
168
+ assert_no_match(/#{value}/, field_value)
169
+ end
222
170
  end
223
171
  end
224
172
 
225
- Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
226
- if defined?(Spec::Rails::Matchers)
227
- field_labeled(field).value.should_not =~ /#{value}/
228
- else
229
- assert_no_match(/#{value}/, field_labeled(field).value)
173
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
174
+ with_scope(selector) do
175
+ field_checked = find_field(label)['checked']
176
+ if field_checked.respond_to? :should
177
+ field_checked.should be_true
178
+ else
179
+ assert field_checked
180
+ end
230
181
  end
231
182
  end
232
183
 
233
- Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
234
- if defined?(Spec::Rails::Matchers)
235
- field_labeled(label).should be_checked
236
- else
237
- assert field_labeled(label).checked?
184
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
185
+ with_scope(selector) do
186
+ field_checked = find_field(label)['checked']
187
+ if field_checked.respond_to? :should
188
+ field_checked.should be_false
189
+ else
190
+ assert !field_checked
191
+ end
238
192
  end
239
193
  end
240
-
241
- Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
242
- if defined?(Spec::Rails::Matchers)
243
- field_labeled(label).should_not be_checked
194
+
195
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
196
+ current_path = URI.parse(current_url).path
197
+ if current_path.respond_to? :should
198
+ current_path.should == path_to(page_name)
244
199
  else
245
- assert !field_labeled(label).checked?
200
+ assert_equal path_to(page_name), current_path
246
201
  end
247
202
  end
248
203
 
249
- Then /^(?:|I )should be on (.+)$/ do |page_name|
250
- if defined?(Spec::Rails::Matchers)
251
- URI.parse(current_url).path.should == path_to(page_name)
204
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205
+ query = URI.parse(current_url).query
206
+ actual_params = query ? CGI.parse(query) : {}
207
+ expected_params = {}
208
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
+
210
+ if actual_params.respond_to? :should
211
+ actual_params.should == expected_params
252
212
  else
253
- assert_equal path_to(page_name), URI.parse(current_url).path
213
+ assert_equal expected_params, actual_params
254
214
  end
255
215
  end
256
216
 
257
217
  Then /^show me the page$/ do
258
218
  save_and_open_page
259
- end
219
+ end