diff --git a/lib/mobility/plugins/attribute_methods.rb b/lib/mobility/plugins/attribute_methods.rb index 2fceb168..4775a012 100644 --- a/lib/mobility/plugins/attribute_methods.rb +++ b/lib/mobility/plugins/attribute_methods.rb @@ -25,6 +25,14 @@ module AttributeMethods attributes.merge(name.to_s => send(name)) end) end + + private + + define_method :attribute_names_for_serialization do + return unless defined?(super) + + super() + names.map(&:to_s) + end end # Applies attribute_methods plugin for a given option value. diff --git a/spec/mobility/plugins/attribute_methods_spec.rb b/spec/mobility/plugins/attribute_methods_spec.rb index 9b55fb7d..1e121f05 100644 --- a/spec/mobility/plugins/attribute_methods_spec.rb +++ b/spec/mobility/plugins/attribute_methods_spec.rb @@ -38,6 +38,13 @@ end end + describe "#as_json" do + it "adds translated attributes to normal attributes" do + expect(backend).to receive(:read).with(Mobility.locale, any_args).and_return('foo').at_least(1) + expect(instance.as_json).to eq(untranslated_attributes.merge('title' => 'foo')) + end + end + describe "#untranslated_attributes" do it "returns original value of attributes method" do expect(instance.untranslated_attributes).to eq(untranslated_attributes)