Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/active_hash/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Base
class_attribute :_data, :dirty, :default_attributes, :scopes

if Object.const_defined?(:ActiveModel)
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Conversion
else
Expand Down
11 changes: 11 additions & 0 deletions spec/active_hash/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,17 @@ class Book < ActiveRecord::Base

end

describe "#model_name" do
# This test reproduces the issue reported in https://github.com/active-hash/active_hash/pull/335,
# regarding whether ActiveHash (and its derived models) expose `#model_name`.
# Some serializers (e.g., okuramasafumi/alba) use the `#model_name` method internally,
# so this test ensures that a NoMethodError is not raised.
it "exposes model_name correctly" do
instance = Country.new(:id => 1)
expect { instance.model_name }.not_to raise_error
end
end

describe ".transaction" do

it "execute the block given to it" do
Expand Down