efficient_translations 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Guardfile +24 -0
- data/efficient_translations.gemspec +2 -0
- data/lib/active_support/concern.rb +35 -0
- data/lib/efficient_translations.rb +7 -5
- data/lib/efficient_translations/translatable_model.rb +69 -0
- data/lib/efficient_translations/translates_method.rb +7 -62
- data/lib/efficient_translations/translation_factory.rb +12 -22
- data/lib/efficient_translations/translation_model.rb +36 -0
- data/lib/efficient_translations/version.rb +1 -1
- data/spec/lib/efficient_translations/translatable_model_spec.rb +50 -0
- data/spec/lib/efficient_translations/translates_method_spec.rb +2 -9
- data/spec/lib/efficient_translations/translation_factory_spec.rb +44 -45
- data/spec/lib/efficient_translations/translation_model_spec.rb +32 -0
- data/spec/support/working_model.rb +5 -0
- metadata +45 -15
- data/Gemfile.lock +0 -33
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.add_development_dependency 'rake'
|
18
18
|
gem.add_development_dependency 'rspec'
|
19
19
|
gem.add_development_dependency 'sqlite3'
|
20
|
+
gem.add_development_dependency 'guard'
|
21
|
+
gem.add_development_dependency 'guard-rspec'
|
20
22
|
gem.add_dependency 'activerecord' , '~> 2.3'
|
21
23
|
gem.add_dependency 'activesupport', '~> 2.3'
|
22
24
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support/deprecation'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Concern
|
5
|
+
def self.extended(base)
|
6
|
+
base.instance_variable_set("@_dependencies", [])
|
7
|
+
end
|
8
|
+
|
9
|
+
def append_features(base)
|
10
|
+
if base.instance_variable_defined?("@_dependencies")
|
11
|
+
base.instance_variable_get("@_dependencies") << self
|
12
|
+
return false
|
13
|
+
else
|
14
|
+
return false if base < self
|
15
|
+
@_dependencies.each { |dep| base.send(:include, dep) }
|
16
|
+
super
|
17
|
+
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
|
18
|
+
if const_defined?("InstanceMethods")
|
19
|
+
base.send :include, const_get("InstanceMethods")
|
20
|
+
ActiveSupport::Deprecation.warn "The InstanceMethods module inside ActiveSupport::Concern will be " \
|
21
|
+
"no longer included automatically. Please define instance methods directly in #{self} instead.", caller
|
22
|
+
end
|
23
|
+
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def included(base = nil, &block)
|
28
|
+
if base.nil?
|
29
|
+
@_included_block = block
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_record'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
require File.join
|
7
|
-
|
8
|
-
|
4
|
+
root = File.expand_path File.dirname __FILE__
|
5
|
+
|
6
|
+
require File.join root, 'active_support/concern'
|
7
|
+
|
8
|
+
%w(version schema translation_model translatable_model translation_factory translates_method).each do |file|
|
9
|
+
require File.join root, "efficient_translations/#{file}"
|
10
|
+
end
|
9
11
|
|
10
12
|
::ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, EfficientTranslations::Schema
|
11
13
|
::ActiveRecord::Base.send :include, EfficientTranslations::TranslatesMethod
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module EfficientTranslations
|
2
|
+
module TranslatableModel
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# Translation Model
|
7
|
+
cattr_accessor :translation_model, :translated_fields
|
8
|
+
self.translation_model = TranslationFactory.build_translation_model self
|
9
|
+
|
10
|
+
# Relationships
|
11
|
+
has_many :translations, :class_name => translation_model.name, :dependent => :delete_all
|
12
|
+
accepts_nested_attributes_for :translations
|
13
|
+
|
14
|
+
# Callbacks
|
15
|
+
after_save :update_translations!
|
16
|
+
|
17
|
+
# Scopes
|
18
|
+
named_scope :with_translations, :include => :translations
|
19
|
+
named_scope :with_current_translation, lambda {
|
20
|
+
{
|
21
|
+
:include => :translations,
|
22
|
+
:conditions => [
|
23
|
+
"#{translation_model.table_name}.locale = ? OR #{translation_model.table_name}.locale = ?",
|
24
|
+
I18n.locale.to_s, I18n.default_locale.to_s
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
named_scope :with_translation_for, lambda { |locale|
|
29
|
+
{
|
30
|
+
:inlude => :translations,
|
31
|
+
:conditions => [
|
32
|
+
"#{translation_model.table_name}.locale = ? OR #{translation_model.table_name}.locale = ?",
|
33
|
+
locale.to_s, I18n.default_locale.to_s
|
34
|
+
]
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def default_locale_presence_validation
|
42
|
+
if efficient_translations_attributes[I18n.default_locale.to_sym].blank? && translations.detect { |t| t.locale.to_sym == I18n.default_locale.to_sym }.nil?
|
43
|
+
# people may expect this message to be localized too ;-)
|
44
|
+
errors.add :translations, "for #{I18n.default_locale} is missing"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# attributes are stored in @efficient_attributes instance variable via setter
|
49
|
+
def efficient_translations_attributes
|
50
|
+
@efficient_translations_attributes ||= Hash.new { |hash, key| hash[key] = {} }
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_translations!
|
54
|
+
if efficient_translations_attributes.present?
|
55
|
+
translations true # force reload all translations
|
56
|
+
efficient_translations_attributes.each do |locale, attributes|
|
57
|
+
translation = translations.detect { |t| t.locale.to_sym == locale }
|
58
|
+
translation ||= begin
|
59
|
+
self.class.translation_model.new({
|
60
|
+
:locale => locale,
|
61
|
+
translation_model.translatable_relation_field => self
|
62
|
+
})
|
63
|
+
end
|
64
|
+
translation.update_attributes! attributes
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -6,44 +6,19 @@ module EfficientTranslations
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def translates *field_names
|
9
|
-
|
9
|
+
include TranslatableModel unless included_modules.include? TranslatableModel
|
10
|
+
self.translated_fields = field_names
|
10
11
|
field_names.each do |field|
|
11
12
|
define_translation_accessors field
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def validates_presence_of_default_locale
|
16
|
-
validate :
|
17
|
+
validate :default_locale_presence_validation
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
def make_efficient_translatable!
|
22
|
-
cattr_accessor :translation_model
|
23
|
-
self.translation_model = TranslationFactory.build self
|
24
|
-
has_many :translations, :class_name => translation_model.name, :dependent => :delete_all
|
25
|
-
accepts_nested_attributes_for :translations
|
26
|
-
after_save :update_translations!
|
27
|
-
|
28
|
-
named_scope :with_translations, :include => :translations
|
29
|
-
named_scope :with_current_translation, lambda {
|
30
|
-
{
|
31
|
-
:include => :translations,
|
32
|
-
:conditions => [scope_conditions, I18n.locale.to_s, I18n.default_locale.to_s]
|
33
|
-
}
|
34
|
-
}
|
35
|
-
named_scope :with_translation_for, lambda { |locale|
|
36
|
-
{
|
37
|
-
:inlude => :translations,
|
38
|
-
:conditions => [scope_conditions, locale.to_s, I18n.default_locale.to_s]
|
39
|
-
}
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def scope_conditions
|
44
|
-
"#{translation_model.table_name}.locale = ? OR #{translation_model.table_name}.locale = ?"
|
45
|
-
end
|
46
|
-
|
47
22
|
def define_translation_accessors field
|
48
23
|
field = field.to_sym
|
49
24
|
class_eval do
|
@@ -60,17 +35,16 @@ module EfficientTranslations
|
|
60
35
|
end
|
61
36
|
|
62
37
|
define_method "#{field}_translation" do |locale|
|
63
|
-
translation_field =
|
38
|
+
translation_field = send "#{field}_translation!", locale
|
64
39
|
if translation_field
|
65
40
|
translation_field
|
66
41
|
elsif locale.to_sym != I18n.default_locale
|
67
|
-
|
42
|
+
send "#{field}_translation!", I18n.default_locale
|
68
43
|
end
|
69
44
|
end
|
70
45
|
|
71
46
|
define_method "set_#{field}_translation" do |locale, value|
|
72
|
-
locale =
|
73
|
-
efficient_translations_attributes[locale][field] = value
|
47
|
+
efficient_translations_attributes[locale.to_sym][field] = value
|
74
48
|
end
|
75
49
|
|
76
50
|
define_method field do
|
@@ -85,7 +59,7 @@ module EfficientTranslations
|
|
85
59
|
self.send "set_#{field}_translation", I18n.locale, value
|
86
60
|
end
|
87
61
|
|
88
|
-
define_method
|
62
|
+
define_method "#{field}_translations" do
|
89
63
|
found = {}
|
90
64
|
efficient_translations_attributes.each do |locale, translation|
|
91
65
|
found[locale] = translation[field]
|
@@ -98,34 +72,5 @@ module EfficientTranslations
|
|
98
72
|
end
|
99
73
|
end
|
100
74
|
end
|
101
|
-
|
102
|
-
# instance methods - no need to put them a module
|
103
|
-
private
|
104
|
-
|
105
|
-
# attributes are stored in @efficient_attributes instance variable via setter
|
106
|
-
def efficient_translations_attributes
|
107
|
-
@efficient_translations_attributes ||= Hash.new { |hash, key| hash[key] = {} }
|
108
|
-
end
|
109
|
-
|
110
|
-
def update_translations!
|
111
|
-
if efficient_translations_attributes.present?
|
112
|
-
translations true # force reload all translations
|
113
|
-
efficient_translations_attributes.each do |locale, attributes|
|
114
|
-
translation = translations.detect { |t| t.locale.to_sym == locale } || begin
|
115
|
-
args = { :locale => locale }
|
116
|
-
args[self.class.translation_model.translatable_relation_field] = self
|
117
|
-
self.class.translation_model.new args
|
118
|
-
end
|
119
|
-
translation.update_attributes! attributes
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def default_locale_required
|
125
|
-
if efficient_translations_attributes[I18n.default_locale.to_sym].blank? && translations.detect { |t| t.locale.to_sym == I18n.default_locale.to_sym }.nil?
|
126
|
-
# people may expect this message to be localized too ;-)
|
127
|
-
errors.add :translations, "for #{I18n.default_locale} is missing"
|
128
|
-
end
|
129
|
-
end
|
130
75
|
end
|
131
76
|
end
|
@@ -1,29 +1,19 @@
|
|
1
1
|
module EfficientTranslations
|
2
2
|
module TranslationFactory
|
3
|
-
def self.
|
4
|
-
if
|
5
|
-
|
3
|
+
def self.translation_model_for model
|
4
|
+
if model.const_defined? :Translation
|
5
|
+
model.const_get :Translation
|
6
6
|
else
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
cattr_accessor :translatable_model, :translatable_relation_field
|
11
|
-
self.translatable_model = base_model
|
12
|
-
self.translatable_relation_field = base_model.model_name.underscore.gsub '/', '_'
|
13
|
-
|
14
|
-
belongs_to translatable_relation_field, :class_name => self.translatable_model.name
|
15
|
-
before_save :stringify_locale!
|
16
|
-
|
17
|
-
named_scope :for_locale, lambda { |locale|
|
18
|
-
{ :conditions => ['locale = ? OR locale = ?', locale.to_s, I18n.locale.to_s] }
|
19
|
-
}
|
20
|
-
|
21
|
-
define_method :stringify_locale! do
|
22
|
-
self.locale = locale.to_s
|
23
|
-
end
|
24
|
-
end
|
25
|
-
klass
|
7
|
+
translation = model.const_set :Translation, Class.new(ActiveRecord::Base)
|
8
|
+
translation.send :include, TranslationModel
|
9
|
+
translation
|
26
10
|
end
|
27
11
|
end
|
12
|
+
|
13
|
+
def self.build_translation_model base_model
|
14
|
+
klass = translation_model_for base_model
|
15
|
+
klass.build_for base_model
|
16
|
+
klass
|
17
|
+
end
|
28
18
|
end
|
29
19
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module EfficientTranslations
|
2
|
+
module TranslationModel
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
extend ClassMethods
|
7
|
+
|
8
|
+
cattr_accessor :translatable_model, :translatable_relation_field
|
9
|
+
|
10
|
+
before_save :stringify_locale!
|
11
|
+
|
12
|
+
named_scope :for_locale, lambda { |locale|
|
13
|
+
{ :conditions => ['locale = ? OR locale = ?', locale.to_s, I18n.locale.to_s] }
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def build_for base_model
|
19
|
+
if translatable_model
|
20
|
+
raise 'This translation model is already built'
|
21
|
+
else
|
22
|
+
self.translatable_model = base_model
|
23
|
+
self.translatable_relation_field = base_model.table_name.singularize.to_sym
|
24
|
+
|
25
|
+
belongs_to translatable_relation_field, :class_name => self.translatable_model.name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def stringify_locale!
|
33
|
+
self.locale = locale.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module EfficientTranslations
|
4
|
+
describe TranslatableModel do
|
5
|
+
it 'is included in WorkingModel' do
|
6
|
+
WorkingModel.included_modules.should include TranslatableModel
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'defines a translation model accessor' do
|
10
|
+
WorkingModel.translation_model.should == WorkingModel::Translation
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'defines a translated_fields accessor' do
|
14
|
+
WorkingModel.should respond_to :translated_fields
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'defines an has_many relationship with its translation child' do
|
18
|
+
WorkingModel.new.should respond_to :translations
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'defines an after_save callback to update translations' do
|
22
|
+
WorkingModel.after_save_callback_chain.map(&:method).should include :update_translations!
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'defines some named scopes' do
|
26
|
+
%w(with_translations with_current_translation with_translation_for).each do |m|
|
27
|
+
WorkingModel.should respond_to m
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#default_locale_presence_validation' do
|
32
|
+
context 'when default locale does not exist' do
|
33
|
+
it 'adds an error' do
|
34
|
+
model = WorkingModel.new
|
35
|
+
model.send :default_locale_presence_validation
|
36
|
+
model.errors.should_not be_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when default locale exist' do
|
41
|
+
it 'does not add an error' do
|
42
|
+
model = WorkingModel.new
|
43
|
+
model.set_name_translation I18n.default_locale, 'w'
|
44
|
+
model.send :default_locale_presence_validation
|
45
|
+
model.errors.should be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -24,17 +24,10 @@ describe EfficientTranslations do
|
|
24
24
|
lambda { model.translates :content }.should_not raise_error
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
27
|
+
it 'fills a translated_fields list' do
|
28
28
|
model = my_model_class
|
29
|
-
model.should_receive :make_efficient_translatable!
|
30
29
|
model.translates :name
|
31
|
-
|
32
|
-
|
33
|
-
it 'should not regenerate the translation model when called multiple times' do
|
34
|
-
model = my_model_class
|
35
|
-
model.translates :name
|
36
|
-
model.should_not_receive :make_efficient_translatable!
|
37
|
-
model.translates :content
|
30
|
+
model.translated_fields.should =~ [:name]
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
@@ -1,58 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '::build' do
|
11
|
-
context 'when no translation model is found' do
|
12
|
-
before do
|
13
|
-
@klass = Class.new(ActiveRecord::Base)
|
14
|
-
@model_class.stub :const_set => @klass
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should create a new ::Translation class' do
|
18
|
-
@model_class.should_receive(:const_set).with(:Translation, kind_of(Class)) { |name, klass| klass }
|
19
|
-
EfficientTranslations::TranslationFactory::build @model_class
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should define a belongs_to association to the main model' do
|
23
|
-
@klass.should_receive(:belongs_to)
|
24
|
-
EfficientTranslations::TranslationFactory::build @model_class
|
3
|
+
module EfficientTranslations
|
4
|
+
describe TranslationFactory do
|
5
|
+
before :each do
|
6
|
+
Kernel.silence_warnings do
|
7
|
+
@model_class = Object.const_set :MyModel, Class.new(ActiveRecord::Base)
|
25
8
|
end
|
9
|
+
end
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
translation
|
30
|
-
|
11
|
+
describe '::translation_model' do
|
12
|
+
context "the first time it's invoked on a model" do
|
13
|
+
it 'defines the translation model' do
|
14
|
+
expect { @model_class.const_get :Translation }.to raise_error NameError
|
15
|
+
TranslationFactory.translation_model_for @model_class
|
16
|
+
expect { @model_class.const_get :Translation }.to_not raise_error NameError
|
17
|
+
end
|
31
18
|
|
32
|
-
|
33
|
-
|
34
|
-
|
19
|
+
it 'includes the TranslationModel module in the translation model' do
|
20
|
+
TranslationFactory.translation_model_for(@model_class).included_modules.should include TranslationModel
|
21
|
+
end
|
35
22
|
end
|
36
23
|
|
37
|
-
it '
|
38
|
-
|
39
|
-
@model_class.
|
40
|
-
EfficientTranslations::TranslationFactory::build(@model_class).should == klass
|
24
|
+
it 'returns the existing translation_model' do
|
25
|
+
t = TranslationFactory.translation_model_for @model_class
|
26
|
+
TranslationFactory.translation_model_for(@model_class).should == t
|
41
27
|
end
|
42
28
|
end
|
43
29
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
describe '::build_translation_model' do
|
31
|
+
before { @translation_model = TranslationFactory.translation_model_for @model_class }
|
32
|
+
|
33
|
+
context 'when translation model is not built' do
|
34
|
+
it 'sets translatable model reader' do
|
35
|
+
@translation_model.translatable_model.should be_nil
|
36
|
+
TranslationFactory.build_translation_model @model_class
|
37
|
+
@translation_model.translatable_model.should == @model_class
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets translatable relation field reader' do
|
41
|
+
@translation_model.translatable_relation_field.should be_nil
|
42
|
+
TranslationFactory.build_translation_model @model_class
|
43
|
+
@translation_model.translatable_relation_field.should == :my_model
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when translation model is already built' do
|
48
|
+
it 'raises an error' do
|
49
|
+
TranslationFactory.build_translation_model(@model_class)
|
50
|
+
TranslationFactory.translation_model_for(@model_class).should_not_receive(:belongs_to)
|
51
|
+
expect {
|
52
|
+
TranslationFactory.build_translation_model @model_class
|
53
|
+
}.to raise_error
|
54
|
+
end
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module EfficientTranslations
|
4
|
+
describe TranslationModel do
|
5
|
+
it 'is included in WorkingModel::Translation' do
|
6
|
+
WorkingModel::Translation.included_modules.should include TranslationModel
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'defines a stringify_locale! method' do
|
10
|
+
instance = WorkingModel::Translation.new :locale => :us
|
11
|
+
expect {
|
12
|
+
instance.send :stringify_locale!
|
13
|
+
}.to change(instance, :locale).to 'us'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'defines a translatable_model reader' do
|
17
|
+
WorkingModel::Translation.translatable_model.should == WorkingModel
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'defines a translatable_relation_field reader' do
|
21
|
+
WorkingModel::Translation.translatable_relation_field.should == :working_model
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'defines a for_locale named_scope' do
|
25
|
+
WorkingModel::Translation.should respond_to :for_locale
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'defines a before_save filter to force the locale in string' do
|
29
|
+
WorkingModel::Translation.before_save_callback_chain.map(&:method).should include :stringify_locale!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: efficient_translations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70173405313380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70173405313380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70173405312760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70173405312760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70173405312000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,32 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70173405312000
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard
|
49
|
+
requirement: &70173405311100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70173405311100
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard-rspec
|
60
|
+
requirement: &70173405310360 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70173405310360
|
47
69
|
- !ruby/object:Gem::Dependency
|
48
70
|
name: activerecord
|
49
|
-
requirement: &
|
71
|
+
requirement: &70173405309360 !ruby/object:Gem::Requirement
|
50
72
|
none: false
|
51
73
|
requirements:
|
52
74
|
- - ~>
|
@@ -54,10 +76,10 @@ dependencies:
|
|
54
76
|
version: '2.3'
|
55
77
|
type: :runtime
|
56
78
|
prerelease: false
|
57
|
-
version_requirements: *
|
79
|
+
version_requirements: *70173405309360
|
58
80
|
- !ruby/object:Gem::Dependency
|
59
81
|
name: activesupport
|
60
|
-
requirement: &
|
82
|
+
requirement: &70173405308540 !ruby/object:Gem::Requirement
|
61
83
|
none: false
|
62
84
|
requirements:
|
63
85
|
- - ~>
|
@@ -65,7 +87,7 @@ dependencies:
|
|
65
87
|
version: '2.3'
|
66
88
|
type: :runtime
|
67
89
|
prerelease: false
|
68
|
-
version_requirements: *
|
90
|
+
version_requirements: *70173405308540
|
69
91
|
description: Translation library for ActiveRecord models in Rails 2
|
70
92
|
email:
|
71
93
|
- nicola@nicolaracco.com
|
@@ -74,20 +96,26 @@ extensions: []
|
|
74
96
|
extra_rdoc_files: []
|
75
97
|
files:
|
76
98
|
- .gitignore
|
99
|
+
- .rspec
|
77
100
|
- Gemfile
|
78
|
-
-
|
101
|
+
- Guardfile
|
79
102
|
- README.md
|
80
103
|
- Rakefile
|
81
104
|
- efficient_translations.gemspec
|
105
|
+
- lib/active_support/concern.rb
|
82
106
|
- lib/efficient_translations.rb
|
83
107
|
- lib/efficient_translations/schema.rb
|
108
|
+
- lib/efficient_translations/translatable_model.rb
|
84
109
|
- lib/efficient_translations/translates_method.rb
|
85
110
|
- lib/efficient_translations/translation_factory.rb
|
111
|
+
- lib/efficient_translations/translation_model.rb
|
86
112
|
- lib/efficient_translations/version.rb
|
87
113
|
- spec/fixtures/schema.rb
|
88
114
|
- spec/lib/efficient_translations/schema_spec.rb
|
115
|
+
- spec/lib/efficient_translations/translatable_model_spec.rb
|
89
116
|
- spec/lib/efficient_translations/translates_method_spec.rb
|
90
117
|
- spec/lib/efficient_translations/translation_factory_spec.rb
|
118
|
+
- spec/lib/efficient_translations/translation_model_spec.rb
|
91
119
|
- spec/spec_helper.rb
|
92
120
|
- spec/support/fake_schema_adapter.rb
|
93
121
|
- spec/support/working_model.rb
|
@@ -105,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
133
|
version: '0'
|
106
134
|
segments:
|
107
135
|
- 0
|
108
|
-
hash:
|
136
|
+
hash: 1567763944166599876
|
109
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
138
|
none: false
|
111
139
|
requirements:
|
@@ -114,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
142
|
version: '0'
|
115
143
|
segments:
|
116
144
|
- 0
|
117
|
-
hash:
|
145
|
+
hash: 1567763944166599876
|
118
146
|
requirements: []
|
119
147
|
rubyforge_project:
|
120
148
|
rubygems_version: 1.8.10
|
@@ -124,8 +152,10 @@ summary: Translation library for ActiveRecord models in Rails 2 with an eye on p
|
|
124
152
|
test_files:
|
125
153
|
- spec/fixtures/schema.rb
|
126
154
|
- spec/lib/efficient_translations/schema_spec.rb
|
155
|
+
- spec/lib/efficient_translations/translatable_model_spec.rb
|
127
156
|
- spec/lib/efficient_translations/translates_method_spec.rb
|
128
157
|
- spec/lib/efficient_translations/translation_factory_spec.rb
|
158
|
+
- spec/lib/efficient_translations/translation_model_spec.rb
|
129
159
|
- spec/spec_helper.rb
|
130
160
|
- spec/support/fake_schema_adapter.rb
|
131
161
|
- spec/support/working_model.rb
|
data/Gemfile.lock
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
efficient_translations (0.0.8)
|
5
|
-
activerecord (~> 2.3)
|
6
|
-
activesupport (~> 2.3)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activerecord (2.3.14)
|
12
|
-
activesupport (= 2.3.14)
|
13
|
-
activesupport (2.3.14)
|
14
|
-
diff-lcs (1.1.3)
|
15
|
-
rake (0.9.2.2)
|
16
|
-
rspec (2.7.0)
|
17
|
-
rspec-core (~> 2.7.0)
|
18
|
-
rspec-expectations (~> 2.7.0)
|
19
|
-
rspec-mocks (~> 2.7.0)
|
20
|
-
rspec-core (2.7.1)
|
21
|
-
rspec-expectations (2.7.0)
|
22
|
-
diff-lcs (~> 1.1.2)
|
23
|
-
rspec-mocks (2.7.0)
|
24
|
-
sqlite3 (1.3.5)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
efficient_translations!
|
31
|
-
rake
|
32
|
-
rspec
|
33
|
-
sqlite3
|