simple_model_translations 0.1.7 → 0.1.8
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/.rspec +2 -0
- data/Gemfile +1 -9
- data/Gemfile.lock +7 -0
- data/LICENSE +1 -1
- data/Rakefile +1 -2
- data/lib/simple_model_translations.rb +1 -0
- data/lib/simple_model_translations/base.rb +2 -1
- data/lib/simple_model_translations/version.rb +1 -1
- data/simple_model_translations.gemspec +1 -1
- data/spec/data/schema.rb +8 -3
- data/spec/nested_attributes_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -8
- metadata +7 -4
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_model_translations (0.1.8)
|
5
|
+
activerecord (~> 3.0.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
@@ -39,4 +45,5 @@ DEPENDENCIES
|
|
39
45
|
database_cleaner (~> 0.5.2)
|
40
46
|
rspec (~> 2.0.0)
|
41
47
|
shoulda (~> 2.11.3)
|
48
|
+
simple_model_translations!
|
42
49
|
sqlite3-ruby (~> 1.3.1)
|
data/LICENSE
CHANGED
data/Rakefile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'simple_model_translations/version'
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
5
|
require 'rake'
|
5
|
-
require 'simple_model_translations/version'
|
6
6
|
require 'rspec/core/rake_task'
|
7
7
|
require 'rake/rdoctask'
|
8
8
|
|
9
9
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
-
spec.rspec_opts = %w(-fs --color)
|
11
10
|
end
|
12
11
|
|
13
12
|
Rake::RDocTask.new do |rdoc|
|
@@ -53,7 +53,8 @@ module SimpleModelTranslations
|
|
53
53
|
has_many :translations, :class_name => translation_class.name, :dependent => :destroy, :autosave => true
|
54
54
|
|
55
55
|
if options[:attributes]
|
56
|
-
|
56
|
+
nested_attributes = options[:attributes].is_a?(Hash) ? options[:attributes] : {}
|
57
|
+
accepts_nested_attributes_for :translations, nested_attributes.reverse_merge(:allow_destroy => true)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = 'Simple ActiveRecord translations for Rails 3'
|
14
14
|
s.description = 'Simple ActiveRecord translations for Rails 3'
|
15
15
|
s.require_path = 'lib'
|
16
|
-
s.files = Dir.glob('{spec,lib}/**/*') + %w(Gemfile Gemfile.lock LICENSE Rakefile README.rdoc simple_model_translations.gemspec)
|
16
|
+
s.files = Dir.glob('{spec,lib}/**/*') + %w(Gemfile Gemfile.lock LICENSE Rakefile README.rdoc simple_model_translations.gemspec .rspec)
|
17
17
|
s.test_files = Dir.glob('spec/**/*')
|
18
18
|
s.extra_rdoc_files = %w(LICENSE README.rdoc)
|
19
19
|
|
data/spec/data/schema.rb
CHANGED
@@ -32,13 +32,18 @@ ActiveRecord::Schema.define do
|
|
32
32
|
t.string :name
|
33
33
|
end
|
34
34
|
|
35
|
-
create_table :categories, :force => true
|
36
|
-
end
|
37
|
-
|
35
|
+
create_table :categories, :force => true
|
38
36
|
create_table :category_translations, :force => true do |t|
|
39
37
|
t.string :locale
|
40
38
|
t.references :category
|
41
39
|
t.string :name
|
42
40
|
end
|
41
|
+
|
42
|
+
create_table :some_models, :force => true
|
43
|
+
create_table :some_model_translations, :force => true do |t|
|
44
|
+
t.string :locale
|
45
|
+
t.references :some_models
|
46
|
+
t.string :name
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe SimpleModelTranslations do
|
4
|
+
context 'when generating nested attributes' do
|
5
|
+
before do
|
6
|
+
SomeModel = Class.new(ActiveRecord::Base)
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Object.send(:remove_const, :SomeModel)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can use options[:attributes] as a Hash' do
|
14
|
+
options = { :reject_if => lambda { |attrs| attrs[:name].blank? } }
|
15
|
+
SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, options.merge(:allow_destroy => true))
|
16
|
+
SomeModel.translates :name, :attributes => options
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can use options[:attributes] as a Boolean' do
|
20
|
+
SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => true })
|
21
|
+
SomeModel.translates :name, :attributes => true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should enable translations' deletion by default" do
|
25
|
+
SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => true })
|
26
|
+
SomeModel.translates :name, :attributes => true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow to disable translations' deletion" do
|
30
|
+
SomeModel.should_receive(:accepts_nested_attributes_for).with(:translations, { :allow_destroy => false })
|
31
|
+
SomeModel.translates :name, :attributes => { :allow_destroy => false }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
1
|
require 'bundler'
|
4
|
-
Bundler.require(:default, :
|
5
|
-
|
6
|
-
require 'rspec'
|
7
|
-
require 'shoulda'
|
8
|
-
require 'active_record'
|
9
|
-
require 'simple_model_translations'
|
2
|
+
Bundler.require(:default, :development)
|
10
3
|
|
11
4
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
12
5
|
DatabaseCleaner.strategy = :transaction
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_model_translations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavel Forkert
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10
|
18
|
+
date: 2010-11-10 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- spec/class_methods_spec.rb
|
114
114
|
- spec/data/models.rb
|
115
115
|
- spec/data/schema.rb
|
116
|
+
- spec/nested_attributes_spec.rb
|
116
117
|
- spec/simple_model_translations_spec.rb
|
117
118
|
- spec/spec_helper.rb
|
118
119
|
- spec/validations_spec.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- Rakefile
|
130
131
|
- README.rdoc
|
131
132
|
- simple_model_translations.gemspec
|
133
|
+
- .rspec
|
132
134
|
has_rdoc: true
|
133
135
|
homepage: http://github.com/fxposter/simple_model_translations
|
134
136
|
licenses: []
|
@@ -171,6 +173,7 @@ test_files:
|
|
171
173
|
- spec/class_methods_spec.rb
|
172
174
|
- spec/data/models.rb
|
173
175
|
- spec/data/schema.rb
|
176
|
+
- spec/nested_attributes_spec.rb
|
174
177
|
- spec/simple_model_translations_spec.rb
|
175
178
|
- spec/spec_helper.rb
|
176
179
|
- spec/validations_spec.rb
|