mobility-actiontext 0.5.0 → 0.6.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ca31827abf078eae807f5aafef4588dad78859d1fe3fea3c753dc311726c533
4
- data.tar.gz: 723483c8e2091d470dbb0ae86f33bc945a7e4eeac87770ecf22c1f2e447f0f0a
3
+ metadata.gz: 62723fa69cae996e74c0b33dfe0d5babf7395d6384c3c548fc7e06c33fcec9ce
4
+ data.tar.gz: 28ec6773c56d337a844d6b27bd13aebaea539bc0a1fafad50a9cfe0257243c82
5
5
  SHA512:
6
- metadata.gz: 8d58add532f751dade73185768f816a2b1ad16b1ac794b74b78997ed62c20d05b0e4a816515bf71c949fe3782bb78ffa8e9a6f4ac1fea3f47659263d8f894685
7
- data.tar.gz: 9cf9d1bf167b0da2feb2513588818789bf998a16291d919f58fc39794172e05fda3853cf35085ffb811fef918d2ccf8d7aed4dc12f1fa3a230a3f3b095c7bf36
6
+ metadata.gz: f2b425c119565f978ed06b45e54bb9c452d648a4ff39026b35dbd50cce2d567f555685de9d56d68b0c02d2559a5f4dbee453e76edf61846321b40972387bf704
7
+ data.tar.gz: 6eced781dcc3440abcb988f898979caca2511eda42486d11a141fa457f26802532d609bbeaa32a8127f036eb563850a3a6035c0a84ec05d6bad1a906c43f4aae
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.1.0
1
+ ruby-3.1.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Mobility Action Text Changelog
2
2
 
3
+ ### 0.6.0 (2022-02-27)
4
+ - Include all translations on eager load using `with_all_rich_text` ([#23](https://github.com/sedubois/mobility-actiontext/pull/23)).
5
+
3
6
  ### 0.5.0 (2022-02-13)
4
7
  - Require only actiontext in gemspec dependencies ([#20](https://github.com/sedubois/mobility-actiontext/pull/20)).
5
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility-actiontext (0.5.0)
4
+ mobility-actiontext (0.6.0)
5
5
  actiontext (>= 6.0)
6
6
  mobility (~> 1.2)
7
7
 
@@ -54,7 +54,7 @@ GEM
54
54
  erubi (1.10.0)
55
55
  globalid (1.0.0)
56
56
  activesupport (>= 5.0)
57
- i18n (1.9.1)
57
+ i18n (1.10.0)
58
58
  concurrent-ruby (~> 1.0)
59
59
  loofah (2.14.0)
60
60
  crass (~> 1.0.2)
@@ -65,9 +65,9 @@ GEM
65
65
  mobility (1.2.5)
66
66
  i18n (>= 0.6.10, < 2)
67
67
  request_store (~> 1.0)
68
- nokogiri (1.13.1-x86_64-darwin)
68
+ nokogiri (1.13.3-x86_64-darwin)
69
69
  racc (~> 1.4)
70
- nokogiri (1.13.1-x86_64-linux)
70
+ nokogiri (1.13.3-x86_64-linux)
71
71
  racc (~> 1.4)
72
72
  racc (1.6.0)
73
73
  rack (2.2.3)
data/README.md CHANGED
@@ -79,7 +79,7 @@ This is done through the `Mobility::Backends::ActionText::Translation` model ext
79
79
 
80
80
  After checking out the repo, run `bundle install` to install dependencies. Then, run `cd test_app && bundle exec rails test` to run the tests.
81
81
 
82
- To release a new version, update `lib/mobility/action_text/version.rb` and `CHANGELOG.md`, run `bundle`, commit, then run `bundle exec rake release`. This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+ To release a new version, update `lib/mobility/action_text/version.rb` and `CHANGELOG.md`, run `bundle && cd test_app && bundle`, commit, then run `bundle exec rake release`. This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
83
 
84
84
  ## Contributing
85
85
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mobility
4
4
  module ActionText
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -70,7 +70,9 @@ module Mobility
70
70
  end
71
71
  end
72
72
 
73
- setup do |attributes, _options|
73
+ setup do |attributes, options|
74
+ next if options[:plain]
75
+
74
76
  attributes.each do |name|
75
77
  has_one :"rich_text_#{name}", -> { where(name: name, locale: Mobility.locale) },
76
78
  class_name: 'Mobility::Backends::ActionText::RichTextTranslation',
@@ -78,7 +80,15 @@ module Mobility
78
80
  scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }
79
81
  scope :"with_rich_text_#{name}_and_embeds",
80
82
  -> { includes("rich_text_#{name}": { embeds_attachments: :blob }) }
81
- end unless _options[:plain]
83
+ end
84
+
85
+ singleton_class.prepend(WithAllRichText) unless singleton_class < WithAllRichText
86
+ end
87
+
88
+ module WithAllRichText
89
+ def with_all_rich_text
90
+ super.eager_load(:rich_text_translations)
91
+ end
82
92
  end
83
93
 
84
94
  module ActionTextValidations
data/test_app/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- ruby '3.1.0'
4
+ ruby '3.1.1'
5
5
 
6
6
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7
7
  gem 'rails', '~> 7.0.0'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- mobility-actiontext (0.5.0)
4
+ mobility-actiontext (0.6.0)
5
5
  actiontext (>= 6.0)
6
6
  mobility (~> 1.2)
7
7
 
@@ -83,7 +83,7 @@ GEM
83
83
  ffi (1.15.5)
84
84
  globalid (1.0.0)
85
85
  activesupport (>= 5.0)
86
- i18n (1.9.1)
86
+ i18n (1.10.0)
87
87
  concurrent-ruby (~> 1.0)
88
88
  io-wait (0.2.1)
89
89
  jbuilder (2.11.5)
@@ -120,15 +120,15 @@ GEM
120
120
  net-protocol
121
121
  timeout
122
122
  nio4r (2.5.8)
123
- nokogiri (1.13.1-x86_64-darwin)
123
+ nokogiri (1.13.3-x86_64-darwin)
124
124
  racc (~> 1.4)
125
- nokogiri (1.13.1-x86_64-linux)
125
+ nokogiri (1.13.3-x86_64-linux)
126
126
  racc (~> 1.4)
127
127
  puma (5.6.2)
128
128
  nio4r (~> 2.0)
129
129
  racc (1.6.0)
130
130
  rack (2.2.3)
131
- rack-mini-profiler (2.3.3)
131
+ rack-mini-profiler (2.3.4)
132
132
  rack (>= 1.2.0)
133
133
  rack-test (1.1.0)
134
134
  rack (>= 1.0, < 3)
@@ -221,7 +221,7 @@ DEPENDENCIES
221
221
  web-console (>= 4.1.0)
222
222
 
223
223
  RUBY VERSION
224
- ruby 3.1.0p0
224
+ ruby 3.1.1p18
225
225
 
226
226
  BUNDLED WITH
227
227
  2.3.7
@@ -4,4 +4,6 @@ class Post < ApplicationRecord
4
4
  extend Mobility
5
5
  translates :title, plain: true
6
6
  translates :content
7
+
8
+ has_rich_text :non_i18n_content
7
9
  end
@@ -3,7 +3,7 @@
3
3
  class TranslateRichTexts < ActiveRecord::Migration[6.1]
4
4
  def change
5
5
  # or null: true to allow untranslated rich text
6
- add_column :action_text_rich_texts, :locale, :string, null: false
6
+ add_column :action_text_rich_texts, :locale, :string, null: true
7
7
 
8
8
  remove_index :action_text_rich_texts,
9
9
  column: %i[record_type record_id name],
@@ -20,7 +20,7 @@ ActiveRecord::Schema.define(version: 20_210_114_125_134) do
20
20
  t.integer 'record_id', null: false
21
21
  t.datetime 'created_at', precision: 6, null: false
22
22
  t.datetime 'updated_at', precision: 6, null: false
23
- t.string 'locale', null: false
23
+ t.string 'locale'
24
24
  t.index %w[record_type record_id name locale], name: 'index_action_text_rich_texts_uniqueness',
25
25
  unique: true
26
26
  end
@@ -22,6 +22,11 @@ post_one_content_fr:
22
22
  locale: fr
23
23
  body: <h1>Bonjour le monde !</h1>
24
24
 
25
+ post_one_non_i18n_content:
26
+ record: one (Post)
27
+ name: non_i18n_content
28
+ body: <h1>Hello non i18n world!</h1>
29
+
25
30
  untranslated_title_en:
26
31
  record: untranslated (Post)
27
32
  name: title
@@ -95,7 +95,7 @@ module Mobility
95
95
  end
96
96
  end
97
97
 
98
- test 'post content is eager loaded' do
98
+ test 'post content is eager loaded explicitly' do
99
99
  post = assert_queries(2) { Post.with_rich_text_content.last }
100
100
 
101
101
  assert_no_queries do
@@ -105,8 +105,24 @@ module Mobility
105
105
  end
106
106
  end
107
107
 
108
+ test 'post content is eager loaded with all rich text' do
109
+ post = assert_queries(2) { Post.with_all_rich_text.last }
110
+
111
+ assert_no_queries do
112
+ assert_equal 'Hello world!', post.content.to_plain_text
113
+ end
114
+ end
115
+
116
+ test 'post non_i18n_content is eager loaded with all rich text' do
117
+ post = assert_queries(2) { Post.with_all_rich_text.last }
118
+
119
+ assert_no_queries do
120
+ assert_equal 'Hello non i18n world!', post.non_i18n_content.to_plain_text
121
+ end
122
+ end
123
+
108
124
  test 'post is being destroyed' do
109
- assert_difference ->{Mobility::Backends::ActionText::RichTextTranslation.count}, -4 do
125
+ assert_difference ->{Mobility::Backends::ActionText::RichTextTranslation.count}, -5 do
110
126
  assert posts(:one).destroy
111
127
  end
112
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobility-actiontext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Dubois
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-13 00:00:00.000000000 Z
11
+ date: 2022-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actiontext
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.3.3
157
+ rubygems_version: 3.3.7
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Translate Rails Action Text rich text with Mobility.