Skip to content

Commit

Permalink
Rails 3.2: Fix utusemi type name of associations
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Jul 29, 2014
1 parent fb267b1 commit 32e32d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utusemi/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def scoped(*args, &block)
association = @association
utusemi_values = association.truthly_owner.utusemi_values
return super unless utusemi_values[:flag]
super.utusemi!(association.klass.model_name.singular, utusemi_values[:options])
super.utusemi!(association.reflection.name.to_s.singularize, utusemi_values[:options])
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class Product < ActiveRecord::Base
has_many :stocks

# for rspec
has_many :dummy_stocks, class_name: Stock.name
end
4 changes: 4 additions & 0 deletions spec/lib/utusemi/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
it 'Inherit utusemi values to instance' do
expect(subject.where(name: nil).utusemi_values).not_to be_empty
end

it 'Inherit utusemi values to associations with collect type name' do
expect(subject.new.dummy_stocks.utusemi_values[:type]).to eq(:dummy_stock)
end
end

describe '::utusemi' do
Expand Down

0 comments on commit 32e32d7

Please sign in to comment.