Class: Rails::AddOns::Shoulda::Matchers::ImplementDeleteActionMatcher
- Inherits:
-
Object
- Object
- Rails::AddOns::Shoulda::Matchers::ImplementDeleteActionMatcher
- Includes:
- RSpec::Matchers
- Defined in:
- lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb
Instance Method Summary collapse
- #by(expected_reduction) ⇒ Object
- #delete_link_text ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object (also: #negative_failure_message)
-
#for(resource) ⇒ Object
Resource that will be deleted.
- #has_correct_current_path ⇒ Object
- #has_correct_status_code ⇒ Object
- #has_reduced_resource_count ⇒ Object
- #id ⇒ Object
-
#initialize(spec) ⇒ ImplementDeleteActionMatcher
constructor
A new instance of ImplementDeleteActionMatcher.
- #matches?(base_path) ⇒ Boolean
- #reducing(&block) ⇒ Object
Constructor Details
#initialize(spec) ⇒ ImplementDeleteActionMatcher
Returns a new instance of ImplementDeleteActionMatcher.
25 26 27 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 25 def initialize(spec) @spec = spec end |
Instance Method Details
#by(expected_reduction) ⇒ Object
44 45 46 47 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 44 def by(expected_reduction) @expected_reduction = expected_reduction self end |
#delete_link_text ⇒ Object
63 64 65 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 63 def delete_link_text @delete_link_text ||= I18n.t('resources_controller.base.show_actions.delete') end |
#description ⇒ Object
104 105 106 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 104 def description "expose delete action on #{@base_path} [#{delete_link_text}]" end |
#failure_message ⇒ Object
94 95 96 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 94 def "Should expose delete action on #{@base_path} [#{delete_link_text}], clicking on #{delete_link_text}. Error: #{@error}" end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
98 99 100 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 98 def "Should not expose delete action on #{@base_path} [#{delete_link_text}], clicking on #{delete_link_text}. Error: #{@error}" end |
#for(resource) ⇒ Object
Resource that will be deleted
30 31 32 33 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 30 def for(resource) @resource = resource self end |
#has_correct_current_path ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 85 def has_correct_current_path if @spec.current_path == @expected_path true else @error = "Wrong current path [#{@spec.current_path}] instead of [#{@expected_path}]" false end end |
#has_correct_status_code ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 67 def has_correct_status_code if @spec.status_code == 200 true else @error = "Wrong status code [#{@spec.status_code}] instead of [200]" false end end |
#has_reduced_resource_count ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 76 def has_reduced_resource_count if (@before_delete_count - @after_delete_count) == @expected_reduction true else @error = "Did not reduce by expected [#{@expected_reduction}] but by [#{@before_delete_count - @after_delete_count}]" false end end |
#id ⇒ Object
35 36 37 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 35 def id @resource.to_param end |
#matches?(base_path) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 49 def matches?(base_path) @base_path = base_path @expected_path = @base_path @show_path = "#{@base_path}/#{id}" @spec.visit(@show_path) @before_delete_count = @block.call @spec.click_link(delete_link_text) @after_delete_count = @block.call has_correct_status_code && has_correct_current_path && has_reduced_resource_count end |
#reducing(&block) ⇒ Object
39 40 41 42 |
# File 'lib/rails/add_ons/shoulda/matchers/implement_delete_action_matcher.rb', line 39 def reducing(&block) @block = block self end |