mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Rename ModelSupport to Decoratable
This commit is contained in:
parent
61e6027236
commit
d06afda764
8 changed files with 12 additions and 12 deletions
|
@ -5,7 +5,7 @@ require 'draper/system'
|
||||||
require 'draper/active_model_support'
|
require 'draper/active_model_support'
|
||||||
require 'draper/decorator'
|
require 'draper/decorator'
|
||||||
require 'draper/lazy_helpers'
|
require 'draper/lazy_helpers'
|
||||||
require 'draper/model_support'
|
require 'draper/decoratable'
|
||||||
require 'draper/helper_support'
|
require 'draper/helper_support'
|
||||||
require 'draper/view_context'
|
require 'draper/view_context'
|
||||||
require 'draper/collection_decorator'
|
require 'draper/collection_decorator'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module Draper::ModelSupport
|
module Draper::Decoratable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def decorator(options = {})
|
def decorator(options = {})
|
|
@ -49,7 +49,7 @@ module Draper
|
||||||
def self.decorates(input, options = {})
|
def self.decorates(input, options = {})
|
||||||
self.model_class = options[:class] || options[:class_name] || input.to_s.camelize
|
self.model_class = options[:class] || options[:class_name] || input.to_s.camelize
|
||||||
self.model_class = model_class.constantize if model_class.respond_to?(:constantize)
|
self.model_class = model_class.constantize if model_class.respond_to?(:constantize)
|
||||||
model_class.send :include, Draper::ModelSupport
|
model_class.send :include, Draper::Decoratable
|
||||||
define_method(input){ @model }
|
define_method(input){ @model }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Draper
|
||||||
|
|
||||||
initializer "draper.extend_active_record_base" do |app|
|
initializer "draper.extend_active_record_base" do |app|
|
||||||
ActiveSupport.on_load(:active_record) do
|
ActiveSupport.on_load(:active_record) do
|
||||||
self.send(:include, Draper::ModelSupport)
|
self.send(:include, Draper::Decoratable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,7 @@ describe Draper::Decorator do
|
||||||
|
|
||||||
context 'the decorated model' do
|
context 'the decorated model' do
|
||||||
it 'receives the mixin' do
|
it 'receives the mixin' do
|
||||||
source.class.ancestors.include?(Draper::ModelSupport)
|
source.class.ancestors.include?(Draper::Decoratable)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes ActiveModel support' do
|
it 'includes ActiveModel support' do
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Draper::ModelSupport do
|
describe Draper::Decoratable do
|
||||||
subject { Product.new }
|
subject { Product.new }
|
||||||
|
|
||||||
describe '#decorator' do
|
describe '#decorator' do
|
||||||
|
@ -17,8 +17,8 @@ describe Draper::ModelSupport do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Draper::ModelSupport::ClassMethods do
|
describe Draper::Decoratable::ClassMethods do
|
||||||
shared_examples_for "a call to Draper::ModelSupport::ClassMethods#decorate" do
|
shared_examples_for "a call to Draper::Decoratable::ClassMethods#decorate" do
|
||||||
subject { klass.limit }
|
subject { klass.limit }
|
||||||
|
|
||||||
its(:decorate) { should be_kind_of(Draper::CollectionDecorator) }
|
its(:decorate) { should be_kind_of(Draper::CollectionDecorator) }
|
||||||
|
@ -36,13 +36,13 @@ describe Draper::ModelSupport do
|
||||||
describe '#decorate - decorate collections of AR objects' do
|
describe '#decorate - decorate collections of AR objects' do
|
||||||
let(:klass) { Product }
|
let(:klass) { Product }
|
||||||
|
|
||||||
it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
|
it_should_behave_like "a call to Draper::Decoratable::ClassMethods#decorate"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#decorate - decorate collections of namespaced AR objects' do
|
describe '#decorate - decorate collections of namespaced AR objects' do
|
||||||
let(:klass) { Namespace::Product }
|
let(:klass) { Namespace::Product }
|
||||||
|
|
||||||
it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
|
it_should_behave_like "a call to Draper::Decoratable::ClassMethods#decorate"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require './spec/support/samples/product'
|
||||||
|
|
||||||
module Namespace
|
module Namespace
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
include Draper::ModelSupport
|
include Draper::Decoratable
|
||||||
|
|
||||||
def self.first
|
def self.first
|
||||||
@@first ||= Namespace::Product.new
|
@@first ||= Namespace::Product.new
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
include Draper::ModelSupport
|
include Draper::Decoratable
|
||||||
|
|
||||||
def self.find_by_name(name)
|
def self.find_by_name(name)
|
||||||
@@dummy ||= Product.new
|
@@dummy ||= Product.new
|
||||||
|
|
Loading…
Reference in a new issue