draper 0.17.0 → 1.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.markdown +49 -0
- data/Gemfile +4 -0
- data/Rakefile +50 -31
- data/Readme.markdown +63 -92
- data/draper.gemspec +6 -4
- data/lib/draper/collection_decorator.rb +88 -0
- data/lib/draper/decoratable.rb +44 -0
- data/lib/draper/decorated_association.rb +55 -0
- data/lib/draper/decorator.rb +260 -0
- data/lib/draper/finders.rb +34 -0
- data/lib/draper/helper_proxy.rb +16 -0
- data/lib/draper/railtie.rb +17 -21
- data/lib/draper/security.rb +48 -0
- data/lib/draper/tasks/tu.rake +5 -0
- data/lib/draper/test/minitest_integration.rb +5 -24
- data/lib/draper/test/rspec_integration.rb +0 -6
- data/lib/draper/test/test_unit_integration.rb +9 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +24 -6
- data/lib/draper/view_helpers.rb +36 -0
- data/lib/draper.rb +48 -7
- data/lib/generators/decorator/decorator_generator.rb +1 -1
- data/lib/generators/decorator/templates/decorator.rb +0 -1
- data/lib/generators/rspec/decorator_generator.rb +1 -1
- data/lib/generators/test_unit/decorator_generator.rb +1 -1
- data/lib/generators/test_unit/templates/decorator_test.rb +0 -3
- data/spec/draper/collection_decorator_spec.rb +240 -0
- data/spec/draper/decoratable_spec.rb +164 -0
- data/spec/draper/decorated_association_spec.rb +130 -0
- data/spec/draper/decorator_spec.rb +622 -0
- data/spec/draper/finders_spec.rb +145 -0
- data/spec/draper/helper_proxy_spec.rb +12 -0
- data/spec/draper/security_spec.rb +158 -0
- data/spec/draper/view_helpers_spec.rb +41 -0
- data/spec/dummy/.rspec +2 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/localized_urls.rb +5 -0
- data/spec/dummy/app/controllers/posts_controller.rb +17 -0
- data/spec/dummy/app/decorators/post_decorator.rb +29 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +3 -0
- data/spec/dummy/app/mailers/post_mailer.rb +9 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +11 -0
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +1 -0
- data/spec/dummy/app/views/posts/_post.html.erb +19 -0
- data/spec/dummy/app/views/posts/show.html.erb +1 -0
- data/spec/dummy/config/application.rb +64 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +34 -0
- data/spec/dummy/config/environments/production.rb +55 -0
- data/spec/dummy/config/environments/test.rb +32 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
- data/spec/dummy/db/schema.rb +21 -0
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/dummy/lib/tasks/spec.rake +5 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +26 -0
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +29 -0
- data/spec/dummy/spec/spec_helper.rb +9 -0
- data/spec/generators/decorator/decorator_generator_spec.rb +25 -6
- data/spec/integration/integration_spec.rb +33 -0
- data/spec/minitest-rails/spec_type_spec.rb +63 -0
- data/{performance → spec/performance}/decorators.rb +2 -4
- data/spec/spec_helper.rb +23 -26
- data/spec/support/action_controller.rb +12 -0
- data/spec/support/active_model.rb +7 -0
- data/spec/support/{samples/active_record.rb → active_record.rb} +5 -0
- data/spec/support/{samples → decorators}/decorator_with_application_helper.rb +1 -1
- data/spec/support/decorators/namespaced_product_decorator.rb +5 -0
- data/spec/support/decorators/non_active_model_product_decorator.rb +2 -0
- data/spec/support/decorators/product_decorator.rb +23 -0
- data/spec/support/decorators/products_decorator.rb +10 -0
- data/spec/support/decorators/some_thing_decorator.rb +2 -0
- data/spec/support/{samples → decorators}/specific_product_decorator.rb +0 -2
- data/spec/support/dummy_app.rb +84 -0
- data/spec/support/matchers/have_text.rb +50 -0
- data/spec/support/{samples → models}/namespaced_product.rb +1 -3
- data/spec/support/{samples → models}/non_active_model_product.rb +1 -0
- data/spec/support/{samples → models}/product.rb +17 -2
- data/spec/support/models/some_thing.rb +5 -0
- data/spec/support/models/uninferrable_decorator_model.rb +3 -0
- metadata +211 -102
- data/doc/ApplicationDecorator.html +0 -147
- data/doc/Draper/AllHelpers.html +0 -256
- data/doc/Draper/Base.html +0 -1222
- data/doc/Draper/DecoratorGenerator.html +0 -216
- data/doc/Draper/LazyHelpers.html +0 -174
- data/doc/Draper/ModelSupport.html +0 -164
- data/doc/Draper/System.html +0 -179
- data/doc/Draper.html +0 -123
- data/doc/_index.html +0 -172
- data/doc/class_list.html +0 -47
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -53
- data/doc/css/style.css +0 -320
- data/doc/file_list.html +0 -46
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -172
- data/doc/js/app.js +0 -205
- data/doc/js/full_list.js +0 -150
- data/doc/js/jquery.js +0 -16
- data/doc/method_list.html +0 -174
- data/doc/top-level-namespace.html +0 -103
- data/lib/draper/active_model_support.rb +0 -27
- data/lib/draper/base.rb +0 -312
- data/lib/draper/decorated_enumerable_proxy.rb +0 -57
- data/lib/draper/model_support.rb +0 -17
- data/lib/draper/rspec_integration.rb +0 -2
- data/lib/draper/system.rb +0 -10
- data/lib/draper/test/view_context.rb +0 -12
- data/spec/draper/base_spec.rb +0 -863
- data/spec/draper/helper_support_spec.rb +0 -18
- data/spec/draper/model_support_spec.rb +0 -48
- data/spec/draper/view_context_spec.rb +0 -30
- data/spec/support/samples/active_model.rb +0 -9
- data/spec/support/samples/application_controller.rb +0 -42
- data/spec/support/samples/application_helper.rb +0 -8
- data/spec/support/samples/decorator.rb +0 -5
- data/spec/support/samples/decorator_with_allows.rb +0 -3
- data/spec/support/samples/decorator_with_denies.rb +0 -3
- data/spec/support/samples/decorator_with_denies_all.rb +0 -3
- data/spec/support/samples/decorator_with_multiple_allows.rb +0 -4
- data/spec/support/samples/decorator_with_special_methods.rb +0 -13
- data/spec/support/samples/namespaced_product_decorator.rb +0 -7
- data/spec/support/samples/product_decorator.rb +0 -7
- data/spec/support/samples/sequel_product.rb +0 -13
- data/spec/support/samples/some_thing.rb +0 -2
- data/spec/support/samples/some_thing_decorator.rb +0 -3
- /data/{performance → spec/performance}/active_record.rb +0 -0
- /data/{performance/bechmark.rb → spec/performance/benchmark.rb} +0 -0
- /data/{performance → spec/performance}/models.rb +0 -0
- /data/spec/support/{samples → decorators}/widget_decorator.rb +0 -0
- /data/spec/support/{samples → models}/widget.rb +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Draper::HelperSupport do
|
|
4
|
-
let(:product){ Product.new }
|
|
5
|
-
|
|
6
|
-
context '#decorate' do
|
|
7
|
-
it 'renders a block' do
|
|
8
|
-
output = ApplicationController.decorate(product){|p| p.model.object_id }
|
|
9
|
-
output.should == product.object_id
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'uses #capture so Rails only renders the content once' do
|
|
13
|
-
ApplicationController.decorate(product){|p| p.model.object_id }
|
|
14
|
-
ApplicationController.capture_triggered.should be
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Draper::ModelSupport do
|
|
4
|
-
subject { Product.new }
|
|
5
|
-
|
|
6
|
-
describe '#decorator' do
|
|
7
|
-
its(:decorator) { should be_kind_of(ProductDecorator) }
|
|
8
|
-
its(:decorator) { should be(subject.decorator) }
|
|
9
|
-
|
|
10
|
-
it 'have abillity to pass block' do
|
|
11
|
-
a = Product.new.decorator { |d| d.awesome_title }
|
|
12
|
-
a.should eql "Awesome Title"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'is aliased to .decorate' do
|
|
16
|
-
subject.decorator.model.should == subject.decorate.model
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe Draper::ModelSupport::ClassMethods do
|
|
21
|
-
shared_examples_for "a call to Draper::ModelSupport::ClassMethods#decorate" do
|
|
22
|
-
subject { klass.limit }
|
|
23
|
-
|
|
24
|
-
its(:decorate) { should be_kind_of(Draper::DecoratedEnumerableProxy) }
|
|
25
|
-
|
|
26
|
-
it "decorate the collection" do
|
|
27
|
-
subject.decorate.size.should == 1
|
|
28
|
-
subject.decorate.to_ary[0].model.should be_a(klass)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "return a new instance each time it is called" do
|
|
32
|
-
subject.decorate.should_not == subject.decorate
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe '#decorate - decorate collections of AR objects' do
|
|
37
|
-
let(:klass) { Product }
|
|
38
|
-
|
|
39
|
-
it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe '#decorate - decorate collections of namespaced AR objects' do
|
|
43
|
-
let(:klass) { Namespace::Product }
|
|
44
|
-
|
|
45
|
-
it_should_behave_like "a call to Draper::ModelSupport::ClassMethods#decorate"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'draper/test/view_context'
|
|
3
|
-
|
|
4
|
-
describe Draper::ViewContext do
|
|
5
|
-
before(:each) do
|
|
6
|
-
Thread.current[:current_view_context] = nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let(:app_controller) { ApplicationController }
|
|
10
|
-
let(:app_controller_instance) { app_controller.new }
|
|
11
|
-
|
|
12
|
-
it "provides a method to create a view context while testing" do
|
|
13
|
-
Draper::ViewContext.should respond_to(:infect!)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "copies the controller's view context to draper" do
|
|
17
|
-
ctx = app_controller_instance.view_context
|
|
18
|
-
Draper::ViewContext.current.should == ctx
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "view_context priming" do
|
|
22
|
-
let(:app_controller_instance) { double(ApplicationController, :view_context => view_context) }
|
|
23
|
-
let(:view_context) { double("ApplicationController#view_context") }
|
|
24
|
-
|
|
25
|
-
it "primes the view_context when nil" do
|
|
26
|
-
app_controller.should_receive(:new).and_return(app_controller_instance)
|
|
27
|
-
Draper::ViewContext.current.should == view_context
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require './spec/support/samples/application_helper'
|
|
2
|
-
|
|
3
|
-
module ActionController
|
|
4
|
-
class AbstractController
|
|
5
|
-
def view_context
|
|
6
|
-
@view_context ||= ApplicationController
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def view_context=(input)
|
|
10
|
-
@view_context = input
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
class Base < AbstractController
|
|
14
|
-
@@before_filters = []
|
|
15
|
-
def self.before_filters
|
|
16
|
-
@@before_filters
|
|
17
|
-
end
|
|
18
|
-
def self.before_filter(name)
|
|
19
|
-
@@before_filters << name
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
class ApplicationController < ActionController::Base
|
|
25
|
-
extend ActionView::Helpers
|
|
26
|
-
extend ActionView::Helpers::TagHelper
|
|
27
|
-
extend ActionView::Helpers::UrlHelper
|
|
28
|
-
extend ApplicationHelper
|
|
29
|
-
|
|
30
|
-
def self.hello
|
|
31
|
-
"Hello!"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def self.capture(&block)
|
|
35
|
-
@@capture = true
|
|
36
|
-
block.call
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def self.capture_triggered
|
|
40
|
-
@@capture ||= false
|
|
41
|
-
end
|
|
42
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|