draper 4.0.2 → 4.0.5
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.
- checksums.yaml +4 -4
- data/.rspec +1 -2
- data/CHANGELOG.md +24 -0
- data/README.md +26 -7
- data/lib/draper/automatic_delegation.rb +14 -4
- data/lib/draper/collection_decorator.rb +0 -6
- data/lib/draper/compatibility/broadcastable.rb +24 -0
- data/lib/draper/compatibility/global_id.rb +9 -5
- data/lib/draper/decoratable/collection_proxy.rb +15 -0
- data/lib/draper/decoratable.rb +7 -2
- data/lib/draper/decorator.rb +2 -18
- data/lib/draper/query_methods.rb +1 -1
- data/lib/draper/railtie.rb +14 -5
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context/build_strategy.rb +1 -9
- data/lib/draper.rb +0 -6
- metadata +16 -235
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -24
- data/.github/workflows/ci.yml +0 -55
- data/.gitignore +0 -18
- data/Gemfile +0 -24
- data/bin/bundle +0 -114
- data/bin/rake +0 -29
- data/draper.gemspec +0 -34
- data/spec/draper/collection_decorator_spec.rb +0 -291
- data/spec/draper/configuration_spec.rb +0 -49
- data/spec/draper/decoratable/equality_spec.rb +0 -10
- data/spec/draper/decoratable_spec.rb +0 -235
- data/spec/draper/decorated_association_spec.rb +0 -82
- data/spec/draper/decorates_assigned_spec.rb +0 -71
- data/spec/draper/decorator_spec.rb +0 -872
- data/spec/draper/draper_spec.rb +0 -25
- data/spec/draper/factory_spec.rb +0 -247
- data/spec/draper/finders_spec.rb +0 -166
- data/spec/draper/helper_proxy_spec.rb +0 -61
- data/spec/draper/lazy_helpers_spec.rb +0 -21
- data/spec/draper/query_methods/load_strategy_spec.rb +0 -26
- data/spec/draper/query_methods_spec.rb +0 -70
- data/spec/draper/undecorate_chain_spec.rb +0 -20
- data/spec/draper/undecorate_spec.rb +0 -19
- data/spec/draper/view_context/build_strategy_spec.rb +0 -132
- data/spec/draper/view_context_spec.rb +0 -182
- data/spec/draper/view_helpers_spec.rb +0 -8
- data/spec/dummy/.rspec +0 -2
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/base_controller.rb +0 -4
- data/spec/dummy/app/controllers/localized_urls.rb +0 -5
- data/spec/dummy/app/controllers/posts_controller.rb +0 -20
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +0 -4
- data/spec/dummy/app/decorators/post_decorator.rb +0 -60
- data/spec/dummy/app/helpers/application_helper.rb +0 -5
- data/spec/dummy/app/jobs/publish_post_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -3
- data/spec/dummy/app/mailers/post_mailer.rb +0 -19
- data/spec/dummy/app/models/admin.rb +0 -5
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/mongoid_post.rb +0 -5
- data/spec/dummy/app/models/post.rb +0 -3
- data/spec/dummy/app/models/user.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -11
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +0 -1
- data/spec/dummy/app/views/posts/_post.html.erb +0 -42
- data/spec/dummy/app/views/posts/show.html.erb +0 -1
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/config/application.rb +0 -68
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -35
- data/spec/dummy/config/environments/production.rb +0 -59
- data/spec/dummy/config/environments/test.rb +0 -35
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/draper.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -8
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/mongoid.yml +0 -142
- data/spec/dummy/config/routes.rb +0 -9
- data/spec/dummy/config/storage.yml +0 -7
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +0 -8
- data/spec/dummy/db/schema.rb +0 -21
- data/spec/dummy/db/seeds.rb +0 -2
- data/spec/dummy/fast_spec/post_decorator_spec.rb +0 -37
- data/spec/dummy/lib/tasks/test.rake +0 -16
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +0 -12
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -55
- data/spec/dummy/spec/decorators/helpers_spec.rb +0 -21
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +0 -64
- data/spec/dummy/spec/decorators/spec_type_spec.rb +0 -7
- data/spec/dummy/spec/decorators/view_context_spec.rb +0 -22
- data/spec/dummy/spec/jobs/publish_post_job_spec.rb +0 -9
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -25
- data/spec/dummy/spec/models/application_spec.rb +0 -7
- data/spec/dummy/spec/models/mongoid_post_spec.rb +0 -8
- data/spec/dummy/spec/models/post_spec.rb +0 -15
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -22
- data/spec/dummy/spec/spec_helper.rb +0 -8
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/minitest/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/minitest/spec_type_test.rb +0 -52
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +0 -24
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/test_unit/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +0 -24
- data/spec/dummy/test/minitest_helper.rb +0 -2
- data/spec/dummy/test/test_helper.rb +0 -3
- data/spec/generators/controller/controller_generator_spec.rb +0 -23
- data/spec/generators/decorator/decorator_generator_spec.rb +0 -93
- data/spec/generators/install/install_generator_spec.rb +0 -19
- data/spec/integration/integration_spec.rb +0 -70
- data/spec/performance/active_record.rb +0 -4
- data/spec/performance/benchmark.rb +0 -55
- data/spec/performance/decorators.rb +0 -45
- data/spec/performance/models.rb +0 -20
- data/spec/spec_helper.rb +0 -50
- data/spec/support/dummy_app.rb +0 -85
- data/spec/support/matchers/have_text.rb +0 -50
- data/spec/support/shared_examples/decoratable_equality.rb +0 -40
- data/spec/support/shared_examples/view_helpers.rb +0 -39
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
def fake_view_context
|
|
4
|
-
double("ViewContext")
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def fake_controller(view_context = fake_view_context)
|
|
8
|
-
double("Controller", view_context: view_context, request: double("Request"))
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
module Draper
|
|
12
|
-
describe ViewContext::BuildStrategy::Full do
|
|
13
|
-
describe "#call" do
|
|
14
|
-
context "when a current controller is set" do
|
|
15
|
-
it "returns the controller's view context" do
|
|
16
|
-
view_context = fake_view_context
|
|
17
|
-
allow(ViewContext).to receive_messages controller: fake_controller(view_context)
|
|
18
|
-
strategy = ViewContext::BuildStrategy::Full.new
|
|
19
|
-
|
|
20
|
-
expect(strategy.call).to be view_context
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context "when a current controller is not set" do
|
|
25
|
-
it "uses ApplicationController" do
|
|
26
|
-
expect(Draper::ViewContext.controller).to be_nil
|
|
27
|
-
view_context = ViewContext::BuildStrategy::Full.new.call
|
|
28
|
-
expect(view_context.controller).to eq Draper::ViewContext.controller
|
|
29
|
-
expect(view_context.controller).to be_an ApplicationController
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "adds a request if one is not defined" do
|
|
34
|
-
controller = Class.new(ActionController::Base).new
|
|
35
|
-
allow(ViewContext).to receive_messages controller: controller
|
|
36
|
-
strategy = ViewContext::BuildStrategy::Full.new
|
|
37
|
-
|
|
38
|
-
expect(controller.request).to be_nil
|
|
39
|
-
strategy.call
|
|
40
|
-
expect(controller.request).to be_an ActionController::TestRequest
|
|
41
|
-
expect(controller.params).to be_empty
|
|
42
|
-
|
|
43
|
-
# sanity checks
|
|
44
|
-
expect(controller.view_context.request).to be controller.request
|
|
45
|
-
expect(controller.view_context.params).to be controller.params
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "compatible with rails 5.1 change on ActionController::TestRequest.create method" do
|
|
49
|
-
ActionController::TestRequest.class_eval do
|
|
50
|
-
if ActionController::TestRequest.method(:create).parameters.first == []
|
|
51
|
-
def create controller_class
|
|
52
|
-
create
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
controller = Class.new(ActionController::Base).new
|
|
57
|
-
allow(ViewContext).to receive_messages controller: controller
|
|
58
|
-
strategy = ViewContext::BuildStrategy::Full.new
|
|
59
|
-
|
|
60
|
-
expect(controller.request).to be_nil
|
|
61
|
-
strategy.call
|
|
62
|
-
expect(controller.request).to be_an ActionController::TestRequest
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "adds methods to the view context from the constructor block" do
|
|
66
|
-
allow(ViewContext).to receive(:controller).and_return(fake_controller)
|
|
67
|
-
strategy = ViewContext::BuildStrategy::Full.new do
|
|
68
|
-
def a_helper_method; end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
expect(strategy.call).to respond_to :a_helper_method
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "includes modules into the view context from the constructor block" do
|
|
75
|
-
view_context = Object.new
|
|
76
|
-
allow(ViewContext).to receive(:controller).and_return(fake_controller(view_context))
|
|
77
|
-
helpers = Module.new do
|
|
78
|
-
def a_helper_method; end
|
|
79
|
-
end
|
|
80
|
-
strategy = ViewContext::BuildStrategy::Full.new do
|
|
81
|
-
include helpers
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
expect(strategy.call).to respond_to :a_helper_method
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe ViewContext::BuildStrategy::Fast do
|
|
90
|
-
describe "#call" do
|
|
91
|
-
it "returns an instance of a subclass of ActionView::Base" do
|
|
92
|
-
strategy = ViewContext::BuildStrategy::Fast.new
|
|
93
|
-
|
|
94
|
-
returned = strategy.call
|
|
95
|
-
|
|
96
|
-
expect(returned).to be_an ActionView::Base
|
|
97
|
-
expect(returned.class).not_to be ActionView::Base
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "returns different instances each time" do
|
|
101
|
-
strategy = ViewContext::BuildStrategy::Fast.new
|
|
102
|
-
|
|
103
|
-
expect(strategy.call).not_to be strategy.call
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "returns the same subclass each time" do
|
|
107
|
-
strategy = ViewContext::BuildStrategy::Fast.new
|
|
108
|
-
|
|
109
|
-
expect(strategy.call.class).to be strategy.call.class
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "adds methods to the view context from the constructor block" do
|
|
113
|
-
strategy = ViewContext::BuildStrategy::Fast.new do
|
|
114
|
-
def a_helper_method; end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
expect(strategy.call).to respond_to :a_helper_method
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "includes modules into the view context from the constructor block" do
|
|
121
|
-
helpers = Module.new do
|
|
122
|
-
def a_helper_method; end
|
|
123
|
-
end
|
|
124
|
-
strategy = ViewContext::BuildStrategy::Fast.new do
|
|
125
|
-
include helpers
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
expect(strategy.call).to respond_to :a_helper_method
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Draper
|
|
4
|
-
describe ViewContext do
|
|
5
|
-
describe "#view_context" do
|
|
6
|
-
let(:base) { Class.new { def view_context; :controller_view_context; end } }
|
|
7
|
-
let(:controller) { Class.new(base) { include ViewContext } }
|
|
8
|
-
|
|
9
|
-
it "saves the superclass's view context" do
|
|
10
|
-
expect(ViewContext).to receive(:current=).with(:controller_view_context)
|
|
11
|
-
controller.new.view_context
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "returns the superclass's view context" do
|
|
15
|
-
expect(controller.new.view_context).to be :controller_view_context
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe ".controller" do
|
|
20
|
-
it "returns the stored controller from RequestStore" do
|
|
21
|
-
allow(RequestStore).to receive_messages store: {current_controller: :stored_controller}
|
|
22
|
-
|
|
23
|
-
expect(ViewContext.controller).to be :stored_controller
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe ".controller=" do
|
|
28
|
-
it "stores a controller in RequestStore" do
|
|
29
|
-
store = {}
|
|
30
|
-
allow(RequestStore).to receive_messages store: store
|
|
31
|
-
|
|
32
|
-
ViewContext.controller = :stored_controller
|
|
33
|
-
expect(store[:current_controller]).to be :stored_controller
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "cleans context when controller changes" do
|
|
37
|
-
store = {
|
|
38
|
-
current_controller: :stored_controller,
|
|
39
|
-
current_view_context: :stored_view_context
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
allow(RequestStore).to receive_messages store: store
|
|
43
|
-
|
|
44
|
-
ViewContext.controller = :other_stored_controller
|
|
45
|
-
|
|
46
|
-
expect(store).to include(current_controller: :other_stored_controller)
|
|
47
|
-
expect(store).not_to include(:current_view_context)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "doesn't clean context when controller is the same" do
|
|
51
|
-
store = {
|
|
52
|
-
current_controller: :stored_controller,
|
|
53
|
-
current_view_context: :stored_view_context
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
allow(RequestStore).to receive_messages store: store
|
|
57
|
-
|
|
58
|
-
ViewContext.controller = :stored_controller
|
|
59
|
-
|
|
60
|
-
expect(store).to include(current_controller: :stored_controller)
|
|
61
|
-
expect(store).to include(current_view_context: :stored_view_context)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe ".current" do
|
|
66
|
-
it "returns the stored view context from RequestStore" do
|
|
67
|
-
allow(RequestStore).to receive_messages store: {current_view_context: :stored_view_context}
|
|
68
|
-
|
|
69
|
-
expect(ViewContext.current).to be :stored_view_context
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "when no view context is stored" do
|
|
73
|
-
it "builds a view context" do
|
|
74
|
-
allow(RequestStore).to receive_messages store: {}
|
|
75
|
-
allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context }
|
|
76
|
-
allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy)
|
|
77
|
-
|
|
78
|
-
expect(ViewContext.current).to be :new_helper_proxy
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "stores the built view context" do
|
|
82
|
-
store = {}
|
|
83
|
-
allow(RequestStore).to receive_messages store: store
|
|
84
|
-
allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context }
|
|
85
|
-
allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy)
|
|
86
|
-
|
|
87
|
-
ViewContext.current
|
|
88
|
-
expect(store[:current_view_context]).to be :new_helper_proxy
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
describe ".current=" do
|
|
94
|
-
it "stores a helper proxy for the view context in RequestStore" do
|
|
95
|
-
store = {}
|
|
96
|
-
allow(RequestStore).to receive_messages store: store
|
|
97
|
-
allow(HelperProxy).to receive(:new).with(:stored_view_context).and_return(:stored_helper_proxy)
|
|
98
|
-
|
|
99
|
-
ViewContext.current = :stored_view_context
|
|
100
|
-
expect(store[:current_view_context]).to be :stored_helper_proxy
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
describe ".clear!" do
|
|
105
|
-
it "clears the stored controller and view controller" do
|
|
106
|
-
store = {current_controller: :stored_controller, current_view_context: :stored_view_context}
|
|
107
|
-
allow(RequestStore).to receive_messages store: store
|
|
108
|
-
|
|
109
|
-
ViewContext.clear!
|
|
110
|
-
expect(store).not_to have_key :current_controller
|
|
111
|
-
expect(store).not_to have_key :current_view_context
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
describe ".build" do
|
|
116
|
-
it "returns a new view context using the build strategy" do
|
|
117
|
-
allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context }
|
|
118
|
-
|
|
119
|
-
expect(ViewContext.build).to be :new_view_context
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe ".build!" do
|
|
124
|
-
it "returns a helper proxy for the new view context" do
|
|
125
|
-
allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context }
|
|
126
|
-
allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy)
|
|
127
|
-
|
|
128
|
-
expect(ViewContext.build!).to be :new_helper_proxy
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "stores the helper proxy" do
|
|
132
|
-
store = {}
|
|
133
|
-
allow(RequestStore).to receive_messages store: store
|
|
134
|
-
allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context }
|
|
135
|
-
allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy)
|
|
136
|
-
|
|
137
|
-
ViewContext.build!
|
|
138
|
-
expect(store[:current_view_context]).to be :new_helper_proxy
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
describe ".build_strategy" do
|
|
143
|
-
it "defaults to full" do
|
|
144
|
-
expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Full
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "memoizes" do
|
|
148
|
-
expect(ViewContext.build_strategy).to be ViewContext.build_strategy
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
describe ".test_strategy" do
|
|
153
|
-
protect_module ViewContext
|
|
154
|
-
|
|
155
|
-
context "with :fast" do
|
|
156
|
-
it "creates a fast strategy" do
|
|
157
|
-
ViewContext.test_strategy :fast
|
|
158
|
-
expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Fast
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it "passes a block to the strategy" do
|
|
162
|
-
allow(ViewContext::BuildStrategy::Fast).to receive(:new) { |&block| block.call }
|
|
163
|
-
|
|
164
|
-
expect(ViewContext.test_strategy(:fast){:passed}).to be :passed
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "with :full" do
|
|
169
|
-
it "creates a full strategy" do
|
|
170
|
-
ViewContext.test_strategy :full
|
|
171
|
-
expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Full
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it "passes a block to the strategy" do
|
|
175
|
-
allow(ViewContext::BuildStrategy::Full).to receive(:new) { |&block| block.call }
|
|
176
|
-
|
|
177
|
-
expect(ViewContext.test_strategy(:full){:passed}).to be :passed
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
data/spec/dummy/.rspec
DELETED
data/spec/dummy/Rakefile
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env rake
|
|
2
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
-
|
|
5
|
-
require File.expand_path('../config/application', __FILE__)
|
|
6
|
-
|
|
7
|
-
Dummy::Application.load_tasks
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class PostsController < BaseController
|
|
2
|
-
decorates_assigned :post
|
|
3
|
-
|
|
4
|
-
def show
|
|
5
|
-
@post = Post.find(params[:id])
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def mail
|
|
9
|
-
post = Post.find(params[:id])
|
|
10
|
-
email = PostMailer.decorated_email(post).deliver
|
|
11
|
-
render html: email.body.to_s.html_safe
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def goodnight_moon
|
|
17
|
-
"Goodnight, moon!"
|
|
18
|
-
end
|
|
19
|
-
helper_method :goodnight_moon
|
|
20
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
class PostDecorator < Draper::Decorator
|
|
2
|
-
# don't delegate_all here because it helps to identify things we
|
|
3
|
-
# have to delegate for ActiveModel compatibility
|
|
4
|
-
|
|
5
|
-
# need to delegate attribute methods for AM::Serialization
|
|
6
|
-
# need to delegate id and new_record? for AR::Base#== (Rails 3.0 only)
|
|
7
|
-
delegate :id, :created_at, :new_record?
|
|
8
|
-
|
|
9
|
-
def posted_date
|
|
10
|
-
if created_at.to_date == DateTime.now.utc.to_date
|
|
11
|
-
"Today"
|
|
12
|
-
else
|
|
13
|
-
"Not Today"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def path_with_model
|
|
18
|
-
h.post_path(object)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def path_with_id
|
|
22
|
-
h.post_path(id: id)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def url_with_model
|
|
26
|
-
h.post_url(object)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def url_with_id
|
|
30
|
-
h.post_url(id: id)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def link
|
|
34
|
-
h.link_to id.to_s, self
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def truncated
|
|
38
|
-
h.truncate("Once upon a time in a world far far away", length: 17, separator: ' ')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def html_escaped
|
|
42
|
-
h.html_escape("<script>danger</script>")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def hello_world
|
|
46
|
-
h.hello_world
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def goodnight_moon
|
|
50
|
-
h.goodnight_moon
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def updated_at
|
|
54
|
-
:overridden
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def persisted?
|
|
58
|
-
true
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class PostMailer < ApplicationMailer
|
|
2
|
-
default from: "from@example.com"
|
|
3
|
-
layout "application"
|
|
4
|
-
|
|
5
|
-
# Mailers don't import app/helpers automatically
|
|
6
|
-
helper :application
|
|
7
|
-
|
|
8
|
-
def decorated_email(post)
|
|
9
|
-
@post = post.decorate
|
|
10
|
-
mail to: "to@example.com", subject: "A decorated post"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
def goodnight_moon
|
|
16
|
-
"Goodnight, moon!"
|
|
17
|
-
end
|
|
18
|
-
helper_method :goodnight_moon
|
|
19
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= render @post %>
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
<dl>
|
|
2
|
-
<dt>Environment:</dt>
|
|
3
|
-
<dd id="environment"><%= Rails.env %></dd>
|
|
4
|
-
|
|
5
|
-
<dt>Draper view context controller:</dt>
|
|
6
|
-
<dd id="controller"><%= Draper::ViewContext.current.controller.class %></dd>
|
|
7
|
-
|
|
8
|
-
<dt>Posted:</dt>
|
|
9
|
-
<dd id="posted_date"><%= post.posted_date %></dd>
|
|
10
|
-
|
|
11
|
-
<dt>Built-in helpers:</dt>
|
|
12
|
-
<dd id="truncated"><%= post.truncated %></dd>
|
|
13
|
-
|
|
14
|
-
<dt>Built-in private helpers:</dt>
|
|
15
|
-
<dd id="html_escaped"><%= post.html_escaped %></dd>
|
|
16
|
-
|
|
17
|
-
<dt>Helpers from app/helpers:</dt>
|
|
18
|
-
<dd id="hello_world"><%= post.hello_world %></dd>
|
|
19
|
-
|
|
20
|
-
<dt>Helpers from the controller:</dt>
|
|
21
|
-
<dd id="goodnight_moon"><%= post.goodnight_moon %></dd>
|
|
22
|
-
|
|
23
|
-
<% unless defined? mailer %>
|
|
24
|
-
<dt>Path with decorator:</dt>
|
|
25
|
-
<dd id="path_with_decorator"><%= post_url(post) %></dd>
|
|
26
|
-
|
|
27
|
-
<dt>Path with model:</dt>
|
|
28
|
-
<dd id="path_with_model"><%= post.path_with_model %></dd>
|
|
29
|
-
|
|
30
|
-
<dt>Path with id:</dt>
|
|
31
|
-
<dd id="path_with_id"><%= post.path_with_id %></dd>
|
|
32
|
-
<% end %>
|
|
33
|
-
|
|
34
|
-
<dt>URL with decorator:</dt>
|
|
35
|
-
<dd id="url_with_decorator"><%= post_url(post) %></dd>
|
|
36
|
-
|
|
37
|
-
<dt>URL with model:</dt>
|
|
38
|
-
<dd id="url_with_model"><%= post.url_with_model %></dd>
|
|
39
|
-
|
|
40
|
-
<dt>URL with id:</dt>
|
|
41
|
-
<dd id="url_with_id"><%= post.url_with_id %></dd>
|
|
42
|
-
</dl>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= render post %>
|
data/spec/dummy/bin/rails
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
|
2
|
-
|
|
3
|
-
def attempt_require(file)
|
|
4
|
-
require file
|
|
5
|
-
rescue LoadError
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require 'rails/all'
|
|
9
|
-
require 'draper'
|
|
10
|
-
attempt_require 'mongoid'
|
|
11
|
-
attempt_require 'devise'
|
|
12
|
-
require 'active_model_serializers'
|
|
13
|
-
|
|
14
|
-
module Dummy
|
|
15
|
-
class Application < Rails::Application
|
|
16
|
-
# Settings in config/environments/* take precedence over those specified here.
|
|
17
|
-
# Application configuration should go into files in config/initializers
|
|
18
|
-
# -- all .rb files in that directory are automatically loaded.
|
|
19
|
-
|
|
20
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
|
21
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
|
22
|
-
|
|
23
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
|
24
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
|
25
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
|
26
|
-
|
|
27
|
-
# Activate observers that should always be running.
|
|
28
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
|
29
|
-
|
|
30
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
31
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
|
32
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
|
33
|
-
|
|
34
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
35
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
36
|
-
# config.i18n.default_locale = :de
|
|
37
|
-
|
|
38
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
|
39
|
-
config.encoding = "utf-8"
|
|
40
|
-
|
|
41
|
-
# Enable escaping HTML in JSON.
|
|
42
|
-
config.active_support.escape_html_entities_in_json = true
|
|
43
|
-
|
|
44
|
-
# Use SQL instead of Active Record's schema dumper when creating the database.
|
|
45
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
|
46
|
-
# like if you have constraints or database-specific column types
|
|
47
|
-
# config.active_record.schema_format = :sql
|
|
48
|
-
|
|
49
|
-
# Enforce whitelist mode for mass assignment.
|
|
50
|
-
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
|
51
|
-
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
|
52
|
-
# parameters by using an attr_accessible or attr_protected declaration.
|
|
53
|
-
# config.active_record.whitelist_attributes = true
|
|
54
|
-
|
|
55
|
-
# Enable the asset pipeline
|
|
56
|
-
# config.assets.enabled = true
|
|
57
|
-
|
|
58
|
-
# Version of your assets, change this if you want to expire all your assets
|
|
59
|
-
# config.assets.version = '1.0'
|
|
60
|
-
|
|
61
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
|
62
|
-
# The :test delivery method accumulates sent emails in the
|
|
63
|
-
# ActionMailer::Base.deliveries array.
|
|
64
|
-
config.action_mailer.delivery_method = :test
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
ActiveRecord::Migration.verbose = false
|