aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/test/activerecord/render_partial_with_record_identification_test.rb3
-rw-r--r--actionpack/test/controller/record_identifier_test.rb3
-rw-r--r--actionpack/test/controller/redirect_test.rb3
-rw-r--r--actionpack/test/lib/controller/fake_models.rb6
-rw-r--r--actionpack/test/template/active_record_helper_test.rb9
-rw-r--r--actionpack/test/template/atom_feed_helper_test.rb3
-rw-r--r--actionpack/test/template/form_helper_test.rb15
-rw-r--r--actionpack/test/template/prototype_helper_test.rb12
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb3
-rw-r--r--actionpack/test/template/test_test.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb6
-rw-r--r--activemodel/lib/active_model.rb2
-rw-r--r--activemodel/lib/active_model/api_compliant.rb25
-rw-r--r--activemodel/lib/active_model/conversion.rb8
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
15 files changed, 53 insertions, 55 deletions
diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
index 0122bc7d8f..df50c3dc6f 100644
--- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
+++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -126,7 +126,8 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
end
class Game < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
end
diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb
index 10f51639cf..44e49ed3f8 100644
--- a/actionpack/test/controller/record_identifier_test.rb
+++ b/actionpack/test/controller/record_identifier_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Comment
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
def save; @id = 1 end
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index a71c39e504..b3321303c0 100644
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -4,7 +4,8 @@ class WorkshopsController < ActionController::Base
end
class Workshop
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :new_record
def initialize(id, new_record)
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 07f01e1c47..c6726432ec 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -1,7 +1,8 @@
require "active_model"
class Customer < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
@@ -16,7 +17,8 @@ end
module Quiz
class Question < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index c1bbdae8fb..b07ce6cf5d 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -5,15 +5,18 @@ class ActiveRecordHelperTest < ActionView::TestCase
silence_warnings do
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
class User < Struct.new(:email)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
class Column < Struct.new(:type, :name, :human_name)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
end
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb
index 89ff01ab0e..3acaecd142 100644
--- a/actionpack/test/template/atom_feed_helper_test.rb
+++ b/actionpack/test/template/atom_feed_helper_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Scroll < Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def new_record?
true
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 883afd985b..99160dd8b1 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -2,7 +2,8 @@ require 'abstract_unit'
silence_warnings do
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
alias_method :secret?, :secret
@@ -25,7 +26,8 @@ silence_warnings do
end
class Comment
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
@@ -43,7 +45,8 @@ silence_warnings do
end
class Tag
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
@@ -61,7 +64,8 @@ silence_warnings do
end
class CommentRelevance
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :comment_id
@@ -75,7 +79,8 @@ silence_warnings do
end
class TagRelevance
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :tag_id
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 301a110076..acbf311212 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -1,11 +1,14 @@
require 'abstract_unit'
require 'active_model'
-Bunny = Struct.new(:Bunny, :id)
-Bunny.extend ActiveModel::APICompliant
+class Bunny < Struct.new(:Bunny, :id)
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+end
class Author
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
def save; @id = 1 end
@@ -16,7 +19,8 @@ class Author
end
class Article
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :author_id
def save; @id = 1; @author_id = 1 end
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index bae26f555d..4144fea678 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Post
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def id
45
end
diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb
index 98307fbae4..f32d0b3d42 100644
--- a/actionpack/test/template/test_test.rb
+++ b/actionpack/test/template/test_test.rb
@@ -41,7 +41,7 @@ class PeopleHelperTest < ActionView::TestCase
def test_link_to_person
person = mock(:name => "David")
- person.class.extend ActiveModel::APICompliant
+ person.class.extend ActiveModel::Naming
expects(:mocha_mock_path).with(person).returns("/people/1")
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 4569689534..9eeb26831c 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -494,7 +494,8 @@ class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase
end
class Workshop
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :new_record
def initialize(id, new_record)
@@ -511,7 +512,8 @@ class Workshop
end
class Session
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :workshop_id, :new_record
def initialize(id, new_record)
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb
index 0665cfbae5..2de19597b1 100644
--- a/activemodel/lib/active_model.rb
+++ b/activemodel/lib/active_model.rb
@@ -26,7 +26,7 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path)
require 'active_support'
module ActiveModel
- autoload :APICompliant, 'active_model/api_compliant'
+ autoload :Conversion, 'active_model/conversion'
autoload :DeprecatedErrorMethods, 'active_model/deprecated_error_methods'
autoload :Errors, 'active_model/errors'
autoload :Name, 'active_model/naming'
diff --git a/activemodel/lib/active_model/api_compliant.rb b/activemodel/lib/active_model/api_compliant.rb
deleted file mode 100644
index 26f83feb6b..0000000000
--- a/activemodel/lib/active_model/api_compliant.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module ActiveModel
- module APICompliant
- include Naming
-
- def self.extended(klass)
- klass.class_eval do
- include Validations
- include InstanceMethods
- end
- end
-
- module InstanceMethods
- def to_model
- if respond_to?(:new_record?)
- self.class.class_eval { def to_model() self end }
- to_model
- else
- raise "In order to be ActiveModel API compliant, you need to define " \
- "a new_record? method, which should return true if it has not " \
- "yet been persisted."
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb
new file mode 100644
index 0000000000..d5c65920f6
--- /dev/null
+++ b/activemodel/lib/active_model/conversion.rb
@@ -0,0 +1,8 @@
+module ActiveModel
+ # Include ActiveModel::Conversion if your object "acts like an ActiveModel model".
+ module Conversion
+ def to_model
+ self
+ end
+ end
+end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f32857afa3..62e97158ec 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2511,13 +2511,6 @@ module ActiveRecord #:nodoc:
(id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes
end
- # Returns the ActiveRecord object when asked for its
- # ActiveModel-compliant representation, because ActiveRecord is
- # ActiveModel-compliant.
- def to_model
- self
- end
-
# Returns a cache key that can be used to identify this record.
#
# ==== Examples
@@ -3186,6 +3179,7 @@ module ActiveRecord #:nodoc:
include Dirty
include Callbacks, ActiveModel::Observing, Timestamp
include Associations, AssociationPreload, NamedScope
+ include ActiveModel::Conversion
# AutosaveAssociation needs to be included before Transactions, because we want
# #save_with_autosave_associations to be wrapped inside a transaction.