fix: namespace and using string for lazy evaluate
parent
ab9610bfe0
commit
1c3685959b
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue