Skip to content

Commit

Permalink
Add enable_optimistic_locking on Valkyrie::Resource
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Headley <[email protected]>
Co-authored-by: Mike Tribone <[email protected]>
  • Loading branch information
3 people committed Jul 30, 2018
1 parent a8a8dc4 commit dc17ade
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/valkyrie/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def self.human_readable_type=(val)
@_human_readable_type = val
end

def self.enable_optimistic_locking
attribute(:optimistic_lock_token, Valkyrie::Types::Set)
end

# @return [Hash] Hash of attributes
def attributes
to_h
Expand Down
37 changes: 37 additions & 0 deletions spec/valkyrie/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,41 @@ class MyResource < Resource
end
end
end

describe "::enable_optimistic_locking" do
context "when it is enabled" do
before do
class MyLockingResource < Valkyrie::Resource
enable_optimistic_locking
attribute :id, Valkyrie::Types::ID.optional
attribute :title, Valkyrie::Types::Set
end
end

after do
Object.send(:remove_const, :MyLockingResource)
end

it "has an optimistic_lock_token attribute" do
expect(MyLockingResource.new).to respond_to(:optimistic_lock_token)
end
end

context "when it is not enabled" do
before do
class MyNonlockingResource < Valkyrie::Resource
attribute :id, Valkyrie::Types::ID.optional
attribute :title, Valkyrie::Types::Set
end
end

after do
Object.send(:remove_const, :MyNonlockingResource)
end

it "does not have an optimistic_lock_token attribute" do
expect(MyNonlockingResource.new).not_to respond_to(:optimistic_lock_token)
end
end
end
end

0 comments on commit dc17ade

Please sign in to comment.