fix: namespace and using string for lazy evaluate

main
Washington Botelho 2018-02-08 14:24:05 -02:00
parent ab9610bfe0
commit 1c3685959b
No known key found for this signature in database
GPG Key ID: 5DE4F42A8F073617
4 changed files with 9 additions and 7 deletions

View File

@ -12,8 +12,8 @@ module Rating
end end
def initialize def initialize
@rate_model = ::Rating::Rate @rate_model = '::Rating::Rate'
@rating_model = ::Rating::Rating @rating_model = '::Rating::Rating'
end end
end end
end end

View File

@ -2,7 +2,8 @@
module Rating module Rating
class Rate < ActiveRecord::Base class Rate < ActiveRecord::Base
self.table_name = 'rating_rates' self.table_name_prefix = 'rating_'
self.table_name = ::Rating.config.rate_model.constantize.table_name
after_save :update_rating after_save :update_rating

View File

@ -2,7 +2,8 @@
module Rating module Rating
class Rating < ActiveRecord::Base class Rating < ActiveRecord::Base
self.table_name = ::Rating.config.rating_model self.table_name_prefix = 'rating_'
self.table_name = ::Rating.config.rating_model.constantize.table_name
belongs_to :resource, polymorphic: true belongs_to :resource, polymorphic: true
belongs_to :scopeable, polymorphic: true belongs_to :scopeable, polymorphic: true
@ -107,7 +108,7 @@ module Rating
end end
def rate_table_name def rate_table_name
@rate_table_name ||= ::Rating.config.rate_model @rate_table_name ||= ::Rating.config.rate_model.constantize.table_name
end end
def scope_type_query(scopeable) def scope_type_query(scopeable)

View File

@ -4,7 +4,7 @@ require 'rails_helper'
RSpec.describe Rating::Config, 'initialize' do RSpec.describe Rating::Config, 'initialize' do
it 'has default models' do it 'has default models' do
expect(subject.rate_model).to eq ::Rating::Rate expect(subject.rate_model).to eq '::Rating::Rate'
expect(subject.rating_model).to eq ::Rating::Rating expect(subject.rating_model).to eq '::Rating::Rating'
end end
end end