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
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 7 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 #{'not ' unless valid}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
26 27 28 29 30 31 32 33 34 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 26 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
20 21 22 23 24 |
# File 'lib/eac_rails_utils/rspec/setup/models_utils.rb', line 20 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 |