effective_test_bot 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8daba6efe86cb1bdf02b6894c786581de4b1a0d1
4
- data.tar.gz: d894f71336ba73f58c5bc968b5eae7e69272f476
3
+ metadata.gz: e103116aeed8578d3cb62239ab87759208152860
4
+ data.tar.gz: a4978f5794f46d577111f8bbfbfbf32c0aafa9d6
5
5
  SHA512:
6
- metadata.gz: 1d76c1ec917029ebed79bbb2b8c457573cc699aed07b45957831be86f0edddd08aea345054a29a89e5f799866071cc79d10a6abdad1ee21b4b7e91365e8ae2fd
7
- data.tar.gz: 0602b7675e99bffc14cf809230532d2277c4285a11f069ead884f92c4c2575b6c3018f3ccb55e35732565246343fe8fb6b6b4df415457229e60e70b5eec66d03
6
+ metadata.gz: a18ae0e701b4e5abcd1275070c9347c10116b626896c6b59edcb7bfe2dcdfd987e7cf17a1fad08b8f6879b4de3eaa0182ccd81603d8f7b22e4108f84d56f0d92
7
+ data.tar.gz: c764261c4bbfbef91ac98864877dbae1f2e549b24b3cc01ed215a934c14cc3c68891fa821ea6367ddd5ef89e8af6d1cfa242b8f742b2fccf5ad300d6b6e0a7aa
@@ -22,4 +22,12 @@ module EffectiveTestBotControllerHelper
22
22
 
23
23
  response.headers['Test-Bot-Assigns'] = Base64.encode64(test_bot_assigns.to_hash.to_json)
24
24
  end
25
+
26
+ # We get here if ApplicationController raised a ActionController::UnpermittedParameters error
27
+ def assign_test_bot_unpermitted_params_headers(exception)
28
+ if exception.kind_of?(ActionController::UnpermittedParameters)
29
+ response.headers['Test-Bot-Unpermitted-Params'] = Base64.encode64(exception.params.to_json)
30
+ end
31
+ end
32
+
25
33
  end
@@ -30,6 +30,13 @@ module EffectiveTestBot
30
30
  if Rails.env.test?
31
31
  ActionController::Base.send :include, ::EffectiveTestBotControllerHelper
32
32
  ActionController::Base.send :after_filter, :assign_test_bot_http_headers
33
+
34
+ ApplicationController.instance_exec do
35
+ rescue_from ActionController::UnpermittedParameters do |exception|
36
+ assign_test_bot_unpermitted_params_headers(exception)
37
+ end
38
+ end
39
+
33
40
  end
34
41
  end
35
42
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -29,6 +29,10 @@ module EffectiveTestBotAssertions
29
29
  assert_equal 0, errors.size, errors.ai
30
30
  end
31
31
 
32
+ def assert_no_unpermitted_params(message = 'Expected no unpermitted params')
33
+ assert_equal [], unpermitted_params, message
34
+ end
35
+
32
36
  # assert_flash
33
37
  # assert_flash :success
34
38
  # assert_flash :error, 'there was a specific error'
@@ -123,6 +123,21 @@ module EffectiveTestBotFormHelper
123
123
  submit_form(label)
124
124
  end
125
125
 
126
+ def with_raised_unpermitted_params_exceptions(&block)
127
+ action = nil
128
+
129
+ begin # This will only work with Rails >= 4.0
130
+ action = ActionController::Parameters.action_on_unpermitted_parameters
131
+ ActionController::Parameters.action_on_unpermitted_parameters = :raise
132
+ rescue => e
133
+ puts 'unable to assign config.action_on_unpermitted_parameters = :raise, unpermitted params assertions disabled.'
134
+ end
135
+
136
+ yield
137
+
138
+ ActionController::Parameters.action_on_unpermitted_parameters = action if action.present?
139
+ end
140
+
126
141
  # The field here is going to be the %input{:type => file}. Files can be one or more pathnames
127
142
  # http://stackoverflow.com/questions/5188240/using-selenium-to-imitate-dragging-a-file-onto-an-upload-element/11203629#11203629
128
143
  def upload_effective_asset(field, files)
@@ -17,6 +17,7 @@ module EffectiveTestBotTestHelper
17
17
  # Assign the Flash and Assigns
18
18
  @flash = (JSON.parse(Base64.decode64(session.driver.response_headers['Test-Bot-Flash'])) rescue {})
19
19
  @assigns = (JSON.parse(Base64.decode64(session.driver.response_headers['Test-Bot-Assigns'])) rescue {})
20
+ @unpermitted_params = (JSON.parse(Base64.decode64(session.driver.response_headers['Test-Bot-Unpermitted-Params'])) rescue [])
20
21
  end
21
22
 
22
23
  # EffectiveTestBot includes an after_filter on ApplicationController to set an http header
@@ -29,4 +30,8 @@ module EffectiveTestBotTestHelper
29
30
  @assigns ||= (JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Assigns'])) rescue {})
30
31
  end
31
32
 
33
+ def unpermitted_params
34
+ @unpermitted_params ||= (JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Unpermitted-Params'])) rescue [])
35
+ end
36
+
32
37
  end
@@ -23,11 +23,13 @@ module CrudTest
23
23
 
24
24
  within("form#new_#{resource_name}") do
25
25
  fill_form(resource_attributes)
26
- submit_form
26
+ skip?(:unpermitted_params) == true ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
27
27
  end
28
28
 
29
29
  after = { count: resource_class.count, path: page.current_path }
30
30
 
31
+ assert_no_unpermitted_params '[create_valid: :unpermitted_params] Expected no unpermitted params' unless skip?(:unpermitted_params)
32
+
31
33
  refute_equal before[:count], after[:count], "Expected fill_form to create a #{resource_class} object"
32
34
  refute_equal(before[:path], after[:path], "[create_valid: :path] Expected unique before and after paths") unless skip?(:path)
33
35
 
@@ -86,12 +88,14 @@ module CrudTest
86
88
 
87
89
  within("form#edit_#{resource_name}_#{resource.id}") do
88
90
  fill_form(resource_attributes)
89
- submit_form
91
+ skip?(:unpermitted_params) == true ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
90
92
  end
91
93
  resource = resource_class.find(resource.id)
92
94
 
93
95
  after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
94
96
 
97
+ assert_no_unpermitted_params '[update_valid: :unpermitted_params] Expected no unpermitted params' unless skip?(:unpermitted_params)
98
+
95
99
  assert_equal before[:count], after[:count], "Expected #{resource_class}.count to be unchanged"
96
100
  refute_equal(before[:updated_at], after[:updated_at], "Expected @#{resource_name}.updated_at to have changed") if resource.respond_to?(:updated_at)
97
101
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_test_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails