Module: EacRailsUtils::Rspec::Setup::ModelsUtils
- Defined in:
- lib/eac_rails_utils/rspec/setup/models_utils.rb
Instance Method Summary collapse
- #model_record_attribute_test(record_variable, attribute, valid, value) ⇒ Object
- #model_record_valid_invalid_values_attribute_test(record_variable, attribute, valid_values, invalid_values) ⇒ Object
- #model_record_values_attribute_test(record_variable, attribute, valid, values) ⇒ Object
Instance Method Details
#model_record_attribute_test(record_variable, attribute, valid, value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 9 def model_record_attribute_test(record_variable, attribute, valid, value) context("when #{record_variable}.#{attribute} == #{value}") do before do send(record_variable).send("#{attribute}=", value) end it "#{record_variable} should be #{valid ? '' : 'not '}valid" do expect(send(record_variable).valid?).to(send("be_#{valid ? 'truthy' : 'falsy'}"), -> { send(record_variable).errors. }) end end end |
#model_record_valid_invalid_values_attribute_test(record_variable, attribute, valid_values, invalid_values) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 28 def model_record_valid_invalid_values_attribute_test(record_variable, attribute, valid_values, invalid_values) { false => invalid_values, true => valid_values }.each do |valid, values| model_record_values_attribute_test(record_variable, attribute, valid, values) end end |
#model_record_values_attribute_test(record_variable, attribute, valid, values) ⇒ Object
22 23 24 25 26 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 22 def model_record_values_attribute_test(record_variable, attribute, valid, values) values.each do |value| model_record_attribute_test(record_variable, attribute, valid, value) end end |