Skip to content

Commit

Permalink
Simplify usages of ignoring_interference_by_writer in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Dec 31, 2015
1 parent 540e6f5 commit e016615
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 47 deletions.
13 changes: 8 additions & 5 deletions spec/support/unit/create_model_arguments/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ def attribute

def all_attribute_overrides
@_all_attribute_overrides ||= begin
attribute_overrides = args.slice(
:changing_values_with,
:default_value
)

overrides =
if args.key?(:changing_values_with)
{ attribute_name => args.slice(:changing_values_with) }
else
if attribute_overrides.empty?
{}
else
{ attribute_name => attribute_overrides }
end

overrides.deep_merge(args.fetch(:attribute_overrides, {}))
Expand Down Expand Up @@ -93,8 +98,6 @@ def matcher_name
def attribute_default_values_by_name
if attribute_overrides.key?(:default_value)
{ attribute_name => attribute_overrides[:default_value] }
elsif args.key?(:default_value)
{ attribute_name => args[:default_value] }
else
{}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def args_from_config_for_test(config)
:attribute_name,
:attribute_overrides,
:changing_values_with,
:default_value,
:model_name,
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ def self.available_column_types
'ignoring_interference_by_writer',
tests: {
raise_if_not_qualified: {
attribute_overrides: {
attr: {
changing_values_with: :next_value
}
}
changing_values_with: :next_value
},
accept_if_qualified_but_changing_value_does_not_interfere: {
attribute_overrides: {
attr: {
changing_values_with: :next_value
}
}
changing_values_with: :next_value
},
}
)
Expand Down Expand Up @@ -95,18 +87,10 @@ def validation_matcher_scenario_args
'ignoring_interference_by_writer',
tests: {
raise_if_not_qualified: {
attribute_overrides: {
attr: {
changing_values_with: :upcase
}
}
changing_values_with: :upcase
},
accept_if_qualified_but_changing_value_does_not_interfere: {
attribute_overrides: {
attr: {
changing_values_with: :upcase
}
}
changing_values_with: :upcase
},
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
expected_message: <<-MESSAGE.strip
Example did not properly validate that :attr lies outside the range ‹2›
Expand Down Expand Up @@ -155,6 +156,7 @@ def configure_validation_matcher(matcher)
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
changing_values_with: :next_value,
expected_message: <<-MESSAGE.strip
Example did not properly validate that :attr is neither ‹"one"› nor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,13 @@
tests: {
raise_if_not_qualified: {
attribute_name: :attr,
attribute_overrides: {
attr: {
changing_values_with: :next_value,
}
}
changing_values_with: :next_value,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
attribute_overrides: {
attr: {
default_value: 'some value',
changing_values_with: :next_value,
}
},
default_value: 'some value',
changing_values_with: :next_value,
expected_message: <<-MESSAGE.strip
Example did not properly validate that :attr is case-sensitively unique.
After taking the given Example, whose :attr is ‹"some valuf"›, and
Expand Down Expand Up @@ -767,21 +759,13 @@
tests: {
raise_if_not_qualified: {
attribute_name: :attr,
attribute_overrides: {
attr: {
changing_values_with: :next_value,
}
}
changing_values_with: :next_value,
},
reject_if_qualified_but_changing_value_interferes: {
model_name: 'Example',
attribute_name: :attr,
attribute_overrides: {
attr: {
default_value: 'some value',
changing_values_with: :next_value,
}
},
default_value: 'some value',
changing_values_with: :next_value,
expected_message: <<-MESSAGE.strip
Example did not properly validate that :attr is case-insensitively
unique.
Expand Down

0 comments on commit e016615

Please sign in to comment.