Module: Cuprum::Rails::RSpec::Contracts::Actions::UpdateContracts::ShouldBeAnUpdateActionContract
- Extended by:
- RSpec::SleepingKingStudios::Contract
- Defined in:
- lib/cuprum/rails/rspec/contracts/actions/update_contracts.rb
Overview
Contract asserting the action implements the show action interface.
Instance Method Summary collapse
-
#apply(example_group, existing_entity: , invalid_attributes: , valid_attributes: , **options) { ... } ⇒ Object
Adds the contract to the example group.
Instance Method Details
#apply(example_group, existing_entity: , invalid_attributes: , valid_attributes: , **options) { ... } ⇒ Object
Adds the contract to the example group.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cuprum/rails/rspec/contracts/actions/update_contracts.rb', line 76 contract do |existing_entity:, invalid_attributes:, valid_attributes:, **, &block| # rubocop:disable Layout/LineLength include Cuprum::Rails::RSpec::Contracts::ActionContracts include Cuprum::Rails::RSpec::Contracts::Actions::UpdateContracts # :nocov: if [:examples_on_success] && block raise ArgumentError, 'provide either :examples_on_success or a block' elsif block [:examples_on_success] = block end # :nocov: configured_params = lambda do Cuprum::Rails::RSpec::Contracts::Actions::UpdateContracts.parameters( context: self, existing_entity: existing_entity, resource: configured_resource, valid_attributes: valid_attributes, ** ) end should_not_update_the_entity = lambda do it 'should not update the entity' do entity = existing_entity entity = instance_exec(&entity) if entity.is_a?(Proc) expect { call_action } .not_to(change { entity.reload.attributes }) end # :nocov: if [:examples_on_failure] instance_exec(&[:examples_on_failure]) end # :nocov: end include_contract 'should be a resource action', require_permitted_attributes: true include_contract( 'should require primary key', params: configured_params, &should_not_update_the_entity ) include_contract( 'should require parameters', params: configured_params, &should_not_update_the_entity ) include_contract( 'should require existing entity', params: configured_params, primary_key_value: [:primary_key_value], &should_not_update_the_entity ) include_contract( 'should validate attributes', existing_entity: existing_entity, expected_attributes: .fetch( :expected_attributes, [:expected_attributes_on_failure] ), invalid_attributes: invalid_attributes, params: configured_params, &should_not_update_the_entity ) include_contract( 'should update the entity', existing_entity: existing_entity, expected_attributes: .fetch( :expected_attributes, [:expected_attributes_on_success] ), expected_value: [:expected_value_on_success], valid_attributes: valid_attributes, params: configured_params, &[:examples_on_success] ) end |