detaso-oprah 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,182 @@
1
+ require 'helper'
2
+
3
+ module Oprah
4
+ class PresenterTest < Minitest::Test
5
+ include Fixtures
6
+
7
+ def test_cache
8
+ assert_kind_of ActiveSupport::Cache::MemoryStore, Presenter.cache
9
+ assert_equal Presenter.cache, Presenter.cache
10
+ assert_equal UserPresenter.cache, Presenter.cache
11
+ end
12
+
13
+ def test_present
14
+ assert_presented present(User.new)
15
+ end
16
+
17
+ def test_present_with_eigenclass
18
+ assert_equal false, present(EigenUser.new).nil?
19
+ end
20
+
21
+ def test_present_no_matching_presenter
22
+ object = Object.new
23
+ presented = present(object)
24
+
25
+ refute_presented presented
26
+ assert_equal presented, object
27
+ end
28
+
29
+ def test_present_only
30
+ presenter = present(User.new, only: UserPresenter)
31
+
32
+ assert_kind_of UserPresenter, presenter
33
+ refute_kind_of EntityPresenter, presenter
34
+
35
+ classes = [UserPresenter, EntityPresenter, CommentPresenter]
36
+ presenter = present(User.new, only: classes)
37
+
38
+ assert_kind_of UserPresenter, presenter
39
+ assert_kind_of EntityPresenter, presenter
40
+ refute_kind_of CommentPresenter, presenter
41
+ end
42
+
43
+ def test_present_many
44
+ present_many([User.new, User.new]).each do |presenter|
45
+ assert_equal "Foo Bar", presenter.name
46
+ end
47
+ end
48
+
49
+ def test_presents_many
50
+ project = present(Project.new)
51
+
52
+ assert_equal 3, project.comments.length
53
+
54
+ project.comments.each do |comment|
55
+ assert_kind_of Comment, comment
56
+ assert_kind_of CommentPresenter, comment
57
+ assert_equal project.view_context.object_id,
58
+ comment.view_context.object_id
59
+ end
60
+ end
61
+
62
+ def test_present_from_instance
63
+ view_context = Object.new
64
+ presenter = present(User.new, view_context: view_context)
65
+ presented = presenter.present(User.new)
66
+
67
+ assert_equal view_context.object_id, presented.view_context.object_id
68
+ end
69
+
70
+ def test_present_many_from_instance
71
+ view_context = Object.new
72
+ presenter = present(User.new, view_context: view_context)
73
+ presented = presenter.present_many([User.new]).first
74
+
75
+ assert_equal view_context.object_id, presented.view_context.object_id
76
+ end
77
+
78
+ def test_present_from_instance_custom_view_context
79
+ view_context = Object.new
80
+ presenter = present(User.new, view_context: view_context)
81
+ presented = presenter.present(User.new, view_context: :ok)
82
+
83
+ assert_equal :ok, presented.view_context
84
+ end
85
+
86
+ def test_present_many_from_instance_custom_view_context
87
+ view_context = Object.new
88
+ presenter = present(User.new, view_context: view_context)
89
+ presented = presenter.present_many([User.new], view_context: :ok).first
90
+
91
+ assert_equal :ok, presented.view_context
92
+ end
93
+
94
+ def test_presents_one
95
+ project = present(Project.new)
96
+ owner = project.owner
97
+
98
+ assert_kind_of UserPresenter, owner
99
+ assert_kind_of User, owner
100
+ assert_equal project.view_context.object_id,
101
+ owner.view_context.object_id
102
+ end
103
+
104
+ def test_presenter_stack_ordering
105
+ assert_equal "foobar", present(User.new).foo
106
+ end
107
+
108
+ def test_default_view_context_using_present
109
+ presenter = Presenter.present(User.new)
110
+ assert_kind_of ActionView::Context, presenter.view_context
111
+ end
112
+
113
+ def test_default_view_context_using_initialize
114
+ presenter = UserPresenter.new(User.new)
115
+ assert_kind_of ActionView::Context, presenter.view_context
116
+ end
117
+
118
+ def test_default_view_context_unique_per_presenter
119
+ refute_equal present(User.new).view_context,
120
+ present(User.new).view_context
121
+ end
122
+
123
+ def test_method_missing_delegation
124
+ assert_equal "Foo Bar", present(User.new).name
125
+ assert_equal "Foo", present(User.new).first_name
126
+ assert_equal "Bar", present(User.new).last_name
127
+ end
128
+
129
+ def test_method_missing_wont_delegate_to_private_methods
130
+ assert_raises NoMethodError do
131
+ present(User.new).password
132
+ end
133
+ end
134
+
135
+ def test_kind_of?
136
+ presenter = present(User.new)
137
+
138
+ assert_kind_of User, presenter
139
+ assert_kind_of UserPresenter, presenter
140
+ assert_kind_of Entity, presenter
141
+ assert_kind_of EntityPresenter, presenter
142
+ refute_kind_of self.class, presenter
143
+ end
144
+
145
+ def test_instance_of?
146
+ presenter = present(User.new)
147
+
148
+ assert_instance_of User, presenter
149
+ assert_instance_of UserPresenter, presenter
150
+ refute_instance_of Entity, presenter
151
+ assert_instance_of EntityPresenter, presenter
152
+ refute_instance_of self.class, presenter
153
+ end
154
+
155
+ def test_equality
156
+ project = Project.new
157
+ project_presenter = Project.new
158
+
159
+ user = User.new
160
+ user_presenter = present(user)
161
+
162
+ assert_equal user_presenter, user
163
+ assert_equal user_presenter, user_presenter
164
+ refute_equal user_presenter, project
165
+ refute_equal user_presenter, project_presenter
166
+ end
167
+
168
+ def test_inspect
169
+ user = User.new
170
+ presenter = present(user)
171
+
172
+ assert_equal user.inspect, presenter.inspect
173
+ end
174
+
175
+ def test_to_s
176
+ user = User.new
177
+ presenter = present(user)
178
+
179
+ assert_equal user.to_s, presenter.to_s
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ module Oprah
4
+ class RailtieTest < Minitest::Test
5
+ include Fixtures
6
+
7
+ def test_cache_invalidation
8
+ present User.new
9
+ refute_nil Presenter.cache.fetch(User.name)
10
+ Rails.application.reloader.reload!
11
+ assert_nil Presenter.cache.fetch(User.name)
12
+ end
13
+
14
+ def test_controller_helper_inclusion
15
+ assert_includes ActionController::Base, ControllerHelpers
16
+ assert_includes ActionMailer::Base, ControllerHelpers
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: detaso-oprah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Svensson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.3.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.3.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.11
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.11
139
+ description: Opinionated presenters for Rails 5 - without the cruft
140
+ email:
141
+ - tob@tobiassvensson.co.uk
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - CHANGELOG.md
149
+ - CONTRIBUTING.md
150
+ - Gemfile
151
+ - LICENSE
152
+ - README.md
153
+ - Rakefile
154
+ - lib/oprah.rb
155
+ - lib/oprah/controller_helpers.rb
156
+ - lib/oprah/presenter.rb
157
+ - lib/oprah/railtie.rb
158
+ - lib/oprah/test_helpers.rb
159
+ - lib/oprah/version.rb
160
+ - oprah.gemspec
161
+ - tasks/bundler.rb
162
+ - tasks/console.rb
163
+ - tasks/minitest.rb
164
+ - tasks/yard.rb
165
+ - test/controllers/posts_controller_test.rb
166
+ - test/dummy/app/controllers/application_controller.rb
167
+ - test/dummy/app/controllers/posts_controller.rb
168
+ - test/dummy/app/mailers/application_mailer.rb
169
+ - test/dummy/app/mailers/post_mailer.rb
170
+ - test/dummy/app/models/post.rb
171
+ - test/dummy/app/presenters/post_presenter.rb
172
+ - test/dummy/app/views/post_mailer/notification.html.erb
173
+ - test/dummy/app/views/posts/show.html.erb
174
+ - test/dummy/config/database.yml
175
+ - test/dummy/config/routes.rb
176
+ - test/dummy/init.rb
177
+ - test/dummy/tmp/.gitkeep
178
+ - test/helper.rb
179
+ - test/mailers/post_mailer_test.rb
180
+ - test/oprah/controller_helpers_test.rb
181
+ - test/oprah/oprah_test.rb
182
+ - test/oprah/presenter_test.rb
183
+ - test/oprah/railtie_test.rb
184
+ homepage: https://github.com/detaso/oprah
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.4.10
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Opinionated presenters for Rails 5 - without the cruft
207
+ test_files:
208
+ - test/controllers/posts_controller_test.rb
209
+ - test/dummy/app/controllers/application_controller.rb
210
+ - test/dummy/app/controllers/posts_controller.rb
211
+ - test/dummy/app/mailers/application_mailer.rb
212
+ - test/dummy/app/mailers/post_mailer.rb
213
+ - test/dummy/app/models/post.rb
214
+ - test/dummy/app/presenters/post_presenter.rb
215
+ - test/dummy/app/views/post_mailer/notification.html.erb
216
+ - test/dummy/app/views/posts/show.html.erb
217
+ - test/dummy/config/database.yml
218
+ - test/dummy/config/routes.rb
219
+ - test/dummy/init.rb
220
+ - test/dummy/tmp/.gitkeep
221
+ - test/helper.rb
222
+ - test/mailers/post_mailer_test.rb
223
+ - test/oprah/controller_helpers_test.rb
224
+ - test/oprah/oprah_test.rb
225
+ - test/oprah/presenter_test.rb
226
+ - test/oprah/railtie_test.rb