show_for 0.8.0 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f887e097d4512d2b054ca7dde3017a18c4389d6fe376a254518474fb266e99da
4
- data.tar.gz: 6f1be23083f6459f303f87a5060d3ae7494c15d9754db16d0a2565aa1ef595d3
3
+ metadata.gz: 0c8de9d2240c250f8dd8846d1bc53c3b372eaeffb1710ec6b4b16fd23c9afe3a
4
+ data.tar.gz: bdd646396d9c3dc0fa4cd553bc25c90e7e650277e2db944d35448ba4f8fec369
5
5
  SHA512:
6
- metadata.gz: 73ca01b5978117f4b942f7784cb8da9d7b3651ab1ad3c8b6995864fd057e7af172e17f7035d24467fdc1171bb00385a9314b26b71abdfe9d6cf5d05a1d50bcb4
7
- data.tar.gz: b122b66cdc14e4db341337e37b1f23726354580448e3e311c4d3ba49b54d06bb4bd448a3edec6a29aaad5274999ec5f021268dd25c0120591eef9c0d15f68f76
6
+ metadata.gz: c1cef95848285f3d701b8f6cd7c91b472c8aae487fb5fa342909d07cd0366a42ce2af27ff4ea4261868339c8de91dfbadc2683f561a06d69448cbe086e9f8568
7
+ data.tar.gz: 4a31e66d11690af071f8ddda98ce40cf7177a278e6b3a6d12d72f1f920c2ad81ade5f029c49f767eab147dde0cd43f54ab7d867781192d7d6f2819efe22024b6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.8.1
2
+
3
+ * Add support for Rails 7.0/7.1 and Ruby 3.1/3.2 (no changes required)
4
+ * Remove test files from the gem package.
5
+
1
6
  ## 0.8.0
2
7
 
3
8
  * Respect `nil` value when provided, by skipping model attribute value.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2012-2019 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2020-2023 Rafael França, Carlos Antônio da Silva
2
+ Copyright (c) 2012-2019 Plataformatec
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # ShowFor
2
2
 
3
3
  [![Gem Version](https://fury-badge.herokuapp.com/rb/show_for.png)](http://badge.fury.io/rb/show_for)
4
- [![Code Climate](https://codeclimate.com/github/heartcombo/show_for.png)](https://codeclimate.com/github/heartcombo/show_for)
5
4
 
6
5
  ShowFor allows you to quickly show a model information with I18n features.
7
6
 
@@ -228,4 +227,6 @@ If you discover any bugs or want to drop a line, feel free to create an issue on
228
227
 
229
228
  http://github.com/heartcombo/show_for/issues
230
229
 
231
- MIT License. Copyright 2012-2019 Plataformatec. http://plataformatec.com.br
230
+ ## License
231
+
232
+ MIT License. Copyright 2020-2023 Rafael França, Carlos Antônio da Silva. Copyright 2012-2019 Plataformatec.
@@ -1,3 +1,3 @@
1
1
  module ShowFor
2
- VERSION = "0.8.0".freeze
2
+ VERSION = "0.8.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -62,21 +62,14 @@ files:
62
62
  - lib/show_for/helper.rb
63
63
  - lib/show_for/label.rb
64
64
  - lib/show_for/version.rb
65
- - test/association_test.rb
66
- - test/attribute_test.rb
67
- - test/builder_test.rb
68
- - test/content_test.rb
69
- - test/generators/show_for_generator_test.rb
70
- - test/helper_test.rb
71
- - test/label_test.rb
72
- - test/support/misc_helpers.rb
73
- - test/support/models.rb
74
- - test/test_helper.rb
75
- - test/value_test.rb
76
65
  homepage: http://github.com/plataformatec/show_for
77
66
  licenses:
78
67
  - MIT
79
- metadata: {}
68
+ metadata:
69
+ homepage_uri: https://github.com/heartcombo/show_for
70
+ changelog_uri: https://github.com/heartcombo/show_for/blob/main/CHANGELOG.md
71
+ source_code_uri: https://github.com/heartcombo/show_for
72
+ bug_tracker_uri: https://github.com/heartcombo/show_for/issues
80
73
  post_install_message:
81
74
  rdoc_options: []
82
75
  require_paths:
@@ -92,19 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
85
  - !ruby/object:Gem::Version
93
86
  version: '0'
94
87
  requirements: []
95
- rubygems_version: 3.0.3
88
+ rubygems_version: 3.4.10
96
89
  signing_key:
97
90
  specification_version: 4
98
91
  summary: Wrap your objects with a helper to easily show them
99
- test_files:
100
- - test/builder_test.rb
101
- - test/attribute_test.rb
102
- - test/value_test.rb
103
- - test/support/misc_helpers.rb
104
- - test/support/models.rb
105
- - test/label_test.rb
106
- - test/test_helper.rb
107
- - test/helper_test.rb
108
- - test/association_test.rb
109
- - test/generators/show_for_generator_test.rb
110
- - test/content_test.rb
92
+ test_files: []
@@ -1,152 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AssociationTest < ActionView::TestCase
4
- test "show_for works with belongs_to/has_one associations" do
5
- with_association_for @user, :company
6
- assert_select "div.show_for div.wrapper", /Plataformatec/
7
- end
8
-
9
- test "show_for accepts :using as option to tell how to retrieve association value" do
10
- with_association_for @user, :company, using: :alternate_name
11
- assert_select "div.show_for div.wrapper", /Alternate Plataformatec/
12
- end
13
-
14
- test "show_for accepts :in to tell to retrieve an attribute from association" do
15
- with_attribute_for @user, :alternate_name, in: :company
16
- assert_select "div.show_for div.wrapper", /Alternate Plataformatec/
17
- end
18
-
19
- test "show_for forwards all options send with :in to association" do
20
- with_attribute_for @user, :alternate_name, in: :tags, to_sentence: true
21
- assert_no_select "div.show_for div.wrapper ul.collection"
22
- assert_select "div.show_for div.wrapper", /Alternate Tag 1, Alternate Tag 2, and Alternate Tag 3/
23
- end
24
-
25
- test "show_for works with has_many/has_and_belongs_to_many associations" do
26
- with_association_for @user, :tags
27
- assert_select "div.show_for div.wrapper ul.collection"
28
- assert_select "div.show_for div.wrapper ul.collection li", "Tag 1"
29
- assert_select "div.show_for div.wrapper ul.collection li", "Tag 2"
30
- assert_select "div.show_for div.wrapper ul.collection li", "Tag 3"
31
- end
32
-
33
- test "show_for works with has_many/has_and_belongs_to_many blank associations" do
34
- def @user.tags
35
- []
36
- end
37
-
38
- swap ShowFor, association_methods: [:name] do
39
- with_association_for @user, :tags
40
- assert_no_select "div.show_for div.wrapper ul.collection"
41
- assert_no_select "div.show_for div.wrapper", /Enumerator/
42
- end
43
- end
44
-
45
- test "show_for accepts a block with has_many/has_and_belongs_to_many blank associations" do
46
- def @user.tags
47
- []
48
- end
49
-
50
- swap ShowFor, association_methods: [:name] do
51
- with_association_for @user, :tags do |tag|
52
- tag.name
53
- end
54
- assert_no_select "div.show_for div.wrapper ul.collection"
55
- assert_no_select "div.show_for div.wrapper", /Enumerator/
56
- end
57
- end
58
-
59
- test "show_for uses :if_blank when has_many/has_and_belongs_to_many association is blank" do
60
- def @user.tags
61
- []
62
- end
63
-
64
- with_association_for @user, :tags, if_blank: 'No tags' do |tag|
65
- tag.name
66
- end
67
- assert_select "div.show_for div.wrapper.blank", /No tags/
68
- assert_no_select "div.show_for div.wrapper ul.collection"
69
- assert_no_select "div.show_for div.wrapper", /Enumerator/
70
- end
71
-
72
- test "show_for uses :if_blank if given a block when has_many/has_and_belongs_to_many association is blank" do
73
- def @user.tags
74
- []
75
- end
76
-
77
- with_association_for @user, :tags, if_blank: 'No tags'
78
- assert_select "div.show_for div.wrapper.blank", /No tags/
79
- assert_no_select "div.show_for div.wrapper ul.collection"
80
- assert_no_select "div.show_for div.wrapper", /Enumerator/
81
- end
82
-
83
- test "show_for accepts a block with an argument in belongs_to associations" do
84
- with_association_for @user, :company do |company|
85
- company.name.upcase
86
- end
87
-
88
- assert_select "div.show_for div.wrapper", /PLATAFORMATEC/
89
- end
90
-
91
- test "show_for accepts :using as option to tell how to retrieve association values" do
92
- with_association_for @user, :tags, using: :alternate_name
93
- assert_select "div.show_for div.wrapper ul.collection"
94
- assert_select "div.show_for div.wrapper ul.collection li", "Alternate Tag 1"
95
- assert_select "div.show_for div.wrapper ul.collection li", "Alternate Tag 2"
96
- assert_select "div.show_for div.wrapper ul.collection li", "Alternate Tag 3"
97
- end
98
-
99
- test "show_for accepts :to_sentence as option in collection associations" do
100
- with_association_for @user, :tags, to_sentence: true
101
- assert_no_select "div.show_for div.wrapper ul.collection"
102
- assert_select "div.show_for div.wrapper", /Tag 1, Tag 2, and Tag 3/
103
- end
104
-
105
- test "show_for accepts :join as option in collection associations" do
106
- with_association_for @user, :tags, join: ", "
107
- assert_no_select "div.show_for div.wrapper ul.collection"
108
- assert_select "div.show_for div.wrapper", /Tag 1, Tag 2, Tag 3/
109
- end
110
-
111
- test "show_for accepts a block without argument in collection associations" do
112
- with_association_for @user, :tags do
113
- @user.tags.map(&:name).to_sentence
114
- end
115
- assert_no_select "div.show_for div.wrapper ul.collection"
116
- assert_select "div.show_for div.wrapper", /Tag 1, Tag 2, and Tag 3/
117
- end
118
-
119
- test "show_for accepts a block with argument in collection associations" do
120
- with_association_for @user, :tags, collection_tag: :p do |tag|
121
- assert_kind_of Tag, tag
122
- content_tag(:span, tag.name)
123
- end
124
- assert_no_select "div.show_for div.wrapper ul.collection"
125
- assert_select "div.show_for div.wrapper p.collection"
126
- assert_select "div.show_for div.wrapper p.collection span", "Tag 1"
127
- assert_select "div.show_for div.wrapper p.collection span", "Tag 2"
128
- assert_select "div.show_for div.wrapper p.collection span", "Tag 3"
129
- end
130
-
131
- test "show_for does not display empty has_many/has_and_belongs_to_many association if skip_blanks option is passed" do
132
- def @user.tags
133
- []
134
- end
135
-
136
- swap ShowFor, skip_blanks: true do
137
- with_association_for @user, :tags
138
- assert_no_select "div.show_for div.wrapper"
139
- end
140
- end
141
-
142
- test "show_for does not display empty belongs_to/has_one association if skip_blanks option is passed" do
143
- def @user.company
144
- nil
145
- end
146
-
147
- swap ShowFor, skip_blanks: true do
148
- with_association_for @user, :company
149
- assert_no_select "div.show_for div.wrapper"
150
- end
151
- end
152
- end
@@ -1,238 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AttributeTest < ActionView::TestCase
4
- # COLLECTIONS
5
- test "show_for accepts an attribute as a collection" do
6
- with_attribute_for @user, :scopes
7
- assert_select "div.show_for div.wrapper ul.collection"
8
- assert_select "div.show_for div.wrapper ul.collection li", count: 3
9
- end
10
-
11
- test "show_for accepts an attribute as a collection with a block to iterate the collection" do
12
- with_attribute_for @user, :scopes do |scope|
13
- content_tag :span, scope
14
- end
15
- assert_select "div.show_for div.wrapper ul.collection"
16
- assert_select "div.show_for div.wrapper ul.collection span", count: 3
17
- end
18
-
19
- test "show_for treats symbol for :value as method on each element of collection" do
20
- with_attribute_for @user, :scopes, value: :upcase
21
- @user.scopes.each do |scope|
22
- assert_select "div.show_for div.wrapper ul.collection", /#{scope.upcase}/
23
- end
24
- end
25
-
26
- test "show_for allows collection tag to be configured globally" do
27
- swap ShowFor, collection_tag: :ol, collection_class: "my_collection" do
28
- with_attribute_for @user, :scopes
29
- assert_select "div.show_for div.wrapper ol.my_collection"
30
- end
31
- end
32
-
33
- test "show_for allows collection class to be disabled globally" do
34
- swap ShowFor, collection_tag: :ol, collection_class: nil do
35
- with_attribute_for @user, :scopes
36
- assert_select "div.show_for div.wrapper ol"
37
- assert_no_select "ol[class]"
38
- end
39
- end
40
-
41
- test "show_for allows collection tag to be changed by attribute" do
42
- with_attribute_for @user, :scopes, collection_tag: :ol
43
- assert_select "div.show_for div.wrapper ol.collection"
44
- end
45
-
46
- test "show_for allows collection tag html to be configured by attribute" do
47
- with_attribute_for @user, :scopes, collection_html: { id: "thecollection", class: "special" }
48
- assert_select "div.show_for div.wrapper ul#thecollection.special.collection"
49
- end
50
-
51
- # CONTENT
52
- test "show_for allows content tag to be configured globally" do
53
- swap ShowFor, content_tag: :span, content_class: :my_content do
54
- with_attribute_for @user, :name
55
- assert_select "div.show_for div.wrapper span.my_content"
56
- end
57
- end
58
-
59
- test "show_for allows content class to be disabled globally" do
60
- swap ShowFor, content_tag: :span, content_class: nil do
61
- with_attribute_for @user, :name
62
- assert_select "div.show_for div.wrapper span"
63
- assert_no_select "span[class]"
64
- end
65
- end
66
-
67
- test "show_for allows content tag to be changed by attribute" do
68
- with_attribute_for @user, :name, content_tag: :span
69
- assert_select "div.show_for div.wrapper span.content"
70
- end
71
-
72
- test "show_for allows content tag html to be configured by attribute" do
73
- with_attribute_for @user, :name, content_tag: :span, content_html: { id: "thecontent", class: "special" }
74
- assert_select "div.show_for div.wrapper span#thecontent.special.content"
75
- end
76
-
77
- test "show_for accepts an attribute as string" do
78
- with_attribute_for @user, :name
79
- assert_select "div.show_for div.wrapper", /ShowFor/
80
- end
81
-
82
- test "show_for accepts an attribute as time" do
83
- with_attribute_for @user, :created_at
84
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.created_at))}/
85
- end
86
-
87
- test "show_for accepts an attribute as date" do
88
- with_attribute_for @user, :updated_at
89
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.updated_at))}/
90
- end
91
-
92
- test "show_for accepts an attribute as time with format options" do
93
- with_attribute_for @user, :created_at, format: :long
94
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.created_at, format: :long))}/
95
- end
96
-
97
- test "show_for accepts an attribute as true" do
98
- with_attribute_for @user, :active
99
- assert_select "div.show_for div.wrapper", /Yes/
100
- end
101
-
102
- test "show_for accepts an attribute as true which can be localized" do
103
- store_translations(:en, show_for: { yes: "Hell yeah!" }) do
104
- with_attribute_for @user, :active
105
- assert_select "div.show_for div.wrapper", /Hell yeah!/
106
- end
107
- end
108
-
109
- test "show_for accepts an attribute as false" do
110
- with_attribute_for @user, :invalid
111
- assert_select "div.show_for div.wrapper", /No/
112
- end
113
-
114
- test "show_for accepts an attribute as false which can be localized" do
115
- store_translations(:en, show_for: { no: "Hell no!" }) do
116
- with_attribute_for @user, :invalid
117
- assert_select "div.show_for div.wrapper", /Hell no!/
118
- end
119
- end
120
-
121
- test "show_for accepts nil and or blank attributes" do
122
- with_attribute_for @user, :description
123
- assert_select "div.show_for div.wrapper", /Not specified/
124
- end
125
-
126
- test "show_for accepts not spcified message can be localized" do
127
- store_translations(:en, show_for: { blank: "OMG! It's blank!" }) do
128
- with_attribute_for @user, :description
129
- assert_select "div.show_for div.wrapper", /OMG! It's blank!/
130
- end
131
- end
132
-
133
- test "show_for accepts not spcified message can be localized with html" do
134
- store_translations(:en, show_for: { blank_html: "<span>OMG! It's blank!</span>" }) do
135
- with_attribute_for @user, :description
136
- assert_select "div.show_for div.wrapper span", "OMG! It's blank!"
137
- end
138
- end
139
-
140
- test "show_for uses :if_blank if attribute is blank" do
141
- with_attribute_for @user, :description, if_blank: "No description provided"
142
- assert_select "div.show_for div.wrapper", /No description provided/
143
- end
144
-
145
- test "show_for accepts a block to supply the content" do
146
- with_attribute_for @user, :description do
147
- "This description is not blank"
148
- end
149
- assert_select "div.show_for div.wrapper", /This description/
150
- end
151
-
152
- test "show_for uses :if_blank if the block content is blank" do
153
- with_attribute_for @user, :description, if_blank: "No description provided" do
154
- ""
155
- end
156
- assert_select "div.show_for div.wrapper", /No description provided/
157
- end
158
-
159
- test "show_for#content given a block should be wrapped in the result" do
160
- with_attribute_for @user, :name do |name|
161
- "<div class='block'>#{name}</div>".html_safe
162
- end
163
- assert_select "div.wrapper.user_name div.block", /ShowFor/
164
- end
165
-
166
- test "show_for escapes content by default" do
167
- @user.name = "<b>hack you!</b>"
168
- with_attribute_for @user, :name
169
- assert_no_select "div.show_for div.wrapper b"
170
- assert_select "div.show_for div.wrapper", "Super User Name!<b>hack you!</b>"
171
- end
172
-
173
- test "show_for works with html_safe marked strings" do
174
- @user.name = "<b>hack you!</b>".html_safe
175
- with_attribute_for @user, :name
176
- assert_select "div.show_for div.wrapper b", "hack you!"
177
- end
178
-
179
- test "show_for uses :value if supplied" do
180
- with_attribute_for @user, :name, value: "Calculated Value"
181
- assert_select "div.show_for div.wrapper", /Calculated Value/
182
- end
183
-
184
- test "show_for uses :value and casts to string if supplied" do
185
- with_attribute_for @user, :name, value: 123
186
- assert_select "div.show_for div.wrapper", /123/
187
- end
188
-
189
- test "show_for ignores attribute if :value supplied but with nil value" do
190
- with_attribute_for @user, :name, value: nil
191
- assert_select "div.show_for div.wrapper", /Not specified/
192
- end
193
-
194
- test "show_for ignores :value if a block is supplied" do
195
- with_attribute_for @user, :name, value: "Calculated Value" do
196
- @user.name.upcase
197
- end
198
- assert_select "div.show_for div.wrapper", /#{@user.name.upcase}/
199
- end
200
-
201
- test "show_for treats symbol for :value as method on attribute" do
202
- with_attribute_for @user, :name, value: :upcase
203
- assert_select "div.show_for div.wrapper", /#{@user.name.upcase}/
204
- end
205
-
206
- test "show_for does not display blank attribute if skip_blanks option is passed" do
207
- swap ShowFor, skip_blanks: true do
208
- with_attribute_for @user, :description
209
- assert_no_select "div.show_for div.wrapper"
210
- end
211
- end
212
-
213
- test "show_for display false attribute if skip_blanks option is passed" do
214
- swap ShowFor, skip_blanks: true do
215
- with_attribute_for @user, :invalid
216
- assert_select "div.show_for div.wrapper", /No/
217
- end
218
- end
219
-
220
- # ATTRIBUTES
221
- test "show_for attributes wraps each attribute with a label and content" do
222
- with_attributes_for @user, :name, :email
223
- assert_select "div.show_for div.user_name.wrapper", /ShowFor/
224
- assert_select "div.user_name strong.label", "Super User Name!"
225
- assert_select "div.show_for div.user_email.wrapper", /Not specified/
226
- assert_select "div.user_email strong.label", "Email"
227
- end
228
-
229
- test "show_for should wrap blank attributes with no_attribute" do
230
- swap ShowFor, blank_content_class: 'no_attribute' do
231
- with_attributes_for @user, :name, :birthday, :karma
232
- assert_select ".wrapper.user_birthday.no_attribute"
233
- assert_select ".wrapper.user_karma.no_attribute"
234
- assert_select ".wrapper.user_name.no_attribute", false
235
- end
236
- end
237
-
238
- end
data/test/builder_test.rb DELETED
@@ -1,81 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BuilderTest < ActionView::TestCase
4
- # WRAPPER
5
- test "show_for allows wrapper to be configured globally" do
6
- swap ShowFor, wrapper_tag: "li", wrapper_class: "my_wrapper" do
7
- with_attribute_for @user, :name
8
- assert_select "div.show_for li.user_name.my_wrapper"
9
- assert_select "div.show_for li.my_wrapper strong.label"
10
- assert_select "div.show_for li.my_wrapper"
11
- end
12
- end
13
-
14
- test "show_for allows wrapper class to be disabled globally" do
15
- swap ShowFor, wrapper_tag: "li", wrapper_class: nil do
16
- with_attribute_for @user, :name
17
- assert_select "div.show_for li[class='user_name']"
18
- end
19
- end
20
-
21
- test "show_for attribute wraps each attribute with a label and content" do
22
- with_attribute_for @user, :name
23
- assert_select "div.show_for div.user_name.wrapper"
24
- assert_select "div.show_for div.wrapper strong.label"
25
- assert_select "div.show_for div.wrapper"
26
- end
27
-
28
- test "show_for properly deals with namespaced models" do
29
- @user = Namespaced::User.new(id: 1, name: "ShowFor")
30
-
31
- with_attribute_for @user, :name
32
- assert_select "div.show_for div.namespaced_user_name.wrapper"
33
- assert_select "div.show_for div.wrapper strong.label"
34
- assert_select "div.show_for div.wrapper"
35
- end
36
-
37
- test "show_for allows wrapper tag to be changed by attribute" do
38
- with_attribute_for @user, :name, wrapper_tag: :span
39
- assert_select "div.show_for span.user_name.wrapper"
40
- end
41
-
42
- test "show_for allows wrapper html to be configured by attribute" do
43
- with_attribute_for @user, :name, wrapper_html: { id: "thewrapper", class: "special" }
44
- assert_select "div.show_for div#thewrapper.user_name.wrapper.special"
45
- end
46
-
47
- # SEPARATOR
48
- test "show_for allows separator to be configured globally" do
49
- swap ShowFor, separator: '<span class="separator"></span>' do
50
- with_attribute_for @user, :name
51
- assert_select "div.show_for div.user_name span.separator"
52
- assert_select "div.show_for div.wrapper span.separator"
53
- assert_no_select "div.show_for br"
54
- end
55
- end
56
-
57
- test "show_for allows separator to be changed by attribute"do
58
- with_attribute_for @user, :name, separator: '<span class="separator"></span>'
59
- assert_select "div.show_for div.wrapper span.separator"
60
- assert_no_select "div.show_for br"
61
- end
62
-
63
- test "show_for allows disabling separator by attribute" do
64
- with_attribute_for @user, :name, separator: false
65
- assert_no_select "div.show_for div.wrapper span.separator"
66
- assert_no_select "div.show_for div.wrapper br"
67
- assert_no_select "div.show_for div.wrapper", /false/
68
- end
69
-
70
- test "show_for uses a separator if requested" do
71
- with_attribute_for @user, :name
72
- assert_select "div.show_for div.wrapper br"
73
- end
74
-
75
- test "show_for does not blow if a separator is not set" do
76
- swap ShowFor, separator: nil do
77
- with_attribute_for @user, :name
78
- assert_select "div.show_for div.wrapper"
79
- end
80
- end
81
- end
data/test/content_test.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ContentTest < ActionView::TestCase
4
- test "show_for#content accepts any object" do
5
- with_content_for @user, "Special content"
6
- assert_select "div.show_for", "Special content"
7
- end
8
-
9
- test "show_for#content accepts :if_blank as option" do
10
- with_content_for @user, "", if_blank: "Got blank"
11
- assert_select "div.show_for", "Got blank"
12
- end
13
-
14
- test "show_for#content accepts html options" do
15
- with_content_for @user, "Special content", content_tag: :b, id: "thecontent", class: "special"
16
- assert_select "div.show_for b#thecontent.special.content", "Special content"
17
- assert_no_select "div.show_for b[content_tag]"
18
- end
19
-
20
- test "show_for#content with blank value has a 'no value'-class" do
21
- swap ShowFor, blank_content_class: "nothing" do
22
- with_content_for @user, nil, content_tag: :b
23
- assert_select "div.show_for b.nothing"
24
- end
25
- end
26
-
27
- test "show_for#content with blank value does not display content if skip_blanks option is passed" do
28
- swap ShowFor, skip_blanks: true do
29
- with_content_for @user, nil, content_tag: :b
30
- assert_no_select "div.show_for b"
31
- end
32
- end
33
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ShowForGeneratorTest < Rails::Generators::TestCase
4
- tests ShowFor::Generators::InstallGenerator
5
- destination File.expand_path('../../tmp', __FILE__)
6
- setup :prepare_destination
7
- teardown { rm_rf(destination_root) }
8
-
9
- test 'generates example locale file' do
10
- run_generator
11
- assert_file 'config/locales/show_for.en.yml'
12
- end
13
-
14
- test 'generates the show_for initializer' do
15
- run_generator
16
- assert_file 'config/initializers/show_for.rb',
17
- /config.show_for_tag = :div/
18
- end
19
-
20
- %W(erb haml slim).each do |engine|
21
- test "generates the scaffold template when using #{engine}" do
22
- run_generator ['-e', engine]
23
- assert_file "lib/templates/#{engine}/scaffold/show.html.#{engine}"
24
- end
25
- end
26
- end
data/test/helper_test.rb DELETED
@@ -1,54 +0,0 @@
1
- require "test_helper"
2
-
3
- class CustomBuilder < ShowFor::Builder
4
- end
5
-
6
- class HelperTest < ActionView::TestCase
7
- test "show for yields an instance of ShowFor::Builder" do
8
- show_for(@user) do |f|
9
- assert f.instance_of?(ShowFor::Builder)
10
- end
11
- end
12
-
13
- test "show for yields an instance of builder class specified by builder option" do
14
- show_for(@user, builder: CustomBuilder) do |f|
15
- assert f.instance_of?(CustomBuilder)
16
- end
17
- end
18
-
19
- test "show for should add default class to form" do
20
- concat(show_for(@user) do |f| end)
21
- assert_select "div.show_for"
22
- end
23
-
24
- test "show for should add object class name as css class to form" do
25
- concat(show_for(@user) do |f| end)
26
- assert_select "div.show_for.user"
27
- end
28
-
29
- test "show for should pass options" do
30
- concat(show_for(@user, id: "my_div", class: "common") do |f| end)
31
- assert_select "div#my_div.show_for.user.common"
32
- end
33
-
34
- test "show for tag should be configurable" do
35
- swap ShowFor, show_for_tag: :p do
36
- concat(show_for(@user) do |f| end)
37
- assert_select "p.show_for"
38
- end
39
- end
40
-
41
- test "show for class should be configurable" do
42
- swap ShowFor, show_for_class: :awesome do
43
- concat(show_for(@user) do |f| end)
44
- assert_select "div.show_for.user.awesome"
45
- end
46
- end
47
-
48
- test "show for options hash should not be modified" do
49
- html_options = { show_for_tag: :li }
50
- concat(show_for(@user, html_options) do |f| end)
51
- assert_equal({ show_for_tag: :li }, html_options)
52
- end
53
-
54
- end
data/test/label_test.rb DELETED
@@ -1,78 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LabelTest < ActionView::TestCase
4
- test "show_for shows a label using the humanized attribute name from model" do
5
- with_attribute_for @user, :name
6
- assert_select "div.show_for div.wrapper strong.label", "Super User Name!"
7
- end
8
-
9
- test "show_for skips label if requested" do
10
- with_attribute_for @user, :name, label: false
11
- assert_no_select "div.show_for div.wrapper strong.label"
12
- assert_no_select "div.show_for div.wrapper br"
13
- end
14
-
15
- test "show_for uses custom content_tag and skips label if requested" do
16
- with_attribute_for @user, :name, label: false, content_tag: :h2
17
- assert_select "div.show_for div.wrapper h2.content", "ShowFor"
18
- end
19
-
20
- test "show_for allows label to be configured globally" do
21
- swap ShowFor, label_tag: :span, label_class: "my_label" do
22
- with_attribute_for @user, :name
23
- assert_select "div.show_for div.wrapper span.my_label"
24
- end
25
- end
26
-
27
- test "show_for allows label class to be disabled globally" do
28
- swap ShowFor, label_tag: :span, label_class: nil do
29
- with_attribute_for @user, :name
30
- assert_select "div.show_for div.wrapper span"
31
- assert_no_select "span[class]"
32
- end
33
- end
34
-
35
- test "show_for allows label to be changed by attribute" do
36
- with_attribute_for @user, :name, label_tag: :span
37
- assert_select "div.show_for div.wrapper span.label"
38
- end
39
-
40
- test "show_for allows label html to be configured by attribute" do
41
- with_attribute_for @user, :name, label_html: { id: "thelabel", class: "special" }
42
- assert_select "div.show_for div.wrapper strong#thelabel.special.label"
43
- end
44
-
45
- test "show_for allows label to be set without lookup" do
46
- with_attribute_for @user, :name, label: "Special Label"
47
- assert_select "div.show_for div.wrapper strong.label", "Special Label"
48
- end
49
-
50
- test "show_for#label accepts the text" do
51
- with_label_for @user, "Special Label"
52
- assert_select "div.show_for strong.label", "Special Label"
53
- end
54
-
55
- test "show_for#label accepts an attribute name" do
56
- with_label_for @user, :name
57
- assert_select "div.show_for strong.label", "Super User Name!"
58
- end
59
-
60
- test "show_for#label accepts html options" do
61
- with_label_for @user, :name, id: "thelabel", class: "special"
62
- assert_select "div.show_for strong#thelabel.special.label"
63
- end
64
-
65
- test "should let you override the label wrapper" do
66
- swap ShowFor, label_proc: proc { |l| l + ":" } do
67
- with_label_for @user, "Special Label"
68
- assert_select "div.show_for strong.label", "Special Label:"
69
- end
70
- end
71
-
72
- test "should you skip wrapping the label on a per item basis" do
73
- swap ShowFor, label_proc: proc { |l| l + ":" } do
74
- with_label_for @user, "Special Label", wrap_label: false
75
- assert_select "div.show_for strong.label", "Special Label"
76
- end
77
- end
78
- end
@@ -1,63 +0,0 @@
1
- module MiscHelpers
2
- def store_translations(locale, translations, &block)
3
- begin
4
- I18n.backend.store_translations locale, translations
5
- yield
6
- ensure
7
- I18n.reload!
8
- end
9
- end
10
-
11
- def assert_no_select(selector, value = nil)
12
- assert_select(selector, text: value, count: 0)
13
- end
14
-
15
- def swap(object, new_values)
16
- old_values = {}
17
- new_values.each do |key, value|
18
- old_values[key] = object.send key
19
- object.send :"#{key}=", value
20
- end
21
- yield
22
- ensure
23
- old_values.each do |key, value|
24
- object.send :"#{key}=", value
25
- end
26
- end
27
-
28
- def with_attribute_for(object, attribute, options = {}, &block)
29
- concat(show_for(object) do |o|
30
- concat o.attribute(attribute, options, &block)
31
- end)
32
- end
33
-
34
- def with_value_for(object, attribute, options = {}, &block)
35
- concat(show_for(object) do |o|
36
- concat o.value(attribute, options, &block)
37
- end)
38
- end
39
-
40
- def with_association_for(object, association, options = {}, &block)
41
- concat(show_for(object) do |o|
42
- concat o.association(association, options, &block)
43
- end)
44
- end
45
-
46
- def with_label_for(object, attribute, options = {})
47
- concat(show_for(object) do |o|
48
- concat o.label(attribute, options)
49
- end)
50
- end
51
-
52
- def with_content_for(object, value, options = {})
53
- concat(show_for(object) do |o|
54
- concat o.content(value, options)
55
- end)
56
- end
57
-
58
- def with_attributes_for(object, *attributes)
59
- concat(show_for(object) do |o|
60
- concat o.attributes(*attributes)
61
- end)
62
- end
63
- end
@@ -1,57 +0,0 @@
1
- require 'ostruct'
2
-
3
- Company = Struct.new(:id, :name) do
4
- extend ActiveModel::Naming
5
-
6
- def alternate_name
7
- "Alternate #{self.name}"
8
- end
9
- end
10
-
11
-
12
- Tag = Struct.new(:id, :name) do
13
- extend ActiveModel::Naming
14
-
15
- def self.all(options = {})
16
- (1..3).map{ |i| Tag.new(i, "Tag #{i}") }
17
- end
18
-
19
- def alternate_name
20
- "Alternate #{self.name}"
21
- end
22
- end
23
-
24
- class User < OpenStruct
25
- extend ActiveModel::Naming
26
-
27
- # Get rid of deprecation warnings
28
- undef_method :id if respond_to?(:id)
29
-
30
- def tags
31
- Tag.all
32
- end
33
-
34
- def company
35
- Company.new(1, "Plataformatec")
36
- end
37
-
38
- def self.human_attribute_name(attribute)
39
- case attribute
40
- when 'name'
41
- 'Super User Name!'
42
- when 'company'
43
- 'Company Human Name!'
44
- else
45
- attribute.humanize
46
- end
47
- end
48
-
49
- def self.human_name
50
- "User"
51
- end
52
- end
53
-
54
- module Namespaced
55
- class User < ::User
56
- end
57
- end
data/test/test_helper.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- require 'minitest/autorun'
4
-
5
- require 'active_model'
6
- require 'action_controller'
7
- require 'action_view'
8
- require 'action_view/template'
9
- require 'action_view/test_case'
10
-
11
- require "rails/generators/test_case"
12
- require 'generators/show_for/install_generator'
13
-
14
- $:.unshift File.expand_path("../../lib", __FILE__)
15
- require 'show_for'
16
-
17
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
18
- I18n.enforce_available_locales = true
19
- I18n.default_locale = :en
20
-
21
- ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)
22
-
23
- class ActionView::TestCase
24
- include MiscHelpers
25
- include ShowFor::Helper
26
-
27
- setup :setup_new_user
28
-
29
- def setup_new_user(options = {})
30
- @user = User.new({
31
- id: 1,
32
- name: 'ShowFor',
33
- description: '',
34
- active: true,
35
- invalid: false,
36
- scopes: ["admin", "manager", "visitor"],
37
- birthday: nil,
38
- karma: Proc.new { nil },
39
- created_at: Time.now,
40
- updated_at: Date.today
41
- }.merge(options))
42
- end
43
- end
data/test/value_test.rb DELETED
@@ -1,89 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ValueTest < ActionView::TestCase
4
- test "show_for allows content tag to be configured globally, without label and separator" do
5
- swap ShowFor, content_tag: :span do
6
- with_value_for @user, :name
7
- assert_no_select "div.show_for div.wrapper strong.label"
8
- assert_no_select "div.show_for div.wrapper br"
9
- assert_select "div.show_for div.wrapper span.content"
10
- end
11
- end
12
-
13
- test "show_for allows content with tag to be changed by attribute, without label and separator" do
14
- with_value_for @user, :name, content_tag: :span
15
- assert_no_select "div.show_for div.wrapper strong.label"
16
- assert_no_select "div.show_for div.wrapper br"
17
- assert_select "div.show_for div.wrapper span.content"
18
- end
19
-
20
- test "show_for allows content tag html to be configured by attribute, without label and separator" do
21
- with_value_for @user, :name, content_tag: :span, content_html: { id: "thecontent", class: "special" }
22
- assert_no_select "div.show_for div.wrapper strong.label"
23
- assert_no_select "div.show_for div.wrapper br"
24
- assert_select "div.show_for div.wrapper span#thecontent.special.content"
25
- end
26
-
27
- test "show_for accepts an attribute as string, without label and separator" do
28
- with_value_for @user, :name
29
- assert_no_select "div.show_for div.wrapper strong.label"
30
- assert_no_select "div.show_for div.wrapper br"
31
- assert_select "div.show_for div.wrapper", /ShowFor/
32
- end
33
-
34
- test "show_for accepts an attribute as time, without label and separator" do
35
- with_value_for @user, :created_at
36
- assert_no_select "div.show_for div.wrapper strong.label"
37
- assert_no_select "div.show_for div.wrapper br"
38
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.created_at))}/
39
- end
40
-
41
- test "show_for accepts an attribute as date, without label and separator" do
42
- with_value_for @user, :updated_at
43
- assert_no_select "div.show_for div.wrapper strong.label"
44
- assert_no_select "div.show_for div.wrapper br"
45
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.updated_at))}/
46
- end
47
-
48
- test "show_for accepts an attribute as time with format options, without label and separator" do
49
- with_value_for @user, :created_at, format: :long
50
- assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.created_at, format: :long))}/
51
- end
52
-
53
- test "show_for accepts an attribute as nil, without label and separator" do
54
- with_value_for @user, :birthday
55
- assert_no_select "div.show_for div.wrapper strong.label"
56
- assert_no_select "div.show_for div.wrapper br"
57
- assert_select "div.show_for div.wrapper", /Not specified/
58
- end
59
-
60
- test "show_for accepts blank attributes, without label and separator" do
61
- with_value_for @user, :description
62
- assert_no_select "div.show_for div.wrapper strong.label"
63
- assert_no_select "div.show_for div.wrapper br"
64
- assert_select "div.show_for div.wrapper", /Not specified/
65
- end
66
-
67
- test "show_for uses :if_blank if attribute is nil, without label and separator" do
68
- with_value_for @user, :birthday, if_blank: "No description provided"
69
- assert_no_select "div.show_for div.wrapper strong.label"
70
- assert_no_select "div.show_for div.wrapper br"
71
- assert_select "div.show_for div.wrapper", /No description provided/
72
- end
73
-
74
- test "show_for uses :if_blank if attribute is blank, without label and separator" do
75
- with_value_for @user, :description, if_blank: "No description provided"
76
- assert_no_select "div.show_for div.wrapper strong.label"
77
- assert_no_select "div.show_for div.wrapper br"
78
- assert_select "div.show_for div.wrapper", /No description provided/
79
- end
80
-
81
- test "show_for escapes content by default, without label and separator" do
82
- @user.name = "<b>hack you!</b>"
83
- with_value_for @user, :name
84
- assert_no_select "div.show_for div.wrapper strong.label"
85
- assert_no_select "div.show_for div.wrapper br"
86
- assert_no_select "div.show_for div.wrapper b"
87
- assert_select "div.show_for div.wrapper", "<b>hack you!</b>"
88
- end
89
- end