show_for 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,18 +13,18 @@ class BuilderTest < ActionView::TestCase
13
13
 
14
14
  test "show_for attribute wraps each attribute with a label and content" do
15
15
  with_attribute_for @user, :name
16
- assert_select "div.show_for p.user_name.wrapper"
17
- assert_select "div.show_for p.wrapper strong.label"
18
- assert_select "div.show_for p.wrapper"
16
+ assert_select "div.show_for div.user_name.wrapper"
17
+ assert_select "div.show_for div.wrapper strong.label"
18
+ assert_select "div.show_for div.wrapper"
19
19
  end
20
20
 
21
21
  test "show_for properly deals with namespaced models" do
22
22
  @user = Namespaced::User.new(:id => 1, :name => "ShowFor")
23
23
 
24
24
  with_attribute_for @user, :name
25
- assert_select "div.show_for p.namespaced_user_name.wrapper"
26
- assert_select "div.show_for p.wrapper strong.label"
27
- assert_select "div.show_for p.wrapper"
25
+ assert_select "div.show_for div.namespaced_user_name.wrapper"
26
+ assert_select "div.show_for div.wrapper strong.label"
27
+ assert_select "div.show_for div.wrapper"
28
28
  end
29
29
 
30
30
  test "show_for allows wrapper tag to be changed by attribute" do
@@ -34,19 +34,41 @@ class BuilderTest < ActionView::TestCase
34
34
 
35
35
  test "show_for allows wrapper html to be configured by attribute" do
36
36
  with_attribute_for @user, :name, :wrapper_html => { :id => "thewrapper", :class => "special" }
37
- assert_select "div.show_for p#thewrapper.user_name.wrapper.special"
37
+ assert_select "div.show_for div#thewrapper.user_name.wrapper.special"
38
38
  end
39
39
 
40
40
  # SEPARATOR
41
+ test "show_for allows separator to be configured globally" do
42
+ swap ShowFor, :separator => '<span class="separator"></span>' do
43
+ with_attribute_for @user, :name
44
+ assert_select "div.show_for div.user_name span.separator"
45
+ assert_select "div.show_for div.wrapper span.separator"
46
+ assert_no_select "div.show_for br"
47
+ end
48
+ end
49
+
50
+ test "show_for allows separator to be changed by attribute"do
51
+ with_attribute_for @user, :name, :separator => '<span class="separator"></span>'
52
+ assert_select "div.show_for div.wrapper span.separator"
53
+ assert_no_select "div.show_for br"
54
+ end
55
+
56
+ test "show_for allows disabling separator by attribute" do
57
+ with_attribute_for @user, :name, :separator => false
58
+ assert_no_select "div.show_for div.wrapper span.separator"
59
+ assert_no_select "div.show_for div.wrapper br"
60
+ assert_no_select "div.show_for div.wrapper", /false/
61
+ end
62
+
41
63
  test "show_for uses a separator if requested" do
42
64
  with_attribute_for @user, :name
43
- assert_select "div.show_for p.wrapper br"
65
+ assert_select "div.show_for div.wrapper br"
44
66
  end
45
67
 
46
68
  test "show_for does not blow if a separator is not set" do
47
69
  swap ShowFor, :separator => nil do
48
70
  with_attribute_for @user, :name
49
- assert_select "div.show_for p.wrapper"
71
+ assert_select "div.show_for div.wrapper"
50
72
  end
51
73
  end
52
74
  end
@@ -23,4 +23,11 @@ class ContentTest < ActionView::TestCase
23
23
  assert_select "div.show_for b.nothing"
24
24
  end
25
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
26
33
  end
@@ -17,7 +17,7 @@ class ShowForGeneratorTest < Rails::Generators::TestCase
17
17
  /config.show_for_tag = :div/
18
18
  end
19
19
 
20
- %W(erb haml).each do |engine|
20
+ %W(erb haml slim).each do |engine|
21
21
  test "generates the scaffold template when using #{engine}" do
22
22
  run_generator ['-e', engine]
23
23
  assert_file "lib/templates/#{engine}/scaffold/show.html.#{engine}"
@@ -3,40 +3,40 @@ require 'test_helper'
3
3
  class LabelTest < ActionView::TestCase
4
4
  test "show_for shows a label using the humanized attribute name from model" do
5
5
  with_attribute_for @user, :name
6
- assert_select "div.show_for p.wrapper strong.label", "Super User Name!"
6
+ assert_select "div.show_for div.wrapper strong.label", "Super User Name!"
7
7
  end
8
8
 
9
9
  test "show_for skips label if requested" do
10
10
  with_attribute_for @user, :name, :label => false
11
- assert_no_select "div.show_for p.wrapper strong.label"
12
- assert_no_select "div.show_for p.wrapper br"
11
+ assert_no_select "div.show_for div.wrapper strong.label"
12
+ assert_no_select "div.show_for div.wrapper br"
13
13
  end
14
14
 
15
15
  test "show_for uses custom content_tag and skips label if requested" do
16
16
  with_attribute_for @user, :name, :label => false, :content_tag => :h2
17
- assert_select "div.show_for p.wrapper h2.content", "ShowFor"
17
+ assert_select "div.show_for div.wrapper h2.content", "ShowFor"
18
18
  end
19
19
 
20
20
  test "show_for allows label to be configured globally" do
21
21
  swap ShowFor, :label_tag => :span, :label_class => "my_label" do
22
22
  with_attribute_for @user, :name
23
- assert_select "div.show_for p.wrapper span.my_label"
23
+ assert_select "div.show_for div.wrapper span.my_label"
24
24
  end
25
25
  end
26
26
 
27
27
  test "show_for allows label to be changed by attribute" do
28
28
  with_attribute_for @user, :name, :label_tag => :span
29
- assert_select "div.show_for p.wrapper span.label"
29
+ assert_select "div.show_for div.wrapper span.label"
30
30
  end
31
31
 
32
32
  test "show_for allows label html to be configured by attribute" do
33
33
  with_attribute_for @user, :name, :label_html => { :id => "thelabel", :class => "special" }
34
- assert_select "div.show_for p.wrapper strong#thelabel.special.label"
34
+ assert_select "div.show_for div.wrapper strong#thelabel.special.label"
35
35
  end
36
36
 
37
37
  test "show_for allows label to be set without lookup" do
38
38
  with_attribute_for @user, :name, :label => "Special Label"
39
- assert_select "div.show_for p.wrapper strong.label", "Special Label"
39
+ assert_select "div.show_for div.wrapper strong.label", "Special Label"
40
40
  end
41
41
 
42
42
  test "show_for#label accepts the text" do
@@ -38,10 +38,10 @@ module MiscHelpers
38
38
  end
39
39
 
40
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
41
+ concat(show_for(object) do |o|
42
+ concat o.association(association, options, &block)
43
+ end)
44
+ end
45
45
 
46
46
  def with_label_for(object, attribute, options={})
47
47
  concat(show_for(object) do |o|
@@ -1,6 +1,6 @@
1
1
  require 'ostruct'
2
2
 
3
- class Company < Struct.new(:id, :name)
3
+ Company = Struct.new(:id, :name) do
4
4
  extend ActiveModel::Naming
5
5
 
6
6
  def alternate_name
@@ -8,7 +8,8 @@ class Company < Struct.new(:id, :name)
8
8
  end
9
9
  end
10
10
 
11
- class Tag < Struct.new(:id, :name)
11
+
12
+ Tag = Struct.new(:id, :name) do
12
13
  extend ActiveModel::Naming
13
14
 
14
15
  def self.all(options={})
@@ -31,7 +32,7 @@ class User < OpenStruct
31
32
  end
32
33
 
33
34
  def company
34
- Company.new(1, "PlataformaTec")
35
+ Company.new(1, "Plataformatec")
35
36
  end
36
37
 
37
38
  def self.human_attribute_name(attribute)
@@ -1,6 +1,6 @@
1
1
  require 'bundler/setup'
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
 
5
5
  require 'active_model'
6
6
  require 'action_controller'
@@ -18,6 +18,8 @@ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
18
18
  I18n.enforce_available_locales = true
19
19
  I18n.default_locale = :en
20
20
 
21
+ ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)
22
+
21
23
  class ActionView::TestCase
22
24
  include MiscHelpers
23
25
  include ShowFor::Helper
@@ -37,4 +39,9 @@ class ActionView::TestCase
37
39
  :updated_at => Date.today
38
40
  }.merge(options))
39
41
  end
42
+
43
+ # TODO: remove after supporting Rails 4.2+ only.
44
+ def rails_42?
45
+ ActiveModel::VERSION::STRING >= "4.2.0"
46
+ end
40
47
  end
@@ -4,86 +4,87 @@ class ValueTest < ActionView::TestCase
4
4
  test "show_for allows content tag to be configured globally, without label and separator" do
5
5
  swap ShowFor, :content_tag => :span do
6
6
  with_value_for @user, :name
7
- assert_no_select "div.show_for p.wrapper strong.label"
8
- assert_no_select "div.show_for p.wrapper br"
9
- assert_select "div.show_for p.wrapper span.content"
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
10
  end
11
11
  end
12
12
 
13
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 => :p
15
- assert_no_select "div.show_for p.wrapper strong.label"
16
- assert_no_select "div.show_for p.wrapper br"
17
- assert_select "div.show_for p.wrapper p.content"
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
18
  end
19
19
 
20
20
  test "show_for allows content tag html to be configured by attribute, without label and separator" do
21
21
  with_value_for @user, :name, :content_tag => :span, :content_html => { :id => "thecontent", :class => "special" }
22
- assert_no_select "div.show_for p.wrapper strong.label"
23
- assert_no_select "div.show_for p.wrapper br"
24
- assert_select "div.show_for p.wrapper span#thecontent.special.content"
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
25
  end
26
26
 
27
27
  test "show_for accepts an attribute as string, without label and separator" do
28
28
  with_value_for @user, :name
29
- assert_no_select "div.show_for p.wrapper strong.label"
30
- assert_no_select "div.show_for p.wrapper br"
31
- assert_select "div.show_for p.wrapper", /ShowFor/
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
32
  end
33
33
 
34
34
  test "show_for accepts an attribute as time, without label and separator" do
35
35
  with_value_for @user, :created_at
36
- assert_no_select "div.show_for p.wrapper strong.label"
37
- assert_no_select "div.show_for p.wrapper br"
38
- assert_select "div.show_for p.wrapper", /#{Regexp.escape(I18n.l(@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
39
  end
40
40
 
41
41
  test "show_for accepts an attribute as date, without label and separator" do
42
42
  with_value_for @user, :updated_at
43
- assert_no_select "div.show_for p.wrapper strong.label"
44
- assert_no_select "div.show_for p.wrapper br"
45
- assert_select "div.show_for p.wrapper", /#{Regexp.escape(I18n.l(@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
46
  end
47
47
 
48
48
  test "show_for accepts an attribute as time with format options, without label and separator" do
49
49
  with_value_for @user, :created_at, :format => :long
50
- assert_select "div.show_for p.wrapper", /#{Regexp.escape(I18n.l(@user.created_at, :format => :long))}/
50
+ assert_select "div.show_for div.wrapper", /#{Regexp.escape(I18n.l(@user.created_at, :format => :long))}/
51
51
  end
52
52
 
53
53
  test "show_for accepts an attribute as nil, without label and separator" do
54
54
  c = with_value_for @user, :birthday
55
- assert_no_select "div.show_for p.wrapper strong.label"
56
- assert_no_select "div.show_for p.wrapper br"
57
- assert_select "div.show_for p.wrapper", /Not specified/
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
58
  end
59
59
 
60
60
  test "show_for accepts blank attributes, without label and separator" do
61
61
  with_value_for @user, :description
62
- assert_no_select "div.show_for p.wrapper strong.label"
63
- assert_no_select "div.show_for p.wrapper br"
64
- assert_select "div.show_for p.wrapper", /Not specified/
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
65
  end
66
66
 
67
67
  test "show_for uses :if_blank if attribute is nil, without label and separator" do
68
68
  with_value_for @user, :birthday, :if_blank => "No description provided"
69
- assert_no_select "div.show_for p.wrapper strong.label"
70
- assert_no_select "div.show_for p.wrapper br"
71
- assert_select "div.show_for p.wrapper", /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
72
  end
73
73
 
74
74
  test "show_for uses :if_blank if attribute is blank, without label and separator" do
75
75
  with_value_for @user, :description, :if_blank => "No description provided"
76
- assert_no_select "div.show_for p.wrapper strong.label"
77
- assert_no_select "div.show_for p.wrapper br"
78
- assert_select "div.show_for p.wrapper", /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
79
  end
80
80
 
81
81
  test "show_for escapes content by default, without label and separator" do
82
82
  @user.name = "<b>hack you!</b>"
83
83
  with_value_for @user, :name
84
- assert_no_select "div.show_for p.wrapper strong.label"
85
- assert_no_select "div.show_for p.wrapper br"
86
- assert_no_select "div.show_for p.wrapper b"
87
- assert_select "div.show_for p.wrapper", /&lt;b&gt;/
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",
88
+ rails_42? ? "<b>hack you!</b>" : "&lt;b&gt;hack you!&lt;/b&gt;"
88
89
  end
89
90
  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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -56,13 +56,15 @@ executables: []
56
56
  extensions: []
57
57
  extra_rdoc_files: []
58
58
  files:
59
- - CHANGELOG.rdoc
59
+ - CHANGELOG.md
60
60
  - MIT-LICENSE
61
+ - README.md
61
62
  - lib/generators/show_for/USAGE
62
63
  - lib/generators/show_for/install_generator.rb
63
64
  - lib/generators/show_for/templates/en.yml
64
65
  - lib/generators/show_for/templates/show.html.erb
65
66
  - lib/generators/show_for/templates/show.html.haml
67
+ - lib/generators/show_for/templates/show.html.slim
66
68
  - lib/generators/show_for/templates/show_for.rb
67
69
  - lib/show_for.rb
68
70
  - lib/show_for/association.rb
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
104
  version: '0'
103
105
  requirements: []
104
106
  rubyforge_project: show_for
105
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.5
106
108
  signing_key:
107
109
  specification_version: 4
108
110
  summary: Wrap your objects with a helper to easily show them
@@ -1,100 +0,0 @@
1
- == 0.3.0
2
-
3
- * bug fix
4
- * Fix blank value not being applied when using a block. (by github.com/tfwright)
5
-
6
- == 0.3.0.rc
7
-
8
- * enhancements
9
- * Support Rails 4.
10
- * Drop support to Rails < 3.2 and Ruby 1.8.
11
-
12
- == 0.2.6
13
-
14
- * enhancements
15
- * Ruby 2.0 support.
16
- * Add Haml template. (by github.com/nashby) Closes #12.
17
- * Add `blank_html` tanslation. (by github.com/nashby)
18
- * Add `show_for_class` configuration option. (by github.com/nashby)
19
-
20
- * bug fix
21
- * Make show_for works with namespaced models. (by github.com/fabiokr)
22
- * Add `blank_content_class` to the attributes. (by github.com/blakehilscher). Closes #24.
23
- * Don't call `association.map` if association method is nil (by github.com/nashby). Closes #40.
24
-
25
- == 0.2.5
26
-
27
- * enhancements
28
- * Add a :value option for attribute (by github.com/ml-gt)
29
- * Add label_class, content_class, wrapper_class and content_class configuration options (by github.com/wojtekmach)
30
-
31
- * bug fix
32
- * Fix problem with label => false and html_safe (label => false) (by github.com/nashby)
33
-
34
- == 0.2.4
35
-
36
- * enhancements
37
- * Do not add separator if label is not present (by github.com/eugenebolshakov)
38
- * Add method for output value only (by github.com/jenkek)
39
-
40
- * bug fix
41
- * Fix empty labels to be html_safe (label => false) (by github.com/eugenebolshakov)
42
-
43
- == 0.2.3
44
-
45
- * enhancements
46
- * added :attributes method to generate all attributes given
47
- * update generator to use the new syntax show_for:install
48
-
49
- * bug fix
50
- * fix numeric types
51
-
52
- == 0.2.2
53
-
54
- * bug fix
55
- * allow show_for to work with AR association proxies
56
-
57
- * enhancements
58
- * improvements on html safe and output buffers
59
-
60
- == 0.2.1
61
-
62
- * enhancements
63
- * added label_proc
64
- * compatibility with latest Rails
65
-
66
- == 0.2.0
67
-
68
- * enhancements
69
- * Rails 3 compatibility
70
-
71
- == 0.1.4
72
-
73
- * bug fix
74
- * allow show_for to work with AR association proxies
75
-
76
- == 0.1.3
77
-
78
- * enhancements
79
- * allow builder to be given to show_for
80
-
81
- * bugfix
82
- * Fix typo in yaml
83
-
84
- == 0.1.2
85
-
86
- * enhancements
87
- * allow f.attribute :nickname, :in => :profile as association shortcut
88
-
89
- * deprecations
90
- * :method now becomes :using
91
-
92
- == 0.1.1
93
-
94
- * enhancements
95
- * HAML compatibility (by github.com/grimen)
96
- * blank_content support (by github.com/grimen)
97
-
98
- == 0.1
99
-
100
- * First release