Skip to content

Commit

Permalink
Release 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Dec 17, 2020
1 parent 1c2f09e commit b0b2817
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Installation
Add this line to your application's Gemfile:

```ruby
gem 'friendly_id-mobility', '~> 0.5.4'
gem 'friendly_id-mobility', '~> 1.0.0'
```

And then execute:
Expand Down
2 changes: 1 addition & 1 deletion friendly_id-mobility.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.files = Dir['{lib/**/*,[A-Z]*}']
spec.require_paths = ["lib"]

spec.add_dependency 'mobility', '>= 0.5.1', '< 1.0'
spec.add_dependency 'mobility', '>= 1.0.0', '< 2.0'
spec.add_dependency 'friendly_id', '>= 5.0.0', '<= 5.4.0'
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
5 changes: 3 additions & 2 deletions lib/friendly_id/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ def included(model_class)

mod = Module.new do
def friendly
super.send(::Mobility.query_method)
# TODO: Make this constant public in Mobility 1.1 so we don't need const_get
super.extending(::Mobility::Plugins::ActiveRecord::Query.const_get(:QueryExtension))
end
end
model_class.send :extend, mod
end

def advise_against_untranslated_model(model)
field = model.friendly_id_config.query_field
if !model.respond_to?(:translated_attribute_names) || model.translated_attribute_names.exclude?(field)
if model.included_modules.grep(::Mobility::Translations).empty? || model.mobility_attributes.exclude?(field)
raise "[FriendlyId] You need to translate the '#{field}' field with " \
"Mobility (add 'translates :#{field}' in your model '#{model.name}')"
end
Expand Down
21 changes: 20 additions & 1 deletion spec/friendly_id/mobility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@
end

context "base column is translated" do
before do
klass = Class.new(ActiveRecord::Base)

# Add dirty plugin for this class, needed for these tests
translations_class = Class.new(Mobility.translations_class)
translations_class.plugins do
dirty
end

klass.class_eval do
self.table_name = :articles
include translations_class.new(:slug, :title, type: :string, fallbacks: { en: [:es] })

extend FriendlyId
friendly_id :title, use: :mobility
end
stub_const('Article', klass)
end

describe "#friendly_id" do
it "sets friendly_id from base column in each locale" do
article = Article.create!(:title => "War and Peace")
Expand Down Expand Up @@ -263,7 +282,7 @@
it "detects scope column from explicit column name" do
model_class = Class.new(ActiveRecord::Base) do
extend Mobility
translates :slug, :empty, type: :string, dirty: true, backend: :key_value
translates :slug, :empty, type: :string

self.abstract_class = true
extend FriendlyId
Expand Down
33 changes: 19 additions & 14 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,47 @@ def self.up
end
end

class Journalist < ActiveRecord::Base
extend Mobility
translates :slug, type: :string, fallthrough_accessors: true, backend: :key_value

extend FriendlyId
friendly_id :name, use: :mobility
# Base plugins
Mobility.configure do
plugins do
backend :key_value
active_record
reader
writer
query
fallbacks
fallthrough_accessors
end
end

class Article < ActiveRecord::Base
class Journalist < ActiveRecord::Base
extend Mobility
translates :slug, :title, type: :string, dirty: true, backend: :key_value, fallbacks: { en: [:es] }
translates :slug, type: :string

extend FriendlyId
friendly_id :title, use: :mobility
friendly_id :name, use: :mobility
end

class Post < ActiveRecord::Base
extend Mobility
translates :slug, :title, type: :string, dirty: true, backend: :key_value
translates :content, type: :text, dirty: true, backend: :key_value
translates :slug, :title, type: :string
translates :content, type: :text

extend FriendlyId
friendly_id :title, use: [:history, :mobility]
end

class Novelist < ActiveRecord::Base
extend Mobility
translates :slug, :name, type: :string, dirty: true, backend: :key_value
translates :slug, :name, type: :string

extend FriendlyId
friendly_id :name, use: [:mobility, :slugged]
end

class Novel < ActiveRecord::Base
extend Mobility
translates :slug, :name, type: :string, dirty: true, backend: :key_value
translates :slug, :name, type: :string

extend FriendlyId
belongs_to :novelist
Expand All @@ -117,7 +122,7 @@ def should_generate_new_friendly_id?

class Publisher < ActiveRecord::Base
extend Mobility
translates :name, type: :string, dirty: true, backend: :key_value
translates :name, type: :string

has_many :novels
end
Expand Down

0 comments on commit b0b2817

Please sign in to comment.