traco 3.1.0 → 3.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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a8bd7fc75a987a4f1f791ac9d4e1eec0aed2a63e
4
- data.tar.gz: 4089adbb897a21f2eefd3c3ea2cc88ea746705e2
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTBlNWVjMTY0MjQ4YzU3NGIwNjM0ZTlmYjI0Yzc4NjUyNzY1MGQ5OQ==
5
+ data.tar.gz: !binary |-
6
+ NDI5OGU2OGY5MzEwZjEyNWU4MWFlNzYzMjkxMmI1ZWZiZjY5YzYwMw==
5
7
  SHA512:
6
- metadata.gz: 87640e9a6cf728ff073ed250497821582555b47a89c1274c14cdefcde446e39676fbd9091de27ac1f7f4ac373255393787600a1872469d27a858e57a86f44c6e
7
- data.tar.gz: 1b64b064d9918cfb1909447dfb2a2f840de1f0f0f5142a4e5583b44b83c652f601557aab24712bff45d9d873a7702820fce21604f5a87e71ecf03fb6b0e64941
8
+ metadata.gz: !binary |-
9
+ Y2M4NGIyNDhlNmI0OTE5YTI1ZTI1ODQyOWE1YmMyZDM4YjM2ZmZlOTk1MjI0
10
+ NGQ4OWVhYjk1OTY4Y2UyODJhNGQ1MWIxMzAzNjRhZjU3YjRhMDdlYmMzMzk2
11
+ ZTBkMTQzNmFiN2QyZDAzMWFlODk4OWQ2ODYzNGYzYjQ5ZGY4MDQ=
12
+ data.tar.gz: !binary |-
13
+ ZDYzMDJkZTJhNjVjZTQ3YTZkNjExMTM3YmZlMTI5YmE0ZGVjYmM5OWUyMjc3
14
+ Y2ZmMzMxNzMxNTY0MmUzN2NhNGIwYmYwMzVjNjAzYjQxNmQxMGFmY2NhOTAw
15
+ ZTM5NzcyODM1Yzc3MDBkN2Q5MTE5OTE1YjVlNmE3NmY0MzIxM2E=
data/README.md CHANGED
@@ -6,7 +6,7 @@ Translatable attributes for Rails 3 and 4 (Ruby 1.9+), stored in the model table
6
6
 
7
7
  Inspired by Iain Hecker's [translatable_columns](https://github.com/iain/translatable_columns/).
8
8
 
9
- To store translations outside the model, see Sven Fuchs' [globalize3](https://github.com/svenfuchs/globalize3).
9
+ To store translations outside the model, see Sven Fuchs' [Globalize](https://github.com/globalize/globalize).
10
10
 
11
11
 
12
12
  ## Usage
@@ -155,7 +155,7 @@ Possible improvements to make:
155
155
 
156
156
  By [Barsoom](http://barsoom.se) under the MIT license:
157
157
 
158
- > Copyright (c) 2012 Barsoom AB
158
+ > Copyright © 2012–2014 Barsoom AB
159
159
  >
160
160
  > Permission is hereby granted, free of charge, to any person obtaining a copy
161
161
  > of this software and associated documentation files (the "Software"), to deal
@@ -54,9 +54,7 @@ module Traco
54
54
  custom_define_method(attribute) do |method_opts = {}|
55
55
  fallback = method_opts.fetch(:fallback, default_fallback)
56
56
 
57
- @localized_readers ||= {}
58
- @localized_readers[attribute] ||= Traco::LocalizedReader.new(self, attribute, fallback: fallback)
59
- @localized_readers[attribute].value
57
+ Traco::LocalizedReader.new(self, attribute, fallback: fallback).value
60
58
  end
61
59
  end
62
60
 
data/lib/traco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
data/spec/traco_spec.rb CHANGED
@@ -5,28 +5,28 @@ require "traco"
5
5
 
6
6
  describe ActiveRecord::Base, ".translates" do
7
7
  it "is available" do
8
- Post.should respond_to :translates
8
+ expect(Post).to respond_to :translates
9
9
  end
10
10
 
11
11
  it "adds functionality" do
12
- Post.new.should_not respond_to :title
12
+ expect(Post.new).not_to respond_to :title
13
13
  Post.translates :title
14
- Post.new.should respond_to :title
14
+ expect(Post.new).to respond_to :title
15
15
  end
16
16
 
17
17
  it "can be run more than once" do
18
- Post.new.should_not respond_to :title, :body
18
+ expect(Post.new).not_to respond_to :title, :body
19
19
  Post.translates :title
20
20
  Post.translates :body
21
- Post.new.should respond_to :title, :body
21
+ expect(Post.new).to respond_to :title, :body
22
22
  end
23
23
 
24
24
  it "inherits columns from the superclass" do
25
25
  Post.translates :title
26
26
  SubPost.translates :body
27
- SubPost.new.should respond_to :title, :body
28
- Post.new.should respond_to :title
29
- Post.new.should_not respond_to :body
27
+ expect(SubPost.new).to respond_to :title, :body
28
+ expect(Post.new).to respond_to :title
29
+ expect(Post.new).not_to respond_to :body
30
30
  end
31
31
  end
32
32
 
@@ -36,7 +36,7 @@ describe Post, ".translatable_attributes" do
36
36
  end
37
37
 
38
38
  it "lists the translatable attributes" do
39
- Post.translatable_attributes.should == [ :title ]
39
+ expect(Post.translatable_attributes).to match_array [ :title ]
40
40
  end
41
41
  end
42
42
 
@@ -47,7 +47,7 @@ describe Post, ".locales_for_attribute" do
47
47
 
48
48
  it "lists the locales, default first and then alphabetically" do
49
49
  I18n.default_locale = :"pt-BR"
50
- Post.locales_for_attribute(:title).should == [
50
+ expect(Post.locales_for_attribute(:title)).to match_array [
51
51
  :pt_br, :en, :sv
52
52
  ]
53
53
  end
@@ -60,14 +60,14 @@ describe Post, ".locale_columns" do
60
60
  end
61
61
 
62
62
  it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
63
- Post.locale_columns(:title).should == [
63
+ expect(Post.locale_columns(:title)).to match_array [
64
64
  :title_pt_br, :title_en, :title_sv
65
65
  ]
66
66
  end
67
67
 
68
68
  it "supports multiple attributes" do
69
69
  Post.translates :body
70
- Post.locale_columns(:body, :title).should == [
70
+ expect(Post.locale_columns(:body, :title)).to match_array [
71
71
  :body_pt_br, :body_en, :body_sv,
72
72
  :title_pt_br, :title_en, :title_sv
73
73
  ]
@@ -81,7 +81,7 @@ describe Post, ".current_locale_column" do
81
81
 
82
82
  it "returns the column name for the current locale" do
83
83
  I18n.locale = :sv
84
- Post.current_locale_column(:title).should == :title_sv
84
+ expect(Post.current_locale_column(:title)).to eq :title_sv
85
85
  end
86
86
  end
87
87
 
@@ -97,42 +97,50 @@ describe Post, "#title" do
97
97
  end
98
98
 
99
99
  it "gives the title in the current locale" do
100
- post.title.should == "Hej"
100
+ expect(post.title).to eq "Hej"
101
101
  end
102
102
 
103
103
  it "handles dashed locales" do
104
104
  I18n.locale = :"pt-BR"
105
- post.title_pt_br.should == "Olá"
106
- post.title.should == "Olá"
105
+ expect(post.title_pt_br).to eq "Olá"
106
+ expect(post.title).to eq "Olá"
107
107
  end
108
108
 
109
109
  it "falls back to the default locale if locale has no column" do
110
110
  I18n.locale = :ru
111
- post.title.should == "Halloa"
111
+ expect(post.title).to eq "Halloa"
112
112
  end
113
113
 
114
114
  it "falls back to the default locale if blank" do
115
115
  post.title_sv = " "
116
- post.title.should == "Halloa"
116
+ expect(post.title).to eq "Halloa"
117
117
  end
118
118
 
119
119
  it "does not fall back to any other locale if default locale is blank" do
120
120
  post.title_sv = " "
121
121
  post.title_en = ""
122
- post.title.should be_nil
122
+ expect(post.title).to be_nil
123
123
  end
124
124
 
125
125
  it "does not fall back if called with fallback: false" do
126
126
  I18n.locale = :sv
127
127
  post.title_sv = ""
128
- post.title(fallback: false).should be_nil
128
+ expect(post.title(fallback: false)).to be_nil
129
+ end
130
+
131
+ # Had a bug: https://github.com/barsoom/traco/issues/25
132
+ it "does not incorrectly memoize fallback state" do
133
+ I18n.locale = :sv
134
+ post.title_sv = ""
135
+ expect(post.title(fallback: :any)).not_to be_nil
136
+ expect(post.title(fallback: false)).to be_nil
129
137
  end
130
138
 
131
139
  it "returns nil if all are blank" do
132
140
  post.title_sv = " "
133
141
  post.title_en = ""
134
142
  post.title_pt_br = nil
135
- post.title.should be_nil
143
+ expect(post.title).to be_nil
136
144
  end
137
145
 
138
146
  it "is overridable" do
@@ -142,7 +150,7 @@ describe Post, "#title" do
142
150
  end
143
151
  end
144
152
 
145
- post.title.should == "jeH"
153
+ expect(post.title).to eq "jeH"
146
154
  end
147
155
 
148
156
  # Had a regression.
@@ -150,16 +158,16 @@ describe Post, "#title" do
150
158
  Post.translates :title, :body
151
159
  post.title_sv = "title"
152
160
  post.body_sv = "body"
153
- post.title.should == "title"
154
- post.body.should == "body"
161
+ expect(post.title).to eq "title"
162
+ expect(post.body).to eq "body"
155
163
  end
156
164
 
157
165
  it "reflects locale change" do
158
- post.title.should == "Hej"
166
+ expect(post.title).to eq "Hej"
159
167
  I18n.locale = :en
160
- post.title.should == "Halloa"
168
+ expect(post.title).to eq "Halloa"
161
169
  I18n.locale = :sv
162
- post.title.should == "Hej"
170
+ expect(post.title).to eq "Hej"
163
171
  end
164
172
 
165
173
  context "when the translation was defined with fallback: false" do
@@ -174,18 +182,18 @@ describe Post, "#title" do
174
182
 
175
183
  it "does not fall back to the default locale if locale has no column" do
176
184
  I18n.locale = :ru
177
- post.title.should be_nil
185
+ expect(post.title).to be_nil
178
186
  end
179
187
 
180
188
  it "does not fall back to the default locale if blank" do
181
189
  I18n.locale = :sv
182
190
  post.title_sv = " "
183
- post.title.should be_nil
191
+ expect(post.title).to be_nil
184
192
  end
185
193
 
186
194
  it "still falls back if called with fallback: :default" do
187
195
  I18n.locale = :ru
188
- post.title(fallback: :default).should == "Halloa"
196
+ expect(post.title(fallback: :default)).to eq "Halloa"
189
197
  end
190
198
  end
191
199
 
@@ -198,12 +206,12 @@ describe Post, "#title" do
198
206
 
199
207
  it "falls back to any locale, not just the default" do
200
208
  post = Post.new(title_en: "", title_pt_br: "", title_sv: "Hej")
201
- post.title.should == "Hej"
209
+ expect(post.title).to eq "Hej"
202
210
  end
203
211
 
204
212
  it "prefers the default locale" do
205
213
  post = Post.new(title_en: "Hello", title_pt_br: "", title_sv: "Hej")
206
- post.title.should == "Hello"
214
+ expect(post.title).to eq "Hello"
207
215
  end
208
216
  end
209
217
  end
@@ -218,20 +226,20 @@ describe Post, "#title=" do
218
226
  it "assigns in the current locale" do
219
227
  I18n.locale = :sv
220
228
  post.title = "Hej"
221
- post.title_sv.should == "Hej"
229
+ expect(post.title_sv).to eq "Hej"
222
230
  end
223
231
 
224
232
  it "handles dashed locales" do
225
233
  I18n.locale = :"pt-BR"
226
234
  post.title = "Olá"
227
- post.title_pt_br.should == "Olá"
235
+ expect(post.title_pt_br).to eq "Olá"
228
236
  end
229
237
 
230
238
  it "raises if locale has no column" do
231
239
  I18n.locale = :ru
232
- lambda {
240
+ expect {
233
241
  post.title = "Privet"
234
- }.should raise_error(NoMethodError, /title_ru/)
242
+ }.to raise_error(NoMethodError, /title_ru/)
235
243
  end
236
244
  end
237
245
 
@@ -242,32 +250,32 @@ describe Post, ".human_attribute_name" do
242
250
  end
243
251
 
244
252
  it "uses explicit translations if present" do
245
- Post.human_attribute_name(:title_sv).should == "Svensk titel"
253
+ expect(Post.human_attribute_name(:title_sv)).to eq "Svensk titel"
246
254
  end
247
255
 
248
256
  it "appends translated language name if present" do
249
- Post.human_attribute_name(:title_en).should == "Titel (engelska)"
257
+ expect(Post.human_attribute_name(:title_en)).to eq "Titel (engelska)"
250
258
  end
251
259
 
252
260
  it "appends an abbreviation when language name is not translated" do
253
- Post.human_attribute_name(:title_pt_br).should == "Titel (PT-BR)"
261
+ expect(Post.human_attribute_name(:title_pt_br)).to eq "Titel (PT-BR)"
254
262
  end
255
263
 
256
264
  it "passes through the default behavior for untranslated attributes" do
257
- Post.human_attribute_name(:title).should == "Titel"
265
+ expect(Post.human_attribute_name(:title)).to eq "Titel"
258
266
  end
259
267
 
260
268
  it "passes through untranslated attributes even if the name suggests it's translated" do
261
- Post.human_attribute_name(:body_sv).should == "Body sv"
269
+ expect(Post.human_attribute_name(:body_sv)).to eq "Body sv"
262
270
  end
263
271
 
264
272
  # ActiveModel::Errors#full_messages passes in an ugly default.
265
273
 
266
274
  it "does not honor passed-in defaults for locale columns" do
267
- Post.human_attribute_name(:title_en, default: "Title en").should == "Titel (engelska)"
275
+ expect(Post.human_attribute_name(:title_en, default: "Title en")).to eq "Titel (engelska)"
268
276
  end
269
277
 
270
278
  it "passes through defaults" do
271
- Post.human_attribute_name(:body_sv, default: "Boday").should == "Boday"
279
+ expect(Post.human_attribute_name(:body_sv, default: "Boday")).to eq "Boday"
272
280
  end
273
281
  end
data/traco.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Translatable columns for Rails 3 or better, stored in the model table itself."
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.test_files = `git ls-files -- spec/*`.split("\n")
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
17
 
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description:
@@ -73,9 +73,9 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
77
- - ".rvmrc"
78
- - ".travis.yml"
76
+ - .gitignore
77
+ - .rvmrc
78
+ - .travis.yml
79
79
  - CHANGELOG.md
80
80
  - Gemfile
81
81
  - README.md
@@ -100,17 +100,17 @@ require_paths:
100
100
  - lib
101
101
  required_ruby_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - ! '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.2.0
113
+ rubygems_version: 2.2.1
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Translatable columns for Rails 3 or better, stored in the model table itself.