Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the deprecated unique attribute on delegates #204

Merged
merged 1 commit into from
Sep 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions lib/active_fedora/delegating.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module ActiveFedora
module Delegating
extend ActiveSupport::Concern
extend Deprecation

included do
after_save :clear_changed_attributes
Expand Down Expand Up @@ -146,29 +145,7 @@ def create_delegate_reader(field, args)
end
end

if !args[:multiple].nil?
self.delegates[field][:multiple] = args[:multiple]
elsif !args[:unique].nil?
i = 0
begin
match = /in `(delegate.*)'/.match(caller[i])
i+=1
end while match.nil?

prev_method = match.captures.first
Deprecation.warn Delegating, "The :unique option for `#{prev_method}' is deprecated. Use :multiple instead. :unique will be removed in ActiveFedora 7", caller(i+1)
self.delegates[field][:multiple] = !args[:unique]
else
i = 0
begin
match = /in `(delegate.*)'/.match(caller[i])
i+=1
end while match.nil?

prev_method = match.captures.first
Deprecation.warn Delegating, "You have not explicitly set the :multiple option on `#{prev_method}'. The default value will switch from true to false in ActiveFedora 7, so if you want to future-proof this application set `multiple: true'", caller(i+ 1)
self.delegates[field][:multiple] = true # this should be false for ActiveFedora 7
end
self.delegates[field][:multiple] = args[:multiple].nil? ? false : args[:multiple]

define_method field do |*opts|
val = array_reader(field, *opts)
Expand Down
29 changes: 14 additions & 15 deletions spec/unit/base_delegate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def self.xml_template
<duck/>
</ducks>
</waterfowl>
<donkey></donkey>
<cow></cow>
</animals>'
end
Expand All @@ -49,9 +48,8 @@ class BarHistory2 < ActiveFedora::Base
end

has_metadata :type=>BarStream2, :name=>"xmlish"
delegate :fubar, :to=>'withText', :unique=>true
delegate :donkey, :to=>'xmlish', :unique=>true
delegate :cow, :to=>'xmlish' # for testing the default value of multiple
delegate :cow, :to=>'xmlish' # for testing the default value of multiple
delegate :fubar, :to=>'withText', multiple: true # test alternate datastream
delegate :pig, :to=>'xmlish', multiple: false
delegate :horse, :to=>'xmlish', multiple: true
delegate :duck, :to=>'xmlish', :at=>[:waterfowl, :ducks], multiple: true
Expand All @@ -65,33 +63,34 @@ class BarHistory2 < ActiveFedora::Base
subject { BarHistory2.new() }

it "should reveal the unique properties" do
BarHistory2.unique?(:fubar).should be_true
BarHistory2.unique?(:cow).should be_false
BarHistory2.unique?(:horse).should be_false
BarHistory2.unique?(:pig).should be_true
BarHistory2.unique?(:cow).should be_true
end

it "should save a delegated property uniquely" do
subject.fubar="Quack"
subject.fubar.should == "Quack"
subject.fubar.should == ["Quack"]
subject.withText.get_values(:fubar).first.should == 'Quack'
subject.donkey="Bray"
subject.donkey.should == "Bray"
subject.xmlish.term_values(:donkey).first.should == 'Bray'
subject.cow="Low"
subject.cow.should == "Low"
subject.xmlish.term_values(:cow).first.should == 'Low'

subject.pig="Oink"
subject.pig.should == "Oink"
end

it "should allow passing parameters to the delegate accessor" do
subject.cow=["one", "two"]
subject.cow(1).should == ['two']
subject.cow(1).should == 'two'
end


it "should return an array if not marked as unique" do
### Metadata datastream does not appear to support multiple value setting
it "should return a single value if not marked as multiple" do
subject.cow=["one", "two"]
subject.cow.should == ["one", "two"]
subject.cow.should == "one"
end

it "should return an array if marked as multiple" do
subject.horse=["neigh", "whinny"]
subject.horse.should == ["neigh", "whinny"]
end
Expand Down