drape 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +27 -0
  3. data/.gitignore +18 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +1159 -0
  6. data/.travis.yml +14 -0
  7. data/.yardopts +1 -0
  8. data/CHANGELOG.md +230 -0
  9. data/CONTRIBUTING.md +20 -0
  10. data/Gemfile +16 -0
  11. data/Guardfile +26 -0
  12. data/LICENSE +7 -0
  13. data/README.md +592 -0
  14. data/Rakefile +76 -0
  15. data/drape.gemspec +31 -0
  16. data/gemfiles/5.0.gemfile +8 -0
  17. data/lib/drape.rb +63 -0
  18. data/lib/drape/automatic_delegation.rb +55 -0
  19. data/lib/drape/collection_decorator.rb +102 -0
  20. data/lib/drape/decoratable.rb +93 -0
  21. data/lib/drape/decoratable/equality.rb +26 -0
  22. data/lib/drape/decorated_association.rb +33 -0
  23. data/lib/drape/decorates_assigned.rb +44 -0
  24. data/lib/drape/decorator.rb +282 -0
  25. data/lib/drape/delegation.rb +13 -0
  26. data/lib/drape/factory.rb +91 -0
  27. data/lib/drape/finders.rb +36 -0
  28. data/lib/drape/helper_proxy.rb +43 -0
  29. data/lib/drape/helper_support.rb +5 -0
  30. data/lib/drape/lazy_helpers.rb +13 -0
  31. data/lib/drape/railtie.rb +69 -0
  32. data/lib/drape/tasks/test.rake +9 -0
  33. data/lib/drape/test/devise_helper.rb +30 -0
  34. data/lib/drape/test/minitest_integration.rb +6 -0
  35. data/lib/drape/test/rspec_integration.rb +20 -0
  36. data/lib/drape/test_case.rb +42 -0
  37. data/lib/drape/undecorate.rb +9 -0
  38. data/lib/drape/version.rb +3 -0
  39. data/lib/drape/view_context.rb +104 -0
  40. data/lib/drape/view_context/build_strategy.rb +46 -0
  41. data/lib/drape/view_helpers.rb +34 -0
  42. data/lib/generators/controller_override.rb +17 -0
  43. data/lib/generators/mini_test/decorator_generator.rb +20 -0
  44. data/lib/generators/mini_test/templates/decorator_spec.rb +4 -0
  45. data/lib/generators/mini_test/templates/decorator_test.rb +4 -0
  46. data/lib/generators/rails/decorator_generator.rb +36 -0
  47. data/lib/generators/rails/templates/decorator.rb +19 -0
  48. data/lib/generators/rspec/decorator_generator.rb +9 -0
  49. data/lib/generators/rspec/templates/decorator_spec.rb +4 -0
  50. data/lib/generators/test_unit/decorator_generator.rb +9 -0
  51. data/lib/generators/test_unit/templates/decorator_test.rb +4 -0
  52. data/spec/draper/collection_decorator_spec.rb +305 -0
  53. data/spec/draper/decoratable/equality_spec.rb +10 -0
  54. data/spec/draper/decoratable_spec.rb +203 -0
  55. data/spec/draper/decorated_association_spec.rb +85 -0
  56. data/spec/draper/decorates_assigned_spec.rb +70 -0
  57. data/spec/draper/decorator_spec.rb +828 -0
  58. data/spec/draper/factory_spec.rb +250 -0
  59. data/spec/draper/finders_spec.rb +165 -0
  60. data/spec/draper/helper_proxy_spec.rb +61 -0
  61. data/spec/draper/lazy_helpers_spec.rb +21 -0
  62. data/spec/draper/undecorate_spec.rb +19 -0
  63. data/spec/draper/view_context/build_strategy_spec.rb +116 -0
  64. data/spec/draper/view_context_spec.rb +160 -0
  65. data/spec/draper/view_helpers_spec.rb +8 -0
  66. data/spec/dummy/.gitignore +21 -0
  67. data/spec/dummy/Rakefile +6 -0
  68. data/spec/dummy/app/assets/config/manifest.js +3 -0
  69. data/spec/dummy/app/assets/images/.keep +0 -0
  70. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  71. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  72. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  73. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  74. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  75. data/spec/dummy/app/channels/application_cable/connection.rb +5 -0
  76. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  77. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  78. data/spec/dummy/app/controllers/posts_controller.rb +21 -0
  79. data/spec/dummy/app/decorators/mongoid_post_decorator.rb +4 -0
  80. data/spec/dummy/app/decorators/post_decorator.rb +59 -0
  81. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  82. data/spec/dummy/app/jobs/application_job.rb +2 -0
  83. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  84. data/spec/dummy/app/mailers/post_mailer.rb +18 -0
  85. data/spec/dummy/app/models/admin.rb +5 -0
  86. data/spec/dummy/app/models/application_record.rb +3 -0
  87. data/spec/dummy/app/models/concerns/.keep +0 -0
  88. data/spec/dummy/app/models/mongoid_post.rb +5 -0
  89. data/spec/dummy/app/models/post.rb +3 -0
  90. data/spec/dummy/app/models/user.rb +5 -0
  91. data/spec/dummy/app/views/layouts/application.html.erb +9 -0
  92. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  93. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  94. data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +31 -0
  95. data/spec/dummy/app/views/posts/_post.html.erb +40 -0
  96. data/spec/dummy/app/views/posts/show.html.erb +1 -0
  97. data/spec/dummy/bin/bundle +3 -0
  98. data/spec/dummy/bin/rails +9 -0
  99. data/spec/dummy/bin/rake +9 -0
  100. data/spec/dummy/bin/setup +34 -0
  101. data/spec/dummy/bin/spring +15 -0
  102. data/spec/dummy/bin/update +29 -0
  103. data/spec/dummy/config.ru +5 -0
  104. data/spec/dummy/config/application.rb +21 -0
  105. data/spec/dummy/config/boot.rb +2 -0
  106. data/spec/dummy/config/cable.yml +10 -0
  107. data/spec/dummy/config/database.yml +25 -0
  108. data/spec/dummy/config/environment.rb +5 -0
  109. data/spec/dummy/config/environments/development.rb +51 -0
  110. data/spec/dummy/config/environments/production.rb +91 -0
  111. data/spec/dummy/config/environments/test.rb +42 -0
  112. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  113. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  114. data/spec/dummy/config/initializers/assets.rb +11 -0
  115. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  116. data/spec/dummy/config/initializers/callback_terminator.rb +6 -0
  117. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  118. data/spec/dummy/config/initializers/devise.rb +3 -0
  119. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  120. data/spec/dummy/config/initializers/inflections.rb +16 -0
  121. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  122. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +4 -0
  123. data/spec/dummy/config/initializers/request_forgery_protection.rb +4 -0
  124. data/spec/dummy/config/initializers/session_store.rb +3 -0
  125. data/spec/dummy/config/initializers/ssl_options.rb +4 -0
  126. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  127. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  128. data/spec/dummy/config/locales/en.yml +23 -0
  129. data/spec/dummy/config/mongoid.yml +16 -0
  130. data/spec/dummy/config/puma.rb +47 -0
  131. data/spec/dummy/config/routes.rb +8 -0
  132. data/spec/dummy/config/secrets.yml +22 -0
  133. data/spec/dummy/config/spring.rb +6 -0
  134. data/spec/dummy/db/migrate/20121019115657_create_posts.rb +7 -0
  135. data/spec/dummy/db/schema.rb +19 -0
  136. data/spec/dummy/db/seeds.rb +2 -0
  137. data/spec/dummy/lib/assets/.keep +0 -0
  138. data/spec/dummy/lib/tasks/.keep +0 -0
  139. data/spec/dummy/lib/tasks/test.rake +16 -0
  140. data/spec/dummy/log/.keep +0 -0
  141. data/spec/dummy/public/404.html +67 -0
  142. data/spec/dummy/public/422.html +67 -0
  143. data/spec/dummy/public/500.html +66 -0
  144. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  145. data/spec/dummy/public/apple-touch-icon.png +0 -0
  146. data/spec/dummy/public/favicon.ico +0 -0
  147. data/spec/dummy/public/robots.txt +5 -0
  148. data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +12 -0
  149. data/spec/dummy/spec/decorators/devise_spec.rb +64 -0
  150. data/spec/dummy/spec/decorators/helpers_spec.rb +21 -0
  151. data/spec/dummy/spec/decorators/post_decorator_spec.rb +66 -0
  152. data/spec/dummy/spec/decorators/spec_type_spec.rb +7 -0
  153. data/spec/dummy/spec/decorators/view_context_spec.rb +22 -0
  154. data/spec/dummy/spec/mailers/post_mailer_spec.rb +33 -0
  155. data/spec/dummy/spec/models/mongoid_post_spec.rb +8 -0
  156. data/spec/dummy/spec/models/post_spec.rb +6 -0
  157. data/spec/dummy/spec/shared_examples/decoratable.rb +26 -0
  158. data/spec/dummy/spec/spec_helper.rb +8 -0
  159. data/spec/dummy/test/controllers/.keep +0 -0
  160. data/spec/dummy/test/fixtures/.keep +0 -0
  161. data/spec/dummy/test/fixtures/files/.keep +0 -0
  162. data/spec/dummy/test/helpers/.keep +0 -0
  163. data/spec/dummy/test/integration/.keep +0 -0
  164. data/spec/dummy/test/mailers/.keep +0 -0
  165. data/spec/dummy/test/models/.keep +0 -0
  166. data/spec/dummy/test/test_helper.rb +10 -0
  167. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  168. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
  169. data/spec/generators/controller/controller_generator_spec.rb +24 -0
  170. data/spec/generators/decorator/decorator_generator_spec.rb +94 -0
  171. data/spec/integration/integration_spec.rb +68 -0
  172. data/spec/performance/active_record.rb +4 -0
  173. data/spec/performance/benchmark.rb +57 -0
  174. data/spec/performance/decorators.rb +41 -0
  175. data/spec/performance/models.rb +20 -0
  176. data/spec/spec_helper.rb +41 -0
  177. data/spec/support/dummy_app.rb +88 -0
  178. data/spec/support/matchers/have_text.rb +50 -0
  179. data/spec/support/shared_examples/decoratable_equality.rb +40 -0
  180. data/spec/support/shared_examples/view_helpers.rb +39 -0
  181. metadata +497 -0
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Drape
4
+ describe LazyHelpers do
5
+ describe '#method_missing' do
6
+ let(:decorator) do
7
+ Struct.new(:helpers) { include Drape::LazyHelpers }.new(double)
8
+ end
9
+
10
+ it 'proxies methods to #helpers' do
11
+ decorator.helpers.stub(:foo) { |arg| arg }
12
+ expect(decorator.foo(:passed)).to be :passed
13
+ end
14
+
15
+ it 'passes blocks' do
16
+ decorator.helpers.stub(:foo) { |&block| block.call }
17
+ expect(decorator.foo { :yielded }).to be :yielded
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Drape, '.undecorate' do
4
+ it 'undecorates a decorated object' do
5
+ object = Model.new
6
+ decorator = Drape::Decorator.new(object)
7
+ expect(Drape.undecorate(decorator)).to equal object
8
+ end
9
+
10
+ it 'passes a non-decorated object through' do
11
+ object = Model.new
12
+ expect(Drape.undecorate(object)).to equal object
13
+ end
14
+
15
+ it 'passes a non-decorator object through' do
16
+ object = Object.new
17
+ expect(Drape.undecorate(object)).to equal object
18
+ end
19
+ end
@@ -0,0 +1,116 @@
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 Drape
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
+ ViewContext.stub 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
+ view_context = fake_view_context
27
+ stub_const 'ApplicationController', double(new: fake_controller(view_context))
28
+ strategy = ViewContext::BuildStrategy::Full.new
29
+
30
+ expect(strategy.call).to be view_context
31
+ end
32
+ end
33
+
34
+ it 'adds a request if one is not defined' do
35
+ controller = Class.new(ActionController::Base).new
36
+ ViewContext.stub controller: controller
37
+ strategy = ViewContext::BuildStrategy::Full.new
38
+
39
+ expect(controller.request).to be_nil
40
+ strategy.call
41
+ expect(controller.request).to be_an ActionController::TestRequest
42
+ expect(controller.params).to eq({})
43
+
44
+ # sanity checks
45
+ expect(controller.view_context.request).to be controller.request
46
+ expect(controller.view_context.params).to be controller.params
47
+ end
48
+
49
+ it 'adds methods to the view context from the constructor block' do
50
+ ViewContext.stub controller: fake_controller
51
+ strategy = ViewContext::BuildStrategy::Full.new do
52
+ def a_helper_method; end
53
+ end
54
+
55
+ expect(strategy.call).to respond_to :a_helper_method
56
+ end
57
+
58
+ it 'includes modules into the view context from the constructor block' do
59
+ view_context = Object.new
60
+ ViewContext.stub controller: fake_controller(view_context)
61
+ helpers = Module.new do
62
+ def a_helper_method; end
63
+ end
64
+ strategy = ViewContext::BuildStrategy::Full.new do
65
+ include helpers
66
+ end
67
+
68
+ expect(strategy.call).to respond_to :a_helper_method
69
+ end
70
+ end
71
+ end
72
+
73
+ describe ViewContext::BuildStrategy::Fast do
74
+ describe '#call' do
75
+ it 'returns an instance of a subclass of ActionView::Base' do
76
+ strategy = ViewContext::BuildStrategy::Fast.new
77
+
78
+ returned = strategy.call
79
+
80
+ expect(returned).to be_an ActionView::Base
81
+ expect(returned.class).not_to be ActionView::Base
82
+ end
83
+
84
+ it 'returns different instances each time' do
85
+ strategy = ViewContext::BuildStrategy::Fast.new
86
+
87
+ expect(strategy.call).not_to be strategy.call
88
+ end
89
+
90
+ it 'returns the same subclass each time' do
91
+ strategy = ViewContext::BuildStrategy::Fast.new
92
+
93
+ expect(strategy.call.class).to be strategy.call.class
94
+ end
95
+
96
+ it 'adds methods to the view context from the constructor block' do
97
+ strategy = ViewContext::BuildStrategy::Fast.new do
98
+ def a_helper_method; end
99
+ end
100
+
101
+ expect(strategy.call).to respond_to :a_helper_method
102
+ end
103
+
104
+ it 'includes modules into the view context from the constructor block' do
105
+ helpers = Module.new do
106
+ def a_helper_method; end
107
+ end
108
+ strategy = ViewContext::BuildStrategy::Fast.new do
109
+ include helpers
110
+ end
111
+
112
+ expect(strategy.call).to respond_to :a_helper_method
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ module Drape
4
+ describe ViewContext do
5
+ describe '#view_context' do
6
+ let(:base) do
7
+ Class.new do
8
+ def view_context
9
+ :controller_view_context
10
+ end
11
+ end
12
+ end
13
+ let(:controller) { Class.new(base) { include ViewContext } }
14
+
15
+ it "saves the superclass's view context" do
16
+ ViewContext.should_receive(:current=).with(:controller_view_context)
17
+ controller.new.view_context
18
+ end
19
+
20
+ it "returns the superclass's view context" do
21
+ expect(controller.new.view_context).to be :controller_view_context
22
+ end
23
+ end
24
+
25
+ describe '.controller' do
26
+ it 'returns the stored controller from RequestStore' do
27
+ RequestStore.stub store: { current_controller: :stored_controller }
28
+
29
+ expect(ViewContext.controller).to be :stored_controller
30
+ end
31
+ end
32
+
33
+ describe '.controller=' do
34
+ it 'stores a controller in RequestStore' do
35
+ store = {}
36
+ RequestStore.stub store: store
37
+
38
+ ViewContext.controller = :stored_controller
39
+ expect(store[:current_controller]).to be :stored_controller
40
+ end
41
+ end
42
+
43
+ describe '.current' do
44
+ it 'returns the stored view context from RequestStore' do
45
+ RequestStore.stub store: { current_view_context: :stored_view_context }
46
+
47
+ expect(ViewContext.current).to be :stored_view_context
48
+ end
49
+
50
+ context 'when no view context is stored' do
51
+ it 'builds a view context' do
52
+ RequestStore.stub store: {}
53
+ ViewContext.stub build_strategy: -> { :new_view_context }
54
+ HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy)
55
+
56
+ expect(ViewContext.current).to be :new_helper_proxy
57
+ end
58
+
59
+ it 'stores the built view context' do
60
+ store = {}
61
+ RequestStore.stub store: store
62
+ ViewContext.stub build_strategy: -> { :new_view_context }
63
+ HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy)
64
+
65
+ ViewContext.current
66
+ expect(store[:current_view_context]).to be :new_helper_proxy
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '.current=' do
72
+ it 'stores a helper proxy for the view context in RequestStore' do
73
+ store = {}
74
+ RequestStore.stub store: store
75
+ HelperProxy.stub(:new).with(:stored_view_context).and_return(:stored_helper_proxy)
76
+
77
+ ViewContext.current = :stored_view_context
78
+ expect(store[:current_view_context]).to be :stored_helper_proxy
79
+ end
80
+ end
81
+
82
+ describe '.clear!' do
83
+ it 'clears the stored controller and view controller' do
84
+ store = { current_controller: :stored_controller, current_view_context: :stored_view_context }
85
+ RequestStore.stub store: store
86
+
87
+ ViewContext.clear!
88
+ expect(store).not_to have_key :current_controller
89
+ expect(store).not_to have_key :current_view_context
90
+ end
91
+ end
92
+
93
+ describe '.build' do
94
+ it 'returns a new view context using the build strategy' do
95
+ ViewContext.stub build_strategy: -> { :new_view_context }
96
+
97
+ expect(ViewContext.build).to be :new_view_context
98
+ end
99
+ end
100
+
101
+ describe '.build!' do
102
+ it 'returns a helper proxy for the new view context' do
103
+ ViewContext.stub build_strategy: -> { :new_view_context }
104
+ HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy)
105
+
106
+ expect(ViewContext.build!).to be :new_helper_proxy
107
+ end
108
+
109
+ it 'stores the helper proxy' do
110
+ store = {}
111
+ RequestStore.stub store: store
112
+ ViewContext.stub build_strategy: -> { :new_view_context }
113
+ HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy)
114
+
115
+ ViewContext.build!
116
+ expect(store[:current_view_context]).to be :new_helper_proxy
117
+ end
118
+ end
119
+
120
+ describe '.build_strategy' do
121
+ it 'defaults to full' do
122
+ expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Full
123
+ end
124
+
125
+ it 'memoizes' do
126
+ expect(ViewContext.build_strategy).to be ViewContext.build_strategy
127
+ end
128
+ end
129
+
130
+ describe '.test_strategy' do
131
+ protect_module ViewContext
132
+
133
+ context 'with :fast' do
134
+ it 'creates a fast strategy' do
135
+ ViewContext.test_strategy :fast
136
+ expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Fast
137
+ end
138
+
139
+ it 'passes a block to the strategy' do
140
+ ViewContext::BuildStrategy::Fast.stub(:new) { |&block| block.call }
141
+
142
+ expect(ViewContext.test_strategy(:fast) { :passed }).to be :passed
143
+ end
144
+ end
145
+
146
+ context 'with :full' do
147
+ it 'creates a full strategy' do
148
+ ViewContext.test_strategy :full
149
+ expect(ViewContext.build_strategy).to be_a ViewContext::BuildStrategy::Full
150
+ end
151
+
152
+ it 'passes a block to the strategy' do
153
+ ViewContext::BuildStrategy::Full.stub(:new) { |&block| block.call }
154
+
155
+ expect(ViewContext.test_strategy(:full) { :passed }).to be :passed
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'support/shared_examples/view_helpers'
3
+
4
+ module Drape
5
+ describe ViewHelpers do
6
+ it_behaves_like 'view helpers', Class.new { include ViewHelpers }.new
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore Byebug command history file.
21
+ .byebug_history
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
2
+ module ApplicationCable
3
+ class Connection < ActionCable::Connection::Base
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,21 @@
1
+ class PostsController < ApplicationController
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 text: email.body
12
+ end
13
+
14
+ private
15
+
16
+ def goodnight_moon
17
+ 'Goodnight, moon!'
18
+ end
19
+
20
+ helper_method :goodnight_moon
21
+ end