Skip to content

Commit

Permalink
Make sure fields get marked as dirty if they change. Story #122
Browse files Browse the repository at this point in the history
I overrode the getter and setter methods for the ordered fields to keep
track of their order in secondary fields, but that caused a problem.
Even though those fields appeared to be correct in the UI, I noticed
that the `description` and `ordered_descriptions` fields were out of
sync in the fedora console.

The overrides to the getters and setters messed up the logic that
determines whether or not a field is marked dirty.

I wrote a spec to make sure that both the original field and its
secondary ordering field will be marked dirty if the field is updated,
and then moved the `super` call to the top of the setter method, which
solves the problem with the logic for dirtiness.
  • Loading branch information
val99erie committed Dec 28, 2017
1 parent 802b2bc commit c445653
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ RSpec/MultipleExpectations:
- 'spec/lib/tufts/metadata_exporter_spec.rb'
- 'spec/lib/tufts/workflow_setup_spec.rb'
- 'spec/services/**/*'
- 'spec/support/shared_examples/metadata_ordered_fields.rb'
RSpec/ScatteredSetup:
Exclude:
- 'spec/models/metadata_import_spec.rb'
RSpec/MessageSpies:
Enabled: false
Style/FileName:
Exclude:
- '**/Capfile'
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/tufts/metadata/ordered_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module OrderedFields
# @param [Array] Ordered array of values
# Overrides setter method to preserve order in a second property.
def description=(values)
self.ordered_descriptions = values.to_json
super
self.ordered_descriptions = values.to_json
end

# @return [Array<String>]
Expand All @@ -48,8 +48,8 @@ def description
# @param [Array] Ordered array of values
# Overrides setter method to preserve order in a second property.
def creator=(values)
self.ordered_creators = values.to_json
super
self.ordered_creators = values.to_json
end

# @return [Array<String>]
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

factory :populated_pdf, class: Pdf do
Pdf.properties.each_value do |property|
next if [:create_date, :modified_date, :has_model, :head, :tail].include? property.term
next if [:create_date, :modified_date, :has_model, :head, :tail, :ordered_descriptions, :ordered_creators].include? property.term

if property.term == :title
send(property.term, [FFaker::Book.title])
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tufts/handle_registrar_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

# rubocop:disable RSpec/MessageSpies, Lint/HandleExceptions, RSpec/InstanceVariable
# rubocop:disable Lint/HandleExceptions, RSpec/InstanceVariable
describe Tufts::HandleRegistrar do
subject(:service) do
described_class.new(connection: stubbed_connection.new(record: record))
Expand Down
16 changes: 16 additions & 0 deletions spec/support/shared_examples/metadata_ordered_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
end
end
end

describe '#description=' do
it 'marks both "description" and "ordered_descriptions" fields as dirty so they will both be updated in fedora' do
expect(work).to receive(:attribute_will_change!).with(:description)
expect(work).to receive(:attribute_will_change!).with(:ordered_descriptions)
work.description = expected_order
end
end
end

describe 'ordered creators' do
Expand Down Expand Up @@ -84,5 +92,13 @@
expect(work.creator).to eq expected_order
end
end

describe '#creator=' do
it 'marks both "creator" and "ordered_creators" fields as dirty so they will both be updated in fedora' do
expect(work).to receive(:attribute_will_change!).with(:creator)
expect(work).to receive(:attribute_will_change!).with(:ordered_creators)
work.creator = expected_order
end
end
end
end

0 comments on commit c445653

Please sign in to comment.