has_translations 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90c1cd38c3c0b3dd760c062f77d2f73fe67cd1de
4
- data.tar.gz: 3f79739a23be82fe00dd03c61058e5a21502a560
3
+ metadata.gz: ebb79aa35a255aab202ab14e115dfe6b2c60a1c7
4
+ data.tar.gz: 7607fe1ceeb9a72dedf171983a48030696c2163a
5
5
  SHA512:
6
- metadata.gz: 6685cbcc8b660f95b509764e9c21d847be5feb4fded8b96dadf0787d6e3b136198b8cb0ae003cb08ebb332de01512598480d85d4e7d897a84afe1ae1c04bb412
7
- data.tar.gz: c9d71e17d3ec0f84e6ea271666422c0a90c837f6877ccd971e4d1dbb90e2c12777790c72f3756802656d1845937dbf50c66d288afe7097537ee4b6a2d12d8bb6
6
+ metadata.gz: 505f35d9261d950b849ad2005466b2323bb922d495de4aeec6d1cec2dc4f77bde2883b8521af1248024cbd16e384e11788761bc2c84c25e086611fa8dc342777
7
+ data.tar.gz: 03be45ac7decd35b2281fd7c2b5525d5dd186249ca2e7c6f652ae9a63aa5e20c27dd1026d310b4c3053591a462754158479e2eb21bb1dce7ae5aee1e134ae4b6
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.7
5
- - 2.2.3
4
+ - 2.1.9
5
+ - 2.2.5
6
+ - 2.3.1
6
7
  before_install:
7
8
  - "gem install bundler -v=1.10.6"
8
9
  before_script:
@@ -13,4 +14,5 @@ gemfile:
13
14
  - gemfiles/4.0.gemfile
14
15
  - gemfiles/4.1.gemfile
15
16
  - gemfiles/4.2.gemfile
17
+ - gemfiles/5.0.gemfile
16
18
  cache: bundler
data/Appraisals CHANGED
@@ -13,3 +13,8 @@ end
13
13
  appraise '4.2' do
14
14
  gem 'rails', '4.2.4'
15
15
  end
16
+
17
+
18
+ appraise '5.0' do
19
+ gem 'rails', '5.0.0'
20
+ end
data/Gemfile.lock CHANGED
@@ -1,35 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- has_translations (1.1.0)
4
+ has_translations (1.1.1)
5
5
  activerecord (>= 3.2.0)
6
6
  activesupport (>= 3.2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (4.2.4)
12
- activesupport (= 4.2.4)
13
- builder (~> 3.1)
14
- activerecord (4.2.4)
15
- activemodel (= 4.2.4)
16
- activesupport (= 4.2.4)
17
- arel (~> 6.0)
18
- activesupport (4.2.4)
11
+ activemodel (5.0.0)
12
+ activesupport (= 5.0.0)
13
+ activerecord (5.0.0)
14
+ activemodel (= 5.0.0)
15
+ activesupport (= 5.0.0)
16
+ arel (~> 7.0)
17
+ activesupport (5.0.0)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (~> 0.7)
20
- json (~> 1.7, >= 1.7.7)
21
20
  minitest (~> 5.1)
22
- thread_safe (~> 0.3, >= 0.3.4)
23
21
  tzinfo (~> 1.1)
24
22
  appraisal (2.1.0)
25
23
  bundler
26
24
  rake
27
25
  thor (>= 0.14.0)
28
- arel (6.0.3)
29
- builder (3.2.2)
26
+ arel (7.0.0)
27
+ concurrent-ruby (1.0.2)
30
28
  i18n (0.7.0)
31
- json (1.8.3)
32
- minitest (5.8.2)
29
+ minitest (5.9.0)
33
30
  power_assert (0.2.5)
34
31
  rake (10.4.2)
35
32
  sqlite3 (1.3.11)
@@ -51,4 +48,4 @@ DEPENDENCIES
51
48
  test-unit
52
49
 
53
50
  BUNDLED WITH
54
- 1.10.6
51
+ 1.12.4
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  HasTranslations
2
2
  ==============================
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/dmitry/has_translations.png?branch=master)](http://travis-ci.org/dmitry/has_translations)
4
+ [![Build Status](https://secure.travis-ci.org/dmitry/has_translations.png?branch=master)](http://travis-ci.org/dmitry/has_translations)
5
5
  [![Gem Version](https://badge.fury.io/rb/has_translations.png)](http://badge.fury.io/rb/has_translations)
6
6
 
7
7
  This simple plugin creates translations for your model.
8
8
  Uses delegation pattern: http://en.wikipedia.org/wiki/Delegation_pattern
9
9
 
10
- Tested with ActiveRecord versions: 3.2.x, 4.0.x, 4.1.x, 4.2.x
11
- And tested with ruby 1.9.3, 2.0.0, 2.1.x, 2.2.x
10
+ Tested with ActiveRecord versions: 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0.x
11
+ And tested with ruby 1.9.3, 2.0.0, 2.1.x, 2.2.x, 2.3.x
12
12
 
13
13
  Compatibility
14
14
  =============
@@ -78,6 +78,7 @@ Options:
78
78
  * `:writer => true` [default: false] - add writer to the model object
79
79
  * `:autosave => true` [default: false] - use [autosave option](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many) for the ActiveRecord translations relation
80
80
  * `:nil => nil` [default: ''] - if no model found by default returns empty string, you can set it for example to `nil` (no `lambda` supported)
81
+ * `:foreign_key => nil` [default: nil] - add the foreign_key for has_many and belogns_to associations
81
82
 
82
83
  It's better to use translations with `accepts_nested_attributes_for`:
83
84
 
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ Rake::TestTask.new do |t|
6
6
  t.libs = %w(lib test)
7
7
  t.test_files = Dir.glob('test/**/*_test.rb').sort
8
8
  t.verbose = true
9
+ # t.warning = false
9
10
  end
10
11
 
11
12
  task :default => :test
@@ -8,12 +8,12 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (3.2.22)
12
- actionpack (= 3.2.22)
11
+ actionmailer (3.2.22.2)
12
+ actionpack (= 3.2.22.2)
13
13
  mail (~> 2.5.4)
14
- actionpack (3.2.22)
15
- activemodel (= 3.2.22)
16
- activesupport (= 3.2.22)
14
+ actionpack (3.2.22.2)
15
+ activemodel (= 3.2.22.2)
16
+ activesupport (= 3.2.22.2)
17
17
  builder (~> 3.0.0)
18
18
  erubis (~> 2.7.0)
19
19
  journey (~> 1.0.4)
@@ -21,18 +21,18 @@ GEM
21
21
  rack-cache (~> 1.2)
22
22
  rack-test (~> 0.6.1)
23
23
  sprockets (~> 2.2.1)
24
- activemodel (3.2.22)
25
- activesupport (= 3.2.22)
24
+ activemodel (3.2.22.2)
25
+ activesupport (= 3.2.22.2)
26
26
  builder (~> 3.0.0)
27
- activerecord (3.2.22)
28
- activemodel (= 3.2.22)
29
- activesupport (= 3.2.22)
27
+ activerecord (3.2.22.2)
28
+ activemodel (= 3.2.22.2)
29
+ activesupport (= 3.2.22.2)
30
30
  arel (~> 3.0.2)
31
31
  tzinfo (~> 0.3.29)
32
- activeresource (3.2.22)
33
- activemodel (= 3.2.22)
34
- activesupport (= 3.2.22)
35
- activesupport (3.2.22)
32
+ activeresource (3.2.22.2)
33
+ activemodel (= 3.2.22.2)
34
+ activesupport (= 3.2.22.2)
35
+ activesupport (3.2.22.2)
36
36
  i18n (~> 0.6, >= 0.6.4)
37
37
  multi_json (~> 1.0)
38
38
  appraisal (2.1.0)
@@ -50,32 +50,32 @@ GEM
50
50
  mime-types (~> 1.16)
51
51
  treetop (~> 1.4.8)
52
52
  mime-types (1.25.1)
53
- multi_json (1.11.2)
53
+ multi_json (1.12.1)
54
54
  polyglot (0.3.5)
55
- power_assert (0.2.5)
55
+ power_assert (0.3.0)
56
56
  rack (1.4.7)
57
- rack-cache (1.5.1)
57
+ rack-cache (1.6.1)
58
58
  rack (>= 0.4)
59
59
  rack-ssl (1.3.4)
60
60
  rack
61
61
  rack-test (0.6.3)
62
62
  rack (>= 1.0)
63
- rails (3.2.22)
64
- actionmailer (= 3.2.22)
65
- actionpack (= 3.2.22)
66
- activerecord (= 3.2.22)
67
- activeresource (= 3.2.22)
68
- activesupport (= 3.2.22)
63
+ rails (3.2.22.2)
64
+ actionmailer (= 3.2.22.2)
65
+ actionpack (= 3.2.22.2)
66
+ activerecord (= 3.2.22.2)
67
+ activeresource (= 3.2.22.2)
68
+ activesupport (= 3.2.22.2)
69
69
  bundler (~> 1.0)
70
- railties (= 3.2.22)
71
- railties (3.2.22)
72
- actionpack (= 3.2.22)
73
- activesupport (= 3.2.22)
70
+ railties (= 3.2.22.2)
71
+ railties (3.2.22.2)
72
+ actionpack (= 3.2.22.2)
73
+ activesupport (= 3.2.22.2)
74
74
  rack-ssl (~> 1.3.2)
75
75
  rake (>= 0.8.7)
76
76
  rdoc (~> 3.4)
77
77
  thor (>= 0.14.6, < 2.0)
78
- rake (10.4.2)
78
+ rake (11.2.2)
79
79
  rdoc (3.12.2)
80
80
  json (~> 1.4)
81
81
  sprockets (2.2.3)
@@ -84,14 +84,14 @@ GEM
84
84
  rack (~> 1.0)
85
85
  tilt (~> 1.1, != 1.3.0)
86
86
  sqlite3 (1.3.11)
87
- test-unit (3.1.5)
87
+ test-unit (3.2.0)
88
88
  power_assert
89
89
  thor (0.19.1)
90
90
  tilt (1.4.1)
91
91
  treetop (1.4.15)
92
92
  polyglot
93
93
  polyglot (>= 0.3.1)
94
- tzinfo (0.3.45)
94
+ tzinfo (0.3.51)
95
95
 
96
96
  PLATFORMS
97
97
  ruby
@@ -105,4 +105,4 @@ DEPENDENCIES
105
105
  test-unit
106
106
 
107
107
  BUNDLED WITH
108
- 1.10.6
108
+ 1.12.4
@@ -38,14 +38,17 @@ GEM
38
38
  thor (>= 0.14.0)
39
39
  arel (4.0.2)
40
40
  builder (3.1.4)
41
+ concurrent-ruby (1.0.2)
41
42
  erubis (2.7.0)
42
43
  i18n (0.7.0)
43
- mail (2.6.3)
44
- mime-types (>= 1.16, < 3)
45
- mime-types (2.6.2)
44
+ mail (2.6.4)
45
+ mime-types (>= 1.16, < 4)
46
+ mime-types (3.1)
47
+ mime-types-data (~> 3.2015)
48
+ mime-types-data (3.2016.0521)
46
49
  minitest (4.7.5)
47
- multi_json (1.11.2)
48
- power_assert (0.2.5)
50
+ multi_json (1.12.1)
51
+ power_assert (0.3.0)
49
52
  rack (1.5.5)
50
53
  rack-test (0.6.3)
51
54
  rack (>= 1.0)
@@ -62,19 +65,20 @@ GEM
62
65
  activesupport (= 4.0.13)
63
66
  rake (>= 0.8.7)
64
67
  thor (>= 0.18.1, < 2.0)
65
- rake (10.4.2)
66
- sprockets (3.4.0)
68
+ rake (11.2.2)
69
+ sprockets (3.6.3)
70
+ concurrent-ruby (~> 1.0)
67
71
  rack (> 1, < 3)
68
72
  sprockets-rails (2.3.3)
69
73
  actionpack (>= 3.0)
70
74
  activesupport (>= 3.0)
71
75
  sprockets (>= 2.8, < 4.0)
72
76
  sqlite3 (1.3.11)
73
- test-unit (3.1.5)
77
+ test-unit (3.2.0)
74
78
  power_assert
75
79
  thor (0.19.1)
76
80
  thread_safe (0.3.5)
77
- tzinfo (0.3.45)
81
+ tzinfo (0.3.51)
78
82
 
79
83
  PLATFORMS
80
84
  ruby
@@ -88,4 +92,4 @@ DEPENDENCIES
88
92
  test-unit
89
93
 
90
94
  BUNDLED WITH
91
- 1.10.6
95
+ 1.12.4
@@ -40,14 +40,17 @@ GEM
40
40
  thor (>= 0.14.0)
41
41
  arel (5.0.1.20140414130214)
42
42
  builder (3.2.2)
43
+ concurrent-ruby (1.0.2)
43
44
  erubis (2.7.0)
44
45
  i18n (0.7.0)
45
46
  json (1.8.3)
46
- mail (2.6.3)
47
- mime-types (>= 1.16, < 3)
48
- mime-types (2.6.2)
49
- minitest (5.8.2)
50
- power_assert (0.2.5)
47
+ mail (2.6.4)
48
+ mime-types (>= 1.16, < 4)
49
+ mime-types (3.1)
50
+ mime-types-data (~> 3.2015)
51
+ mime-types-data (3.2016.0521)
52
+ minitest (5.9.0)
53
+ power_assert (0.3.0)
51
54
  rack (1.5.5)
52
55
  rack-test (0.6.3)
53
56
  rack (>= 1.0)
@@ -66,15 +69,16 @@ GEM
66
69
  activesupport (= 4.1.13)
67
70
  rake (>= 0.8.7)
68
71
  thor (>= 0.18.1, < 2.0)
69
- rake (10.4.2)
70
- sprockets (3.4.0)
72
+ rake (11.2.2)
73
+ sprockets (3.6.3)
74
+ concurrent-ruby (~> 1.0)
71
75
  rack (> 1, < 3)
72
76
  sprockets-rails (2.3.3)
73
77
  actionpack (>= 3.0)
74
78
  activesupport (>= 3.0)
75
79
  sprockets (>= 2.8, < 4.0)
76
80
  sqlite3 (1.3.11)
77
- test-unit (3.1.5)
81
+ test-unit (3.2.0)
78
82
  power_assert
79
83
  thor (0.19.1)
80
84
  thread_safe (0.3.5)
@@ -93,4 +97,4 @@ DEPENDENCIES
93
97
  test-unit
94
98
 
95
99
  BUNDLED WITH
96
- 1.10.6
100
+ 1.12.4
@@ -49,6 +49,7 @@ GEM
49
49
  thor (>= 0.14.0)
50
50
  arel (6.0.3)
51
51
  builder (3.2.2)
52
+ concurrent-ruby (1.0.2)
52
53
  erubis (2.7.0)
53
54
  globalid (0.3.6)
54
55
  activesupport (>= 4.1.0)
@@ -56,14 +57,18 @@ GEM
56
57
  json (1.8.3)
57
58
  loofah (2.0.3)
58
59
  nokogiri (>= 1.5.9)
59
- mail (2.6.3)
60
- mime-types (>= 1.16, < 3)
61
- mime-types (2.6.2)
62
- mini_portile (0.6.2)
63
- minitest (5.8.2)
64
- nokogiri (1.6.6.2)
65
- mini_portile (~> 0.6.0)
66
- power_assert (0.2.5)
60
+ mail (2.6.4)
61
+ mime-types (>= 1.16, < 4)
62
+ mime-types (3.1)
63
+ mime-types-data (~> 3.2015)
64
+ mime-types-data (3.2016.0521)
65
+ mini_portile2 (2.1.0)
66
+ minitest (5.9.0)
67
+ nokogiri (1.6.8)
68
+ mini_portile2 (~> 2.1.0)
69
+ pkg-config (~> 1.1.7)
70
+ pkg-config (1.1.7)
71
+ power_assert (0.3.0)
67
72
  rack (1.6.4)
68
73
  rack-test (0.6.3)
69
74
  rack (>= 1.0)
@@ -84,22 +89,23 @@ GEM
84
89
  activesupport (>= 4.2.0.beta, < 5.0)
85
90
  nokogiri (~> 1.6.0)
86
91
  rails-deprecated_sanitizer (>= 1.0.1)
87
- rails-html-sanitizer (1.0.2)
92
+ rails-html-sanitizer (1.0.3)
88
93
  loofah (~> 2.0)
89
94
  railties (4.2.4)
90
95
  actionpack (= 4.2.4)
91
96
  activesupport (= 4.2.4)
92
97
  rake (>= 0.8.7)
93
98
  thor (>= 0.18.1, < 2.0)
94
- rake (10.4.2)
95
- sprockets (3.4.0)
99
+ rake (11.2.2)
100
+ sprockets (3.6.3)
101
+ concurrent-ruby (~> 1.0)
96
102
  rack (> 1, < 3)
97
- sprockets-rails (2.3.3)
98
- actionpack (>= 3.0)
99
- activesupport (>= 3.0)
100
- sprockets (>= 2.8, < 4.0)
103
+ sprockets-rails (3.1.1)
104
+ actionpack (>= 4.0)
105
+ activesupport (>= 4.0)
106
+ sprockets (>= 3.0.0)
101
107
  sqlite3 (1.3.11)
102
- test-unit (3.1.5)
108
+ test-unit (3.2.0)
103
109
  power_assert
104
110
  thor (0.19.1)
105
111
  thread_safe (0.3.5)
@@ -118,4 +124,4 @@ DEPENDENCIES
118
124
  test-unit
119
125
 
120
126
  BUNDLED WITH
121
- 1.10.6
127
+ 1.12.4
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ has_translations (1.1.0)
5
+ activerecord (>= 3.2.0)
6
+ activesupport (>= 3.2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.0.0)
12
+ actionpack (= 5.0.0)
13
+ nio4r (~> 1.2)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.0.0)
16
+ actionpack (= 5.0.0)
17
+ actionview (= 5.0.0)
18
+ activejob (= 5.0.0)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.0.0)
22
+ actionview (= 5.0.0)
23
+ activesupport (= 5.0.0)
24
+ rack (~> 2.0)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.0.0)
29
+ activesupport (= 5.0.0)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ activejob (5.0.0)
35
+ activesupport (= 5.0.0)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.0.0)
38
+ activesupport (= 5.0.0)
39
+ activerecord (5.0.0)
40
+ activemodel (= 5.0.0)
41
+ activesupport (= 5.0.0)
42
+ arel (~> 7.0)
43
+ activesupport (5.0.0)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ appraisal (2.1.0)
49
+ bundler
50
+ rake
51
+ thor (>= 0.14.0)
52
+ arel (7.0.0)
53
+ builder (3.2.2)
54
+ concurrent-ruby (1.0.2)
55
+ erubis (2.7.0)
56
+ globalid (0.3.6)
57
+ activesupport (>= 4.1.0)
58
+ i18n (0.7.0)
59
+ loofah (2.0.3)
60
+ nokogiri (>= 1.5.9)
61
+ mail (2.6.4)
62
+ mime-types (>= 1.16, < 4)
63
+ method_source (0.8.2)
64
+ mime-types (3.1)
65
+ mime-types-data (~> 3.2015)
66
+ mime-types-data (3.2016.0521)
67
+ mini_portile2 (2.1.0)
68
+ minitest (5.9.0)
69
+ nio4r (1.2.1)
70
+ nokogiri (1.6.8)
71
+ mini_portile2 (~> 2.1.0)
72
+ pkg-config (~> 1.1.7)
73
+ pkg-config (1.1.7)
74
+ power_assert (0.3.0)
75
+ rack (2.0.1)
76
+ rack-test (0.6.3)
77
+ rack (>= 1.0)
78
+ rails (5.0.0)
79
+ actioncable (= 5.0.0)
80
+ actionmailer (= 5.0.0)
81
+ actionpack (= 5.0.0)
82
+ actionview (= 5.0.0)
83
+ activejob (= 5.0.0)
84
+ activemodel (= 5.0.0)
85
+ activerecord (= 5.0.0)
86
+ activesupport (= 5.0.0)
87
+ bundler (>= 1.3.0, < 2.0)
88
+ railties (= 5.0.0)
89
+ sprockets-rails (>= 2.0.0)
90
+ rails-dom-testing (2.0.1)
91
+ activesupport (>= 4.2.0, < 6.0)
92
+ nokogiri (~> 1.6.0)
93
+ rails-html-sanitizer (1.0.3)
94
+ loofah (~> 2.0)
95
+ railties (5.0.0)
96
+ actionpack (= 5.0.0)
97
+ activesupport (= 5.0.0)
98
+ method_source
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
101
+ rake (11.2.2)
102
+ sprockets (3.6.3)
103
+ concurrent-ruby (~> 1.0)
104
+ rack (> 1, < 3)
105
+ sprockets-rails (3.1.1)
106
+ actionpack (>= 4.0)
107
+ activesupport (>= 4.0)
108
+ sprockets (>= 3.0.0)
109
+ sqlite3 (1.3.11)
110
+ test-unit (3.2.0)
111
+ power_assert
112
+ thor (0.19.1)
113
+ thread_safe (0.3.5)
114
+ tzinfo (1.2.2)
115
+ thread_safe (~> 0.1)
116
+ websocket-driver (0.6.4)
117
+ websocket-extensions (>= 0.1.0)
118
+ websocket-extensions (0.1.2)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ appraisal
125
+ has_translations!
126
+ rails (= 5.0.0)
127
+ rake
128
+ sqlite3
129
+ test-unit
130
+
131
+ BUNDLED WITH
132
+ 1.12.4
@@ -29,7 +29,8 @@ module HasTranslations
29
29
  :nil,
30
30
  :inverse_of,
31
31
  :autosave,
32
- :translation_class
32
+ :translation_class,
33
+ :foreign_key
33
34
  ]
34
35
  )
35
36
 
@@ -39,18 +40,19 @@ module HasTranslations
39
40
  self.has_translations_options = options
40
41
 
41
42
  # associations, validations and scope definitions
42
- options[:translation_class].belongs_to(belongs_to)
43
+ options[:translation_class].belongs_to(belongs_to, foreign_key: options[:foreign_key])
43
44
  has_many(
44
45
  :translations,
45
46
  class_name: translation_class_name,
46
47
  dependent: :destroy,
47
48
  autosave: options[:autosave],
48
- inverse_of: options[:inverse_of]
49
+ inverse_of: options[:inverse_of],
50
+ foreign_key: options[:foreign_key]
49
51
  )
50
52
  options[:translation_class].validates(
51
53
  :locale,
52
54
  presence: true,
53
- uniqueness: {scope: :"#{belongs_to}_id"}
55
+ uniqueness: {scope: (options[:foreign_key] || "#{belongs_to}_id").to_sym}
54
56
  )
55
57
 
56
58
  # Optionals delegated readers
@@ -1,3 +1,3 @@
1
1
  module HasTranslations
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -5,8 +5,8 @@ require 'test_helper'
5
5
  class HasTranslationsTest < Test::Unit::TestCase
6
6
  def setup
7
7
  setup_db
8
-
9
- [Article, ArticleTranslation, Team, TeamTranslation].each do |k|
8
+
9
+ [Article, ArticleTranslation, Team, TeamTranslation, Organization, Organization, OrganizationTranslation].each do |k|
10
10
  k.delete_all
11
11
  end
12
12
  I18n.locale = :ru
@@ -17,7 +17,7 @@ class HasTranslationsTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_schema_has_loaded_correctly
20
- [Article, ArticleTranslation, Team, TeamTranslation].each do |k|
20
+ [Article, ArticleTranslation, Team, TeamTranslation, Organization, OrganizationTranslation].each do |k|
21
21
  assert_equal [], k.all
22
22
  end
23
23
  assert_equal :ru, I18n.locale
@@ -144,4 +144,14 @@ class HasTranslationsTest < Test::Unit::TestCase
144
144
  team.translations.create!(:locale => 'ru', :text => 'текст')
145
145
  assert_equal 1, Team.translated(:ru).count
146
146
  end
147
+
148
+ def test_foreign_key_for_has_many_associations
149
+ organization = Organization.create!
150
+ organization.translations.create!(:locale => 'en', :text => 'text')
151
+ assert organization.has_translation?(:en)
152
+ organization.translations.create!(:locale => 'ru', :text => 'текст')
153
+ assert_equal 2, organization.reload.translations.count
154
+ assert_equal 1, Organization.translated(:en).count
155
+ assert_equal 1, Organization.translated(:ru).count
156
+ end
147
157
  end
data/test/schema.rb CHANGED
@@ -19,6 +19,16 @@ ActiveRecord::Schema.define(:version => 0) do
19
19
  t.string :locale, :null => false, :limit => 2
20
20
  t.text :text
21
21
  end
22
+
23
+ create_table :organizations, :force => true do |t|
24
+ t.string :title
25
+ end
26
+
27
+ create_table :organization_translations, :force => true do |t|
28
+ t.integer :company_id, :null => false
29
+ t.string :locale, :null => false, :limit => 2
30
+ t.text :text
31
+ end
22
32
  end
23
33
 
24
34
  class ArticleTranslation < ActiveRecord::Base
@@ -37,3 +47,11 @@ class Team < ActiveRecord::Base
37
47
 
38
48
  has_translations :text, :fallback => true, :nil => nil
39
49
  end
50
+
51
+ class OrganizationTranslation < ActiveRecord::Base
52
+ end
53
+ class Organization < ActiveRecord::Base
54
+ include HasTranslations::ModelAdditions
55
+
56
+ has_translations :text, :writer => true, :foreign_key => 'company_id'
57
+ end
data/test/test_helper.rb CHANGED
@@ -24,7 +24,7 @@ def setup_db
24
24
  end
25
25
 
26
26
  def teardown_db
27
- ActiveRecord::Base.connection.tables.each do |table|
27
+ ActiveRecord::Base.connection.public_send(ActiveRecord::VERSION::MAJOR >= 5 ? :data_sources : :tables).each do |table|
28
28
  ActiveRecord::Base.connection.drop_table(table)
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Polushkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -118,6 +118,8 @@ files:
118
118
  - gemfiles/4.1.gemfile.lock
119
119
  - gemfiles/4.2.gemfile
120
120
  - gemfiles/4.2.gemfile.lock
121
+ - gemfiles/5.0.gemfile
122
+ - gemfiles/5.0.gemfile.lock
121
123
  - has_translations.gemspec
122
124
  - lib/generators/templates/migration.rb.erb
123
125
  - lib/generators/templates/model.rb.erb