traco 3.1.6 → 5.1.0

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,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzZlZTA3YTcxYTNiNDA3ZmQ3MTdhMzE5ZGQxNzA1Yzg4YmFhMjI5Mg==
5
- data.tar.gz: !binary |-
6
- OTQ3MzczNzVmZDI4ZWMwYjBhOGY0NjMyZmU4MWE1N2UyN2RhMTZkMA==
2
+ SHA256:
3
+ metadata.gz: '0558c0d88be16881d21c8d132f91237f872f8d6ed718ac9c5f96542fa2a2da29'
4
+ data.tar.gz: ef022bdbd5381ed2a5df36e125fd1dbc98423bdb0788a682105b997d9ecca720
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjkwNjFmOWJiNmM2ZDg1MzI3ZGNlNDBkMzU3ZTIwYWRiN2NkNjJmMzFjMjQ3
10
- ZGNlOGIyNzA1MzM5OGQ4YzBlN2M2ZmFlZjE5ZTg5ZjgyNzY5YmMxZDQ4MDcz
11
- MTBiYTAyOGMyYjNmOWVkNzU0Yzk0MDU4NGE2NDY3ZjZhYmQxMjQ=
12
- data.tar.gz: !binary |-
13
- MjdkMWE2YzM0NzcxYjZkYjkzNzZiYWVmZTMyMGUxMjVmNzMxYjAyZjVmYzBi
14
- YmRhMDY3YWM5OTI3MzdmNDBhNTVjZjVkMDBmZTQ4ZjE5OWVhMjQ0ZjhkYTk3
15
- OWE1MjBlZWM4ZWYxNzMyYWJjNzE5Njk4OWMxNDRkYTU2Nzg3YTA=
6
+ metadata.gz: 7eb1119b6ed4de3f33df0c85b6c82faaedcc48f5982066e037bd2bd0ecd9c666eb4ce52f19845f01ca522b4e5f5ff5bad60ad93f09ac536de56976d67a70e300
7
+ data.tar.gz: 64e59646deb593318e26e0363c5b90f76e0f62a85c7702d987a0f8e599abd095ea4cb0fe966b7c2b67ce3102d40390c76c76bf71fc88060a3f4585ecc505fc13
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ Gemfile.lock
3
3
  pkg/
4
4
  tmp
5
5
  *.gem
6
+ # Appraisal generated lockfiles
7
+ *.gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -r spec_helper
@@ -1,5 +1,24 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.1.0
4
- - 2.0.0
5
- - 1.9.3
4
+ - 2.6.3
5
+ - 2.5.5
6
+ - 2.4.6
7
+ - 2.3.8
8
+ gemfile:
9
+ - gemfiles/rails_4.2.gemfile
10
+ - gemfiles/rails_5.0.gemfile
11
+ - gemfiles/rails_5.1.gemfile
12
+ - gemfiles/rails_5.2.gemfile
13
+ - gemfiles/rails_6.0.gemfile
14
+ - gemfiles/rails_6.1.gemfile
15
+ matrix:
16
+ exclude:
17
+ - rvm: 2.3.8
18
+ gemfile: gemfiles/rails_6.0.gemfile
19
+ - rvm: 2.3.8
20
+ gemfile: gemfiles/rails_6.1.gemfile
21
+ - rvm: 2.4.6
22
+ gemfile: gemfiles/rails_6.0.gemfile
23
+ - rvm: 2.4.6
24
+ gemfile: gemfiles/rails_6.1.gemfile
@@ -0,0 +1,26 @@
1
+ appraise "rails-4.2" do
2
+ gem "activerecord", "~> 4.2.0"
3
+ gem "sqlite3", "~> 1.3.13"
4
+ end
5
+
6
+ appraise "rails-5.0" do
7
+ gem "activerecord", "~> 5.0.0"
8
+ gem "sqlite3", "~> 1.3.13"
9
+ end
10
+
11
+ appraise "rails-5.1" do
12
+ gem "activerecord", "~> 5.1.0"
13
+ gem "sqlite3", "~> 1.3.13"
14
+ end
15
+
16
+ appraise "rails-5.2" do
17
+ gem "activerecord", "~> 5.2.0"
18
+ end
19
+
20
+ appraise "rails-6.0" do
21
+ gem "activerecord", "~> 6.0.3.1"
22
+ end
23
+
24
+ appraise "rails-6.1" do
25
+ gem "activerecord", "~> 6.1.0"
26
+ end
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.1.0
4
+
5
+ * Feature: Add `fallback: :i18n` to use the fallbacks from `I18n.fallbacks`. Thanks to [sunny](https://github.com/sunny)!
6
+
7
+ ## 5.0.0
8
+
9
+ * Change `locale_columns` and `locales_for_attribute` to sort current locale first, then default locale (previously, it was default locale first). This makes more sense for our own apps, and hopefully other apps as well.
10
+
11
+ ## 4.0.0
12
+
13
+ * Drop support for end-of-lifed Ruby 2.1 and 2.2.
14
+
15
+ ## 3.3.0
16
+
17
+ * Traco now automatically adds query methods, e.g. `Item#title?` when `title` is translated.
18
+
19
+ ## 3.2.2
20
+
21
+ * Internal cleanup.
22
+
23
+ ## 3.2.1
24
+
25
+ * Bugfix: with `fallback: [:sv]`, always look at current locale before any fallbacks.
26
+
27
+ ## 3.2.0
28
+
29
+ * Introduce e.g. `fallback: [:sv]` to explicitly specify fallbacks.
30
+
3
31
  ## 3.1.6
4
32
 
5
33
  Make [license (MIT)](LICENSE.txt) easier to autodetect.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Traco
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/barsoom/traco.png)](http://travis-ci.org/barsoom/traco)
3
+ [![Build Status](https://secure.travis-ci.org/barsoom/traco.svg)](http://travis-ci.org/barsoom/traco)
4
4
 
5
- Translatable attributes for Rails 3 and 4 (Ruby 1.9+), stored in the model table itself.
5
+ Translatable attributes for Ruby on Rails 4.2+, stored in the model table itself.
6
6
 
7
7
  Inspired by Iain Hecker's [translatable_columns](https://github.com/iain/translatable_columns/).
8
8
 
@@ -46,11 +46,13 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
46
46
 
47
47
  `#title=`: Assigns the title to the column for the current locale, if present. Raises if the column doesn't exist.
48
48
 
49
+ `#title?`: Is the title present? Respects the Traco [fallback](#fallbacks) setting.
50
+
49
51
  `.human_attribute_name(:title_sv)`: Extends this standard method to return "Title (Swedish)" if you have a translation key `i18n.languages.sv = "Swedish"` and "Title (SV)" otherwise. Rails uses this method to build validation error messages and form labels.
50
52
 
51
53
  `.translatable_attributes`: Returns an array like `[:title, :body]`.
52
54
 
53
- `.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with default locale first and then alphabetically. Suitable for looping in forms:
55
+ `.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with current locale first, then default locale, and then alphabetically. Suitable for looping in forms:
54
56
 
55
57
  ```erb
56
58
  <% Post.locale_columns(:title).each do |column| %>
@@ -79,7 +81,7 @@ The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]
79
81
 
80
82
  `.current_locale_column(:title)`: Returns `:title_sv` if `:sv` is the current locale. Suitable for some SQL queries, such as sorting.
81
83
 
82
- `.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with default locale first and then alphabetically.
84
+ `.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with current locale first, then default locale, and then alphabetically.
83
85
 
84
86
  And the equivalent methods for `body`, of course.
85
87
 
@@ -94,6 +96,10 @@ You can specify e.g. `translates :title, fallback: false` to never fall back and
94
96
 
95
97
  You can specify e.g. `translates :title, fallback: :any` to fall back first to the default locale, then to any other locale.
96
98
 
99
+ You can specify e.g. `translates :title, fallback: [:sv]` to explicitly declare fallbacks as an array of any length.
100
+
101
+ You can specify e.g. `translates :title, fallback: :i18n` to use the fallbacks from `I18n.fallbacks`.
102
+
97
103
  You can override the default fallback strategy with a parameter passed to the reader: `post.title(fallback: :any)`.
98
104
 
99
105
  If you need to declare the default locale fallback, do `post.title(fallback: :default)`.
@@ -118,7 +124,7 @@ end
118
124
  Add this to your `Gemfile`:
119
125
 
120
126
  ```ruby
121
- gem 'traco'
127
+ gem "traco"
122
128
  ```
123
129
 
124
130
  Then run
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "sqlite3", "~> 1.3.13"
7
+
8
+ group :benchmark do
9
+ gem "benchmark-ips"
10
+ end
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3.13"
7
+
8
+ group :benchmark do
9
+ gem "benchmark-ips"
10
+ end
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1.0"
6
+ gem "sqlite3", "~> 1.3.13"
7
+
8
+ group :benchmark do
9
+ gem "benchmark-ips"
10
+ end
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.0"
6
+
7
+ group :benchmark do
8
+ gem "benchmark-ips"
9
+ end
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.3.1"
6
+
7
+ group :benchmark do
8
+ gem "benchmark-ips"
9
+ end
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+
7
+ group :benchmark do
8
+ gem "benchmark-ips"
9
+ end
10
+
11
+ gemspec path: "../"
@@ -7,6 +7,7 @@ module Traco
7
7
  attributes.each do |attribute|
8
8
  define_reader(attribute)
9
9
  define_writer(attribute)
10
+ define_query(attribute)
10
11
  end
11
12
  end
12
13
 
@@ -25,7 +26,7 @@ module Traco
25
26
  default_fallback = #{@options.fetch(:fallback, LocaleFallbacks::DEFAULT_FALLBACK).inspect}
26
27
  fallback = options.fetch(:fallback, default_fallback)
27
28
 
28
- columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback)
29
+ columns_to_try = self.class._locale_columns_for_attribute(:#{attribute}, fallback: fallback)
29
30
  columns_to_try.each do |column|
30
31
  value = send(column)
31
32
  return value if value.present?
@@ -45,6 +46,14 @@ module Traco
45
46
  EOM
46
47
  end
47
48
 
49
+ def define_query(attribute)
50
+ class_eval <<-EOM, __FILE__, __LINE__ + 1
51
+ def #{attribute}?
52
+ #{attribute}.present?
53
+ end
54
+ EOM
55
+ end
56
+
48
57
  # Only called once per class or inheritance chain (e.g. once
49
58
  # for the superclass, not at all for subclasses). The separation
50
59
  # is important if we don't want to overwrite values if running
@@ -1,18 +1,18 @@
1
1
  module Traco
2
2
  module ClassMethods
3
3
  def locales_for_attribute(attribute)
4
- traco_cache(attribute, LocaleFallbacks::DEFAULT_FIRST_FALLBACK).keys
4
+ traco_cache(attribute, fallback: LocaleFallbacks::ANY_FALLBACK).keys
5
5
  end
6
6
 
7
7
  def locale_columns(*attributes)
8
- attributes.each_with_object([]) do |attribute, columns|
9
- columns.concat(_locale_columns_for_attribute(attribute, LocaleFallbacks::DEFAULT_FIRST_FALLBACK))
10
- end
8
+ attributes.flat_map { |attribute|
9
+ _locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::ANY_FALLBACK)
10
+ }
11
11
  end
12
12
 
13
13
  # Consider this method internal.
14
- def _locale_columns_for_attribute(attribute, fallback)
15
- traco_cache(attribute, fallback).values
14
+ def _locale_columns_for_attribute(attribute, fallback:)
15
+ traco_cache(attribute, fallback: fallback).values
16
16
  end
17
17
 
18
18
  def current_locale_column(attribute)
@@ -52,7 +52,7 @@ module Traco
52
52
  # }
53
53
  # }
54
54
  # }
55
- def traco_cache(attribute, fallback)
55
+ def traco_cache(attribute, fallback:)
56
56
  cache = @traco_cache ||= {}
57
57
  per_locale_cache = cache[I18n.locale] ||= {}
58
58
  per_attribute_cache = per_locale_cache[attribute] ||= {}
@@ -7,13 +7,16 @@ module Traco
7
7
  ANY_FALLBACK = :any,
8
8
  NO_FALLBACK = false,
9
9
  DEFAULT_FIRST_FALLBACK = :default_first,
10
+ I18N_FALLBACK = :i18n,
10
11
  ]
11
12
 
12
13
  attr_reader :fallback_option
13
14
  private :fallback_option
14
15
 
15
16
  def initialize(fallback_option)
16
- @fallback_option = validate_option(fallback_option)
17
+ validate_option(fallback_option)
18
+
19
+ @fallback_option = fallback_option
17
20
  @default_locale = I18n.default_locale
18
21
  @available_locales = I18n.available_locales.sort
19
22
  end
@@ -24,6 +27,8 @@ module Traco
24
27
  when ANY_FALLBACK then [ current_locale, @default_locale, *@available_locales ].uniq
25
28
  when NO_FALLBACK then [ current_locale ]
26
29
  when DEFAULT_FIRST_FALLBACK then [ @default_locale, *@available_locales ].uniq
30
+ when I18N_FALLBACK then I18n.fallbacks[current_locale]
31
+ when Array then [ current_locale, *fallback_option ]
27
32
  else raise "Unknown fallback." # Should never get here.
28
33
  end
29
34
  end
@@ -31,12 +36,11 @@ module Traco
31
36
  private
32
37
 
33
38
  def validate_option(fallback_option)
34
- if OPTIONS.include?(fallback_option)
35
- fallback_option
36
- else
37
- valids = OPTIONS.map(&:inspect).join(", ")
38
- raise ArgumentError.new("Unsupported fallback: #{fallback_option.inspect} (expected one of #{valids})")
39
- end
39
+ return if OPTIONS.include?(fallback_option)
40
+ return if fallback_option.is_a?(Array)
41
+
42
+ valids = OPTIONS.map(&:inspect).join(", ")
43
+ raise ArgumentError.new("Unsupported fallback: #{fallback_option.inspect} (expected one of #{valids}, or an array)")
40
44
  end
41
45
  end
42
46
  end
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "3.1.6"
2
+ VERSION = "5.1.0"
3
3
  end
@@ -1,7 +1,6 @@
1
- require "spec_helper"
2
1
  require "traco/locale_fallbacks"
3
2
 
4
- describe Traco::LocaleFallbacks do
3
+ RSpec.describe Traco::LocaleFallbacks do
5
4
  describe ".new" do
6
5
  it "raises ArgumentError if an unknown argument passed in" do
7
6
  expect { Traco::LocaleFallbacks.new(:foo) }.to raise_error(ArgumentError)
@@ -35,6 +34,13 @@ describe Traco::LocaleFallbacks do
35
34
  end
36
35
  end
37
36
 
37
+ context "with an explicit list of locales" do
38
+ it "returns only those locales, after the current one" do
39
+ subject = Traco::LocaleFallbacks.new([ :en ])
40
+ expect(subject[:sv]).to eq [ :sv, :en ]
41
+ end
42
+ end
43
+
38
44
  context "with the ':default_first' option" do
39
45
  it "returns default locale, then remaining available locales alphabetically" do
40
46
  I18n.default_locale = :uk
@@ -44,5 +50,20 @@ describe Traco::LocaleFallbacks do
44
50
  expect(subject[:sv]).to eq [ :uk, :de, :en, :sv ]
45
51
  end
46
52
  end
53
+
54
+ context "with the ':i18n' option" do
55
+ it "returns what is configured as a I18n fallback" do
56
+ I18n.fallbacks = I18n::Locale::Fallbacks.new(
57
+ en: [ :en, :uk, :de, :sv ],
58
+ uk: [ :uk, :en, :de, :sv ],
59
+ de: [ :de, :uk, :en, :sv ],
60
+ sv: [ :sv, :en, :uk, :de ],
61
+ )
62
+
63
+ subject = Traco::LocaleFallbacks.new(:i18n)
64
+ expect(subject[:sv]).to eq [ :sv, :en, :uk, :de ]
65
+ expect(subject[:de]).to eq [ :de, :uk, :en, :sv ]
66
+ end
67
+ end
47
68
  end
48
69
  end
@@ -1,9 +1,11 @@
1
1
  require "i18n"
2
2
 
3
3
  RSpec.configure do |config|
4
- config.treat_symbols_as_metadata_keys_with_true_values = true
5
4
  config.filter_run focus: true
6
5
  config.run_all_when_everything_filtered = true
6
+ config.disable_monkey_patching!
7
7
  end
8
8
 
9
9
  I18n.enforce_available_locales = false
10
+
11
+ I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
@@ -1,5 +1,5 @@
1
1
  RSpec.configure do |config|
2
- config.before(:each) do
2
+ config.before do
3
3
  # Clear class state before each spec.
4
4
  Object.send(:remove_const, "Post")
5
5
  Object.send(:remove_const, "SubPost")
@@ -19,12 +19,10 @@ require "app/post.rb"
19
19
 
20
20
  ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
21
21
 
22
- silence_stream(STDOUT) do
23
- ActiveRecord::Schema.define(version: 0) do
24
- create_table :posts, force: true do |t|
25
- t.string :title_sv, :title_en, :title_pt_br
26
- t.string :body_sv, :body_en, :body_pt_br
27
- end
22
+ ActiveRecord::Schema.define(version: 0) do
23
+ create_table :posts, force: true do |t|
24
+ t.string :title_sv, :title_en, :title_pt_br, :title_de
25
+ t.string :body_sv, :body_en, :body_pt_br, :body_de
28
26
  end
29
27
  end
30
28
 
@@ -1,10 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "spec_helper"
4
3
  require "spec_helper_models"
5
4
  require "traco"
6
5
 
7
- describe Traco, ".split_localized_column" do
6
+ RSpec.describe Traco, ".split_localized_column" do
8
7
  subject { described_class }
9
8
 
10
9
  it "returns attribute and locale" do
@@ -24,7 +23,7 @@ describe Traco, ".split_localized_column" do
24
23
  end
25
24
  end
26
25
 
27
- describe ActiveRecord::Base, ".translates" do
26
+ RSpec.describe ActiveRecord::Base, ".translates" do
28
27
  it "is available" do
29
28
  expect(Post).to respond_to :translates
30
29
  end
@@ -57,7 +56,7 @@ describe ActiveRecord::Base, ".translates" do
57
56
  end
58
57
  end
59
58
 
60
- describe Post, ".translatable_attributes" do
59
+ RSpec.describe Post, ".translatable_attributes" do
61
60
  before do
62
61
  Post.translates :title
63
62
  end
@@ -77,15 +76,15 @@ describe Post, ".translatable_attributes" do
77
76
  end
78
77
  end
79
78
 
80
- describe Post, ".locales_for_attribute" do
79
+ RSpec.describe Post, ".locales_for_attribute" do
81
80
  before do
82
81
  Post.translates :title
83
82
  I18n.default_locale = :"pt-BR"
84
83
  I18n.locale = :en
85
84
  end
86
85
 
87
- it "lists the locales for that attribute, default locale first and then alphabetically" do
88
- expect(Post.locales_for_attribute(:title)).to eq [ :"pt-BR", :en, :sv ]
86
+ it "lists the locales for that attribute, current locale first, then default locale, and then alphabetically" do
87
+ expect(Post.locales_for_attribute(:title)).to eq [ :en, :"pt-BR", :de, :sv ]
89
88
  end
90
89
 
91
90
  it "doesn't include a locale if there's no corresponding column for it" do
@@ -95,16 +94,16 @@ describe Post, ".locales_for_attribute" do
95
94
  end
96
95
  end
97
96
 
98
- describe Post, ".locale_columns" do
97
+ RSpec.describe Post, ".locale_columns" do
99
98
  before do
100
99
  Post.translates :title
101
100
  I18n.default_locale = :"pt-BR"
102
101
  I18n.locale = :en
103
102
  end
104
103
 
105
- it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
104
+ it "lists the columns-with-locale for that attribute, current locale first, then default locale, and then alphabetically" do
106
105
  expect(Post.locale_columns(:title)).to eq [
107
- :title_pt_br, :title_en, :title_sv
106
+ :title_en, :title_pt_br, :title_de, :title_sv,
108
107
  ]
109
108
  end
110
109
 
@@ -114,17 +113,17 @@ describe Post, ".locale_columns" do
114
113
  expect(Post.locale_columns(:title)).not_to include(:title_ru)
115
114
  end
116
115
 
117
- it "supports multiple attributes" do
118
- Post.translates :body
116
+ it "supports multiple attributes" do
117
+ Post.translates :body
119
118
 
120
119
  expect(Post.locale_columns(:body, :title)).to eq [
121
- :body_pt_br, :body_en, :body_sv,
122
- :title_pt_br, :title_en, :title_sv,
120
+ :body_en, :body_pt_br, :body_de, :body_sv,
121
+ :title_en, :title_pt_br, :title_de, :title_sv,
123
122
  ]
124
123
  end
125
124
  end
126
125
 
127
- describe Post, ".current_locale_column" do
126
+ RSpec.describe Post, ".current_locale_column" do
128
127
  before do
129
128
  Post.translates :title
130
129
  end
@@ -140,7 +139,7 @@ describe Post, ".current_locale_column" do
140
139
  end
141
140
  end
142
141
 
143
- describe Post, "#title" do
142
+ RSpec.describe Post, "#title" do
144
143
  let(:post) {
145
144
  Post.new(title_sv: "Hej", title_en: "Halloa", title_pt_br: "Olá")
146
145
  }
@@ -271,7 +270,7 @@ describe Post, "#title" do
271
270
  end
272
271
  end
273
272
 
274
- describe Post, "#title=" do
273
+ RSpec.describe Post, "#title=" do
275
274
  before do
276
275
  Post.translates :title
277
276
  end
@@ -298,7 +297,24 @@ describe Post, "#title=" do
298
297
  end
299
298
  end
300
299
 
301
- describe Post, ".human_attribute_name" do
300
+ RSpec.describe Post, "#title?" do
301
+ before do
302
+ Post.translates :title
303
+ I18n.locale = :sv
304
+ I18n.default_locale = :en
305
+ end
306
+
307
+ it "is true if the title is present" do
308
+ post = Post.new(title_sv: "", title_en: " ", title_pt_br: nil)
309
+ expect(post.title?).to be false
310
+
311
+ post.title_en = "Hello"
312
+
313
+ expect(post.title?).to be true
314
+ end
315
+ end
316
+
317
+ RSpec.describe Post, ".human_attribute_name" do
302
318
  before do
303
319
  Post.translates :title
304
320
  I18n.locale = :sv
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Henrik Nyh"]
9
9
  s.email = ["henrik@barsoom.se"]
10
10
  s.homepage = ""
11
- s.summary = "Translatable columns for Rails 3 or better, stored in the model table itself."
11
+ s.summary = "Translatable columns for Rails 4.2 or better, stored in the model table itself."
12
12
  s.license = "MIT"
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
@@ -16,10 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency "activerecord", ">= 3.0"
19
+ s.required_ruby_version = ">= 2.3.0"
20
+
21
+ s.add_dependency "activerecord", ">= 4.2"
20
22
 
21
23
  s.add_development_dependency "sqlite3"
22
24
 
23
25
  s.add_development_dependency "rake"
24
26
  s.add_development_dependency "rspec"
27
+ s.add_development_dependency "appraisal"
25
28
  end
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2020-12-14 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
- version: '3.0'
19
+ version: '4.2'
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
- version: '3.0'
26
+ version: '4.2'
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
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description:
@@ -73,15 +87,22 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - .gitignore
77
- - .rvmrc
78
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Appraisals
79
94
  - CHANGELOG.md
80
95
  - Gemfile
81
96
  - LICENSE.txt
82
97
  - README.md
83
98
  - Rakefile
84
99
  - benchmarks/overhead.rb
100
+ - gemfiles/rails_4.2.gemfile
101
+ - gemfiles/rails_5.0.gemfile
102
+ - gemfiles/rails_5.1.gemfile
103
+ - gemfiles/rails_5.2.gemfile
104
+ - gemfiles/rails_6.0.gemfile
105
+ - gemfiles/rails_6.1.gemfile
85
106
  - lib/traco.rb
86
107
  - lib/traco/attributes.rb
87
108
  - lib/traco/class_methods.rb
@@ -105,20 +126,19 @@ require_paths:
105
126
  - lib
106
127
  required_ruby_version: !ruby/object:Gem::Requirement
107
128
  requirements:
108
- - - ! '>='
129
+ - - ">="
109
130
  - !ruby/object:Gem::Version
110
- version: '0'
131
+ version: 2.3.0
111
132
  required_rubygems_version: !ruby/object:Gem::Requirement
112
133
  requirements:
113
- - - ! '>='
134
+ - - ">="
114
135
  - !ruby/object:Gem::Version
115
136
  version: '0'
116
137
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.2.2
138
+ rubygems_version: 3.1.4
119
139
  signing_key:
120
140
  specification_version: 4
121
- summary: Translatable columns for Rails 3 or better, stored in the model table itself.
141
+ summary: Translatable columns for Rails 4.2 or better, stored in the model table itself.
122
142
  test_files:
123
143
  - spec/app/post.rb
124
144
  - spec/app/sv.yml
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm ruby-1.9.3-p194-falcon@traco --create