Module: Cuprum::Rails::RSpec::Contracts::Actions::DestroyContracts::ShouldDestroyTheEntityContract
- Extended by:
- RSpec::SleepingKingStudios::Contract
- Defined in:
- lib/cuprum/rails/rspec/contracts/actions/destroy_contracts.rb
Overview
Contract asserting the action destroys the specified entity.
Instance Method Summary collapse
-
#apply(example_group, existing_entity: , **options) { ... } ⇒ Object
Adds the contract to the example group.
Instance Method Details
#apply(example_group, existing_entity: , **options) { ... } ⇒ Object
Adds the contract to the example group.
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 161 |
# File 'lib/cuprum/rails/rspec/contracts/actions/destroy_contracts.rb', line 106 contract do |existing_entity:, **, &block| describe '#call' do include Cuprum::Rails::RSpec::ContractHelpers context 'when the entity exists' do let(:request) do Cuprum::Rails::Request.new(params: configured_params) end let(:configured_existing_entity) do option_with_default(existing_entity) end let(:configured_params) do resource_id = configured_existing_entity[configured_resource.primary_key] option_with_default( [:params], default: { 'id' => resource_id } ) end let(:configured_expected_value) do resource_name = configured_resource.singular_name option_with_default( [:expected_value], default: { resource_name => configured_existing_entity } ) end it 'should return a passing result' do expect(call_action) .to be_a_passing_result .with_value(configured_expected_value) end it 'should destroy the entity', :aggregate_failures do expect { call_action } .to change(configured_resource.entity_class, :count) .by(-1) primary_key_name = configured_resource.primary_key primary_key_value = configured_existing_entity[primary_key_name] expect( action .resource .entity_class .exists?(primary_key_name => primary_key_value) ).to be false end instance_exec(&block) if block end end end |