dom_for 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +40 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +7 -5
- data/dom_for.gemspec +3 -2
- data/lib/dom_for/model.rb +18 -15
- data/lib/dom_for/record.rb +15 -13
- data/lib/dom_for/version.rb +1 -1
- data/lib/dom_for.rb +15 -19
- data/spec/helpers/dom_for_spec.rb +80 -8
- metadata +18 -7
- data/spec/helpers/dom_for_model_spec.rb +0 -57
- data/spec/helpers/dom_for_record_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8fc0fad1bfddcb6a68a0801745603b5d4a4aed9
|
4
|
+
data.tar.gz: 6c713b8e9135fb37737a3c5dd56da9dc05b5b09a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b9ee7cb04d7c2c19328533812d64bfe486d7a687333cb43c6e52e422e15c58f445877a374b164b8b12b4d384704001cddd8ca2917b6e2ccbf271d2c26ac2b1
|
7
|
+
data.tar.gz: 001723acf36b81251b7ac16a9c266fc2c31863f449ad06a10131f1c8ec80839d9d2949cc1bdd0b843323ae1aee0d0c5cb18d4d7b95beb720f7f291f0d368dc48
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
AllCops:
|
2
|
+
# Cop names are not displayed in offense messages by default. Change behavior
|
3
|
+
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
|
4
|
+
# option.
|
5
|
+
DisplayCopNames: true
|
6
|
+
# Style guide URLs are not displayed in offense messages by default. Change
|
7
|
+
# behavior by overriding DisplayStyleGuide, or by giving the
|
8
|
+
# -S/--display-style-guide option.
|
9
|
+
DisplayStyleGuide: true
|
10
|
+
Exclude:
|
11
|
+
- 'bin/**/*'
|
12
|
+
- 'spec/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
|
15
|
+
# Missing top-level class documentation comment
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Line is too long
|
20
|
+
# https://github.com/bbatsov/ruby-style-guide#80-character-limits
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 180 # 80
|
23
|
+
|
24
|
+
# Assignment Branch Condition size for perform is too high
|
25
|
+
# http://c2.com/cgi/wiki?AbcMetric
|
26
|
+
Metrics/AbcSize:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Method has too many lines
|
30
|
+
# https://github.com/bbatsov/ruby-style-guide#short-methods
|
31
|
+
Metrics/MethodLength:
|
32
|
+
Max: 25 # 10
|
33
|
+
|
34
|
+
# Cyclomatic complexity for dom_for_model is too high
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
# Perceived complexity for dom_for_model is too high
|
39
|
+
Metrics/PerceivedComplexity:
|
40
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,11 +24,13 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
+
By default the helper `dom_for` creates tag `div`. But it can override, passing an additional argument `tag`, for example: `dom _for User, tag: :span`:
|
28
|
+
|
27
29
|
```erb
|
28
30
|
<%# /app/views/users/index.html.erb %>
|
29
31
|
<%= dom_for User, attribute_1: 'value_1', attribute_2: 'value_2', attribute_3: 'value_3' do %>
|
30
32
|
<% @users.each do |user| %>
|
31
|
-
<%= dom_for user, admin: user.admin, blocked: user.blocked do %>
|
33
|
+
<%= dom_for user, tag: :p, admin: user.admin, blocked: user.blocked do %>
|
32
34
|
<%= content_tag(:span, user.name) %>
|
33
35
|
<% end %>
|
34
36
|
<% end %>
|
@@ -37,10 +39,10 @@ Or install it yourself as:
|
|
37
39
|
|
38
40
|
```html
|
39
41
|
<div id="users" class="users" data-action="index" data-attribute-1="value_1" data-attribute-2="value_2" data-attribute-3="value_3">
|
40
|
-
<
|
42
|
+
<p id="user_1" class="user" data-admin="true" data-blocked="false" data-object-id="1">
|
41
43
|
<span>Mikhail</span>
|
42
44
|
</div>
|
43
|
-
<
|
45
|
+
<p id="user_2" class="user" data-admin="false" data-blocked="false" data-object-id="2">
|
44
46
|
<span>Yulia</span>
|
45
47
|
</div>
|
46
48
|
</div>
|
@@ -95,11 +97,11 @@ The third argument, the helper `dom_for`, takes a block of code that will be wra
|
|
95
97
|
|
96
98
|
```erb
|
97
99
|
<%# /app/views/users/index.html.erb %>
|
98
|
-
<%= dom_for User %>
|
100
|
+
<%= dom_for User, tag: :span %>
|
99
101
|
```
|
100
102
|
|
101
103
|
```html
|
102
|
-
<
|
104
|
+
<span id="users" class="users" data-action="index" />
|
103
105
|
```
|
104
106
|
|
105
107
|
When defined instance variable with class name, the helper `dom_for` creates the additional html-attributes for this object:
|
data/dom_for.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
3
|
|
4
4
|
# Maintain your gem's version:
|
5
5
|
require 'dom_for/version'
|
@@ -28,4 +28,5 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency 'rspec-rails'
|
29
29
|
s.add_development_dependency 'yard', '~> 0.8.7'
|
30
30
|
s.add_development_dependency 'redcarpet', '~> 3.0' # Markdown implementation (for yard)
|
31
|
-
|
31
|
+
s.add_development_dependency 'rubocop'
|
32
|
+
end
|
data/lib/dom_for/model.rb
CHANGED
@@ -26,32 +26,33 @@ module DomFor
|
|
26
26
|
# Creates a div tag with the attributes for the model of ActiveRecord
|
27
27
|
#
|
28
28
|
# @example Without the block:
|
29
|
-
#
|
29
|
+
# dom_for(User) #=> <div class="users" id="users" />
|
30
30
|
#
|
31
31
|
# @example When there is a request:
|
32
|
-
#
|
32
|
+
# dom_for(User) #=> <div class="users" data-action="show" id="users" />
|
33
33
|
#
|
34
34
|
# @example For the new user:
|
35
|
-
#
|
35
|
+
# dom_for(User) #=> <div class="user new_user" data-action="new" id="new_user" />
|
36
36
|
#
|
37
37
|
# @example For the saved record (if exists @user):
|
38
|
-
#
|
38
|
+
# dom_for(User) #=> <div class="user show_user" data-action="show" data-object-id="1" data-object="users" id="user_1" />
|
39
39
|
#
|
40
40
|
# @example With the additional attributes:
|
41
|
-
#
|
41
|
+
# dom_for(User, admin: true) #=> <div class="user show_user" data-action="show" data-admin="true" data-object-id="1" data-object="users" id="user_1" />
|
42
42
|
#
|
43
43
|
# @example With the block:
|
44
|
-
#
|
44
|
+
# dom_for(User, admin: true) do
|
45
45
|
# tag(:span)
|
46
46
|
# end #=> <div class="user show_user" data-action="show" data-admin="true" data-object-id="1" data-object="users" id="user_1"><span /></div>
|
47
47
|
#
|
48
|
-
# @param [Class]
|
49
|
-
# @param [
|
50
|
-
# @param [
|
48
|
+
# @param klass [Class] Model of ActiveRecord::Base
|
49
|
+
# @param tag [Symbol] HTML tag name
|
50
|
+
# @param attrs [Hash] Additional attributes for the record
|
51
|
+
# @param block [Proc] Block for a div tag
|
51
52
|
#
|
52
53
|
# @return [String] Sanitized HTML string
|
53
54
|
#
|
54
|
-
def
|
55
|
+
def _dom_for_model(klass, tag, attrs = {}, &block)
|
55
56
|
object_classes = []
|
56
57
|
class_name = klass.to_s.underscore
|
57
58
|
request_action = request.path_parameters[:action]
|
@@ -60,6 +61,7 @@ module DomFor
|
|
60
61
|
|
61
62
|
object = instance_variable_get("@#{class_name}")
|
62
63
|
|
64
|
+
# TODO: Need refactoring
|
63
65
|
object_id = if object
|
64
66
|
if object.persisted?
|
65
67
|
attrs = attrs.merge(object_id: object.id, object: class_name.pluralize)
|
@@ -76,13 +78,14 @@ module DomFor
|
|
76
78
|
end
|
77
79
|
|
78
80
|
if block_given?
|
79
|
-
content_tag(
|
81
|
+
content_tag(tag, id: object_id, class: object_classes.join(' '), data: attrs, &block)
|
80
82
|
else
|
81
|
-
tag(
|
83
|
+
tag(tag, id: object_id, class: object_classes.join(' '), data: attrs)
|
82
84
|
end
|
83
|
-
|
84
85
|
rescue
|
85
|
-
content_tag(
|
86
|
+
content_tag(tag, &block)
|
86
87
|
end
|
88
|
+
|
89
|
+
private :_dom_for_model
|
87
90
|
end
|
88
|
-
end
|
91
|
+
end
|
data/lib/dom_for/record.rb
CHANGED
@@ -11,39 +11,41 @@ module DomFor
|
|
11
11
|
# Creates a div tag with the attributes for the instance of ActiveRecord
|
12
12
|
#
|
13
13
|
# @example For the new record:
|
14
|
-
#
|
14
|
+
# dom_for(User.new) #=> <div class="user" id="new_user" />
|
15
15
|
#
|
16
16
|
# @example For the saved record:
|
17
|
-
#
|
17
|
+
# dom_for(@user) #=> <div class="user" data-object-id="1" id="user_1" />
|
18
18
|
#
|
19
19
|
# @example With the additional attributes:
|
20
|
-
#
|
20
|
+
# dom_for(@user, admin: true) #=> <div class="user" data-admin="true" data-object-id="1" id="user_1" />
|
21
21
|
#
|
22
22
|
# @example With the block:
|
23
|
-
#
|
23
|
+
# dom_for(@user, admin: true) do
|
24
24
|
# tag(:span)
|
25
25
|
# end #=> <div class="user" data-admin="true" data-object-id="1" id="user_1"><span /></div>
|
26
26
|
#
|
27
|
-
# @param [ActiveRecord::Base]
|
28
|
-
# @param [
|
29
|
-
# @param [
|
27
|
+
# @param record [ActiveRecord::Base] Instance of ActiveRecord::Base
|
28
|
+
# @param tag [Symbol] HTML tag name
|
29
|
+
# @param attrs [Hash] Additional attributes for the record
|
30
|
+
# @param block [Proc] Block for a div tag
|
30
31
|
#
|
31
32
|
# @return [String] Sanitized HTML string
|
32
33
|
#
|
33
|
-
def
|
34
|
+
def _dom_for_record(record, tag, attrs = {}, &block)
|
34
35
|
object_id = dom_id(record)
|
35
36
|
object_class = dom_class(record.class)
|
36
37
|
|
37
38
|
attrs = attrs.merge(object_id: record.id) if record.persisted?
|
38
39
|
|
39
40
|
if block_given?
|
40
|
-
content_tag(
|
41
|
+
content_tag(tag, id: object_id, class: object_class, data: attrs, &block)
|
41
42
|
else
|
42
|
-
tag(
|
43
|
+
tag(tag, id: object_id, class: object_class, data: attrs)
|
43
44
|
end
|
44
|
-
|
45
45
|
rescue
|
46
|
-
content_tag(
|
46
|
+
content_tag(tag, &block)
|
47
47
|
end
|
48
|
+
|
49
|
+
private :_dom_for_record
|
48
50
|
end
|
49
|
-
end
|
51
|
+
end
|
data/lib/dom_for/version.rb
CHANGED
data/lib/dom_for.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
require 'active_support/dependencies/autoload'
|
2
1
|
require 'active_support/core_ext/object/blank'
|
3
2
|
require 'active_support/core_ext/string/inflections'
|
4
3
|
|
4
|
+
require_relative 'dom_for/model'
|
5
|
+
require_relative 'dom_for/record'
|
6
|
+
|
5
7
|
module DomFor
|
8
|
+
include Model
|
9
|
+
include Record
|
6
10
|
#
|
7
11
|
# dom_for Project do
|
8
12
|
#
|
@@ -15,31 +19,23 @@ module DomFor
|
|
15
19
|
# dom_for Comment do
|
16
20
|
# dom_for comment, private: true
|
17
21
|
#
|
18
|
-
|
19
|
-
|
20
|
-
autoload :Model
|
21
|
-
autoload :Record
|
22
|
-
|
23
|
-
include Model
|
24
|
-
include Record
|
25
|
-
|
26
|
-
#
|
27
|
-
# Creates a div tag with the attributes for the model or record of ActiveRecord
|
22
|
+
# Creates a html tag with the attributes for the model or record of ActiveRecord
|
28
23
|
#
|
29
|
-
# @param [ActiveRecord::Base, Class]
|
30
|
-
# @param [Hash]
|
31
|
-
# @param [Proc]
|
24
|
+
# @param object [ActiveRecord::Base, Class] Model or record of ActiveRecord
|
25
|
+
# @param attrs [Hash] Additional attributes for the record
|
26
|
+
# @param block [Proc] Block for a div tag
|
32
27
|
#
|
33
28
|
# @return [String] Sanitized HTML string
|
34
29
|
#
|
35
|
-
def dom_for(object, attrs={}, &block)
|
30
|
+
def dom_for(object, attrs = {}, &block)
|
31
|
+
tag = attrs.delete(:tag) || :div
|
32
|
+
|
36
33
|
if object.instance_of? Class
|
37
|
-
|
34
|
+
_dom_for_model(object, tag, attrs, &block)
|
38
35
|
else
|
39
|
-
|
36
|
+
_dom_for_record(object, tag, attrs, &block)
|
40
37
|
end
|
41
38
|
end
|
42
|
-
|
43
39
|
end
|
44
40
|
|
45
|
-
require_relative 'dom_for/railtie' if defined? Rails
|
41
|
+
require_relative 'dom_for/railtie' if defined? ::Rails
|
@@ -1,21 +1,93 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe DomFor do
|
4
|
-
|
5
4
|
it 'includes in ActiveView::Base' do
|
6
5
|
expect(ActionView::Base.ancestors).to include(DomFor)
|
7
|
-
expect(ActionView::Base.ancestors).to include(DomFor::Model)
|
8
|
-
expect(ActionView::Base.ancestors).to include(DomFor::Record)
|
9
6
|
end
|
10
7
|
|
11
8
|
context '#dom_for' do
|
12
|
-
it '
|
13
|
-
expect(helper.dom_for(User)).to eq '<
|
9
|
+
it 'returns span tag' do
|
10
|
+
expect(helper.dom_for(User, tag: :span)).to eq '<span id="users" class="users" />'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with model' do
|
14
|
+
it 'returns div without nested tags' do
|
15
|
+
expect(helper.dom_for(User)).to eq '<div id="users" class="users" />'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns div with data-action attribute' do
|
19
|
+
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
20
|
+
|
21
|
+
expect(helper.dom_for(User)).to eq '<div id="users" class="users" data-action="show" />'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns div for the new user' do
|
25
|
+
@user = User.new(name: 'test')
|
26
|
+
expect(helper.request).to receive(:path_parameters).and_return({ action: 'new' })
|
27
|
+
|
28
|
+
expect(helper.dom_for(User)).to eq '<div id="new_user" class="user new_user" data-action="new" />'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns div for the new user without request' do
|
32
|
+
@user = User.new(name: 'test')
|
33
|
+
|
34
|
+
expect(helper.dom_for(User)).to eq '<div id="new_user" class="user" />'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns div for the saved user' do
|
38
|
+
@user = User.create(name: 'test')
|
39
|
+
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
40
|
+
|
41
|
+
expect(
|
42
|
+
helper.dom_for(User)
|
43
|
+
).to eq '<div id="user_1" class="user show_user" data-action="show" data-object-id="1" data-object="users" />'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns div with the additional data-attributes' do
|
47
|
+
@user = User.create(name: 'test')
|
48
|
+
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
49
|
+
|
50
|
+
expect(
|
51
|
+
helper.dom_for(User, admin: true)
|
52
|
+
).to eq '<div id="user_1" class="user show_user" data-admin="true" data-action="show" data-object-id="1" data-object="users" />'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns div with nested tags' do
|
56
|
+
@user = User.create(name: 'test')
|
57
|
+
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
58
|
+
|
59
|
+
expect(
|
60
|
+
helper.dom_for(User, admin: true) { helper.tag(:span) }
|
61
|
+
).to eq '<div id="user_1" class="user show_user" data-admin="true" data-action="show" data-object-id="1" data-object="users"><span /></div>'
|
62
|
+
end
|
14
63
|
end
|
15
64
|
|
16
|
-
|
17
|
-
|
65
|
+
context 'with record' do
|
66
|
+
it 'returns div for the new user' do
|
67
|
+
expect(helper.dom_for(User.new)).to eq '<div id="new_user" class="user" />'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns div without nested tags' do
|
71
|
+
user = User.create(name: 'test')
|
72
|
+
|
73
|
+
expect(helper.dom_for(user)).to eq '<div id="user_1" class="user" data-object-id="1" />'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns div with nested tags' do
|
77
|
+
user = User.create(name: 'test')
|
78
|
+
|
79
|
+
expect(
|
80
|
+
helper.dom_for(user) { helper.tag(:span) }
|
81
|
+
).to eq '<div id="user_1" class="user" data-object-id="1"><span /></div>'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns div with the additional data-attributes' do
|
85
|
+
user = User.create(name: 'test')
|
86
|
+
|
87
|
+
expect(
|
88
|
+
helper.dom_for(user, admin: true) { helper.tag(:span) }
|
89
|
+
).to eq '<div id="user_1" class="user" data-admin="true" data-object-id="1"><span /></div>'
|
90
|
+
end
|
18
91
|
end
|
19
92
|
end
|
20
|
-
|
21
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dom_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Grachev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Helper for easy creation of HTML wrapper ActiveRecord objects.
|
84
98
|
email:
|
85
99
|
- work@mgrachev.com
|
@@ -88,6 +102,7 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
91
106
|
- ".ruby-version"
|
92
107
|
- ".travis.yml"
|
93
108
|
- ".yardopts"
|
@@ -153,8 +168,6 @@ files:
|
|
153
168
|
- spec/dummy/public/422.html
|
154
169
|
- spec/dummy/public/500.html
|
155
170
|
- spec/dummy/public/favicon.ico
|
156
|
-
- spec/helpers/dom_for_model_spec.rb
|
157
|
-
- spec/helpers/dom_for_record_spec.rb
|
158
171
|
- spec/helpers/dom_for_spec.rb
|
159
172
|
- spec/rails_helper.rb
|
160
173
|
- spec/spec_helper.rb
|
@@ -178,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
191
|
version: '0'
|
179
192
|
requirements: []
|
180
193
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.4.7
|
182
195
|
signing_key:
|
183
196
|
specification_version: 4
|
184
197
|
summary: Helper for creating HTML wrappers ActiveRecord objects.
|
@@ -234,8 +247,6 @@ test_files:
|
|
234
247
|
- spec/dummy/public/422.html
|
235
248
|
- spec/dummy/public/500.html
|
236
249
|
- spec/dummy/public/favicon.ico
|
237
|
-
- spec/helpers/dom_for_model_spec.rb
|
238
|
-
- spec/helpers/dom_for_record_spec.rb
|
239
250
|
- spec/helpers/dom_for_spec.rb
|
240
251
|
- spec/rails_helper.rb
|
241
252
|
- spec/spec_helper.rb
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe DomFor::Model do
|
4
|
-
|
5
|
-
context '#dom_for_model' do
|
6
|
-
it 'returns empty div' do
|
7
|
-
expect(helper.dom_for_model(User.new)).to eq '<div></div>'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns div without nested tags' do
|
11
|
-
expect(helper.dom_for_model(User)).to eq '<div id="users" class="users" />'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns div with data-action attribute' do
|
15
|
-
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
16
|
-
|
17
|
-
expect(helper.dom_for_model(User)).to eq '<div id="users" class="users" data-action="show" />'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns div for the new user' do
|
21
|
-
@user = User.new(name: 'test')
|
22
|
-
expect(helper.request).to receive(:path_parameters).and_return({ action: 'new' })
|
23
|
-
|
24
|
-
expect(helper.dom_for_model(User)).to eq '<div id="new_user" class="user new_user" data-action="new" />'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns div for the new user without request' do
|
28
|
-
@user = User.new(name: 'test')
|
29
|
-
|
30
|
-
expect(helper.dom_for_model(User)).to eq '<div id="new_user" class="user" />'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'returns div for the saved user' do
|
34
|
-
@user = User.create(name: 'test')
|
35
|
-
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
36
|
-
|
37
|
-
expect(helper.dom_for_model(User)).to eq '<div id="user_1" class="user show_user" data-action="show" data-object-id="1" data-object="users" />'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns div with the additional data-attributes' do
|
41
|
-
@user = User.create(name: 'test')
|
42
|
-
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
43
|
-
|
44
|
-
expect(helper.dom_for_model(User, admin: true)).to eq '<div id="user_1" class="user show_user" data-admin="true" data-action="show" data-object-id="1" data-object="users" />'
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns div with nested tags' do
|
48
|
-
@user = User.create(name: 'test')
|
49
|
-
expect(helper.request).to receive(:path_parameters).and_return({ action: 'show' })
|
50
|
-
|
51
|
-
expect(
|
52
|
-
helper.dom_for_model(User, admin: true) { helper.tag(:span) }
|
53
|
-
).to eq '<div id="user_1" class="user show_user" data-admin="true" data-action="show" data-object-id="1" data-object="users"><span /></div>'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe DomFor::Record do
|
4
|
-
|
5
|
-
context '#dom_for_record' do
|
6
|
-
it 'returns empty div' do
|
7
|
-
expect(helper.dom_for_record(User)).to eq '<div></div>'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns div for the new user' do
|
11
|
-
expect(helper.dom_for_record(User.new)).to eq '<div id="new_user" class="user" />'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns div without nested tags' do
|
15
|
-
user = User.create(name: 'test')
|
16
|
-
|
17
|
-
expect(helper.dom_for_record(user)).to eq '<div id="user_1" class="user" data-object-id="1" />'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns div with nested tags' do
|
21
|
-
user = User.create(name: 'test')
|
22
|
-
|
23
|
-
expect(
|
24
|
-
helper.dom_for_record(user) { helper.tag(:span) }
|
25
|
-
).to eq '<div id="user_1" class="user" data-object-id="1"><span /></div>'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns div with the additional data-attributes' do
|
29
|
-
user = User.create(name: 'test')
|
30
|
-
|
31
|
-
expect(
|
32
|
-
helper.dom_for_record(user, admin: true) { helper.tag(:span) }
|
33
|
-
).to eq '<div id="user_1" class="user" data-admin="true" data-object-id="1"><span /></div>'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|