Skip to content

Commit

Permalink
Merge pull request #153 from samvera/152-multi-value-input-for-object…
Browse files Browse the repository at this point in the history
…-methods

MultiValue gets values from object methods and attributes
  • Loading branch information
jrgriffiniii authored May 11, 2018
2 parents 2e052d5 + 0d19925 commit 8a0800b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/inputs/multi_value_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def input_dom_id

def collection
@collection ||= begin
val = object[attribute_name]
val = object.send(attribute_name)
col = val.respond_to?(:to_ary) ? val.to_ary : val
col.reject { |value| value.to_s.strip.blank? } + ['']
end
Expand Down
26 changes: 19 additions & 7 deletions spec/inputs/multi_value_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
describe 'MultiValueInput', type: :input do
class Foo < ActiveFedora::Base
property :bar, predicate: ::RDF::URI('http://example.com/bar')

def double_bar
bar.map { |b| b+ b }
end
end

context 'happy case' do
let(:foo) { Foo.new }
let(:foo) do
Foo.new.tap { |f| f.bar = bar }
end
let(:bar) { ['bar1', 'bar2'] }
subject do
foo.bar = bar
input_for(foo, :bar, as: :multi_value, required: true)

context "for values from a property on the object" do
subject { input_for(foo, :bar, as: :multi_value, required: true) }
it 'renders multi-value' do
expect(subject).to have_selector('.form-group.foo_bar.multi_value label.required[for=foo_bar]', text: '* Bar')
expect(subject).to have_selector('.form-group.foo_bar.multi_value ul.listing li input.foo_bar', count: 3)
end
end

it 'renders multi-value' do
expect(subject).to have_selector('.form-group.foo_bar.multi_value label.required[for=foo_bar]', text: '* Bar')
expect(subject).to have_selector('.form-group.foo_bar.multi_value ul.listing li input.foo_bar', count: 3)
context 'for values from a method on the object' do
subject { input_for(foo, :double_bar, as: :multi_value) }
it 'renders multi-value' do
expect(subject).to have_selector('.form-group.foo_double_bar.multi_value ul.listing li input.foo_double_bar', count: 3)
end
end
end

Expand Down

0 comments on commit 8a0800b

Please sign in to comment.