Skip to content

Commit

Permalink
Merge pull request #1091 from projecthydra/save_metadata
Browse files Browse the repository at this point in the history
AF::File#save! should persist metadata
  • Loading branch information
awead committed May 31, 2016
2 parents 2b844b2 + f992bea commit b738724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ def initialize(identifier = nil, &_block)
end
end

def save
super.tap do
metadata.save if metadata.changed?
end
end

def described_by
raise "#{self} isn't persisted yet" if new_record?
links['describedby'].first
Expand Down Expand Up @@ -176,6 +170,12 @@ def prefix(path)

private

def create_or_update(*options)
super.tap do
metadata.save if metadata.changed?
end
end

# Rack::Test::UploadedFile is often set via content=, however it's not an IO, though it wraps an io object.
def behaves_like_io?(obj)
[IO, Tempfile, StringIO].any? { |klass| obj.is_a? klass } || (defined?(Rack) && obj.is_a?(Rack::Test::UploadedFile))
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@

it { is_expected.not_to be_metadata }

describe "#save!" do
context "when updating metadata" do
before do
file.content = 'foo'
file.save!
file.mime_type = 'application/pdf'
end

it "Updates metadata" do
expect(file.metadata).to receive(:save)
file.save!
end
end
end

describe "#behaves_like_io?" do
subject { file.send(:behaves_like_io?, object) }

Expand Down

0 comments on commit b738724

Please sign in to comment.