has_localization_table 0.3.5 → 0.3.6

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWMxOGEwOTdjY2U5OWM3YTAwZDNhN2RhMWQ1N2IyODQ3YWZkYjU5YQ==
4
+ ZTA1YWMxMTY1ODUxODQ4ZDVkZjU3Yjk2OTkyZmEwNmM1NzU2NWY4OQ==
5
5
  data.tar.gz: !binary |-
6
- YzUzNzFiMzk3MDViYzZmOWE4NWM3NzQ2ZjIzOWE4NTkxYzkwMjcyNA==
6
+ OGYwY2ZkNDFkY2E0YTg1OWMyN2FlNGNmMmRjOTM2YTRkMTI3NjViOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmUzNzEyOTAxMGYyNGY5MmM4MWEwNjFiZTY4M2FiY2Q0Y2Y4Njc1ZjZiZjRh
10
- ZDQwMGE1ODM4ZmFhNGVlYjc3NWYyNWQ2NmQ0MzY0MWI5NjU5NGU5ODBmODZl
11
- ZWE1NGVkNzIxMWQ2ZDgxZTUyZmUxNWMxNDc5ZGJiZmY4YTY0Zjg=
9
+ ZWUzMTFjZDg0ZDZlMjUwMTMyYTFiOWQ4ZDczMTZlMTQ1NTRmMzk0NGY4NzBh
10
+ NGM2NTcxYzk4ODc1ZjlmNDBjNjdlYzE2Y2M5MTRhOTliMTY1NGJiY2U2N2Rj
11
+ N2Q2ODNhZGU3ZmMwNDgyOGI5NjA2ODlmMjljOGFmMjQzZjk0MTU=
12
12
  data.tar.gz: !binary |-
13
- M2Y4YzlhZTBjZThmZTM4ZDQwNTQyYTYxMGRlZjgwNmYyZWJjYTkxNDViNWMz
14
- YTg1ZTk5YzEwMjY3MDkzNWFmZTNlYzc3ZjFiNzI4ZjliYTliMjc4YTE0MTMy
15
- ZDI4YzJiODE2NjM4NTQ3ODkwNDkwNThmNTYzZGY4YWJlODIxMGU=
13
+ MGZlNWM1MmMzOGQ4OTJhYzQ2OWU2ZDVkNzc1MjBmYTQ5YmY0YTRlZDg5MTVh
14
+ Y2JkYzU5ZGRiMjc5MjY1MGFkYWNjNzhlODM0ZjJkYjkwYjAzZDE0ZDU1OWQy
15
+ YzU0MDJlMTAyNmQ0YjU4MDY4YmJiNjFiYWEzYWI0MGEyZjc1NTI=
@@ -19,5 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency 'activerecord', ['>= 3.0.0']
20
20
  gem.add_development_dependency 'minitest'
21
21
  gem.add_development_dependency 'sqlite3'
22
+ gem.add_development_dependency 'rake'
22
23
  end
23
24
 
@@ -46,7 +46,7 @@ module HasLocalizationTable
46
46
 
47
47
  # Collect all localizations for the object
48
48
  def create_has_many_association
49
- self.has_many localization_association_name, localization_table_options.except(:association_name, :required, :optional, :has_one) do
49
+ self.has_many localization_association_name, localization_table_options.except(:association_name, :required, :optional, :has_one).reverse_merge(autosave: true) do
50
50
  def for_locale(locale)
51
51
  # where(HasLocalizationTable.locale_foreign_key => locale).first
52
52
  select{ |s| s.send(HasLocalizationTable.locale_foreign_key) == locale }.first
@@ -13,7 +13,7 @@ module HasLocalizationTable
13
13
 
14
14
  # Add validation to ensure a string for the primary locale exists if the string is required
15
15
  validate do
16
- if localization_table_options[:required] || false
16
+ if localization_table_options.fetch(:required, false)
17
17
  errors.add(localization_association_name, :primary_lang_string_required) unless localization_association.any? do |string|
18
18
  string.send(HasLocalizationTable.locale_foreign_key) == HasLocalizationTable.primary_locale.id
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module HasLocalizationTable
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -32,6 +32,12 @@ describe HasLocalizationTable do
32
32
  a.name.must_equal "Test"
33
33
  a.description.must_equal "Description"
34
34
  end
35
+
36
+ it "should save with update_attributes" do
37
+ a.save!
38
+ a.update_attributes!(name: "Test 2")
39
+ Article.find(a.id).name.must_equal "Test 2"
40
+ end
35
41
 
36
42
  it "should create mutator methods" do
37
43
  a.name = "Changed"
@@ -15,19 +15,26 @@ describe HasLocalizationTable do
15
15
  end
16
16
 
17
17
  let(:a) { Article.new(name: "Test", description: "Description") }
18
-
19
- it "should add validations if given required: true" do
20
- Article.has_localization_table required: true
21
- a = Article.new
22
- refute a.valid?
23
- a.errors[:localizations].wont_be_empty
24
-
25
- a = Article.new(description: "Wishing the world hello!")
26
- s = a.localizations.first
27
- refute s.valid?
28
- s.errors[:name].wont_be_empty
18
+
19
+ describe 'when the required option is true' do
20
+ before { Article.has_localization_table required: true }
21
+
22
+ it "should add an error to the base class if a string is not given" do
23
+ Article.has_localization_table required: true
24
+ a = Article.new
25
+ refute a.valid?
26
+ a.errors.wont_be_empty
27
+ end
28
+
29
+ it 'should add an error to the association column if a string is not given' do
30
+ Article.has_localization_table required: true
31
+ a = Article.new(description: "Wishing the world hello!")
32
+ s = a.localizations.first
33
+ refute s.valid?
34
+ s.errors[:name].wont_be_empty
35
+ end
29
36
  end
30
-
37
+
31
38
  it "should not add validations if given required: false" do
32
39
  Article.has_localization_table required: false
33
40
  a = Article.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_localization_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  type: :runtime
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ prerelease: false
72
+ name: rake
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Automatically sets up usage of a relational table to contain user-created
70
84
  multi-locale string attributes
71
85
  email:
@@ -95,7 +109,7 @@ files:
95
109
  - spec/active_record/finder_method_spec.rb
96
110
  - spec/active_record/ordered_by_spec.rb
97
111
  - spec/active_record/relation_spec.rb
98
- - spec/active_record/validation_spec.rb
112
+ - spec/active_record/validations_spec.rb
99
113
  - spec/active_record_spec.rb
100
114
  - spec/spec_helper.rb
101
115
  - spec/support/setup.rb
@@ -128,7 +142,7 @@ test_files:
128
142
  - spec/active_record/finder_method_spec.rb
129
143
  - spec/active_record/ordered_by_spec.rb
130
144
  - spec/active_record/relation_spec.rb
131
- - spec/active_record/validation_spec.rb
145
+ - spec/active_record/validations_spec.rb
132
146
  - spec/active_record_spec.rb
133
147
  - spec/spec_helper.rb
134
148
  - spec/support/setup.rb