From 1c3685959b66be706d144bd415bc983ce90ecfdb Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Thu, 8 Feb 2018 14:24:05 -0200 Subject: [PATCH] fix: namespace and using string for lazy evaluate --- lib/rating/config.rb | 4 ++-- lib/rating/models/rating/rate.rb | 3 ++- lib/rating/models/rating/rating.rb | 5 +++-- spec/config/initialize_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/rating/config.rb b/lib/rating/config.rb index 3622683..73c5d9e 100644 --- a/lib/rating/config.rb +++ b/lib/rating/config.rb @@ -12,8 +12,8 @@ module Rating end def initialize - @rate_model = ::Rating::Rate - @rating_model = ::Rating::Rating + @rate_model = '::Rating::Rate' + @rating_model = '::Rating::Rating' end end end diff --git a/lib/rating/models/rating/rate.rb b/lib/rating/models/rating/rate.rb index c78792f..2329ecb 100644 --- a/lib/rating/models/rating/rate.rb +++ b/lib/rating/models/rating/rate.rb @@ -2,7 +2,8 @@ module Rating 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 diff --git a/lib/rating/models/rating/rating.rb b/lib/rating/models/rating/rating.rb index b8d400e..ab234da 100644 --- a/lib/rating/models/rating/rating.rb +++ b/lib/rating/models/rating/rating.rb @@ -2,7 +2,8 @@ module Rating 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 :scopeable, polymorphic: true @@ -107,7 +108,7 @@ module Rating end def rate_table_name - @rate_table_name ||= ::Rating.config.rate_model + @rate_table_name ||= ::Rating.config.rate_model.constantize.table_name end def scope_type_query(scopeable) diff --git a/spec/config/initialize_spec.rb b/spec/config/initialize_spec.rb index 6a395cf..520a932 100644 --- a/spec/config/initialize_spec.rb +++ b/spec/config/initialize_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' RSpec.describe Rating::Config, 'initialize' do it 'has default models' do - expect(subject.rate_model).to eq ::Rating::Rate - expect(subject.rating_model).to eq ::Rating::Rating + expect(subject.rate_model).to eq '::Rating::Rate' + expect(subject.rating_model).to eq '::Rating::Rating' end end