Module: Cuprum::Rails::RSpec::Contracts::Actions::CreateContracts::ShouldBeACreateActionContract
- Extended by:
- RSpec::SleepingKingStudios::Contract
- Defined in:
- lib/cuprum/rails/rspec/contracts/actions/create_contracts.rb
Overview
Contract asserting the action implements the create action interface.
Instance Method Summary collapse
-
#apply(example_group, invalid_attributes: , valid_attributes: , **options) { ... } ⇒ Object
Adds the contract to the example group.
Instance Method Details
#apply(example_group, invalid_attributes: , valid_attributes: , **options) { ... } ⇒ Object
Adds the contract to the example group.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 |
# File 'lib/cuprum/rails/rspec/contracts/actions/create_contracts.rb', line 48 contract do |invalid_attributes:, valid_attributes:, **, &block| include Cuprum::Rails::RSpec::Contracts::ActionContracts include Cuprum::Rails::RSpec::Contracts::Actions::CreateContracts = .merge(valid_attributes: valid_attributes) configured_params = lambda do attributes = Cuprum::Rails::RSpec::ContractHelpers.option_with_default( valid_attributes, context: self ) Cuprum::Rails::RSpec::ContractHelpers.option_with_default( [:params], context: self, default: { configured_resource.singular_name => attributes } ) end # :nocov: if [:examples_on_success] && block raise ArgumentError, 'provide either :examples_on_success or a block' elsif block [:examples_on_success] = block end # :nocov: should_not_create_an_entity = lambda do it 'should not create an entity' do expect { call_action } .not_to change(configured_resource.entity_class, :count) 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 parameters', params: configured_params, &should_not_create_an_entity ) include_contract( 'should validate attributes', expected_attributes: .fetch( :expected_attributes, [:expected_attributes_on_failure] ), invalid_attributes: invalid_attributes, params: configured_params, &should_not_create_an_entity ) if [:duplicate_attributes] include_contract( 'should not create a duplicate entity', params: configured_params, valid_attributes: [:duplicate_attributes], &should_not_create_an_entity ) end include_contract 'should create the entity', expected_attributes: .fetch( :expected_attributes, [:expected_attributes_on_success] ), expected_value: [:expected_value_on_success], params: configured_params, valid_attributes: valid_attributes, &[:examples_on_success] end |