rad_core 0.0.30 → 0.2.0
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.
- data/Rakefile +1 -0
- data/lib/rad/gems.rb +18 -14
- data/lib/rad/spec/controller.rb +1 -1
- data/lib/rad/spec/http_controller.rb +1 -1
- data/lib/rad/spec/mailer.rb +1 -1
- data/lib/rad/spec.rb +2 -0
- data/spec/html/form_helper_spec.rb +7 -5
- data/spec/html/model_helper_spec.rb +63 -61
- data/spec/html/spec_helper.rb +0 -1
- data/spec/web/view_routing_helper_spec.rb +73 -69
- metadata +1 -2
- data/lib/rad/spec/xhtml.rb +0 -33
data/Rakefile
CHANGED
data/lib/rad/gems.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
|
-
# core gems dependencies
|
2
|
-
# gem 'i18n', '0.5.0'
|
3
|
-
# gem 'polyglot', '0.3.1'
|
4
|
-
# gem 'treetop', '1.4.9'
|
5
|
-
# gem 'mime-types', '1.16'
|
6
|
-
|
7
|
-
# core gems
|
8
1
|
gem 'activesupport', '3.0.7'
|
9
|
-
# gem 'builder', '2.1.2'
|
10
|
-
|
11
2
|
gem 'haml', '3.0.25'
|
12
3
|
gem 'tilt', '1.2.1'
|
13
|
-
|
14
4
|
gem 'json', '1.4.6'
|
15
5
|
gem 'addressable', '2.2.2'
|
16
|
-
# gem 'nokogiri', '1.4.4'
|
17
|
-
|
18
6
|
gem 'rack', '1.3.0'
|
19
7
|
gem 'thin', '1.2.7'
|
20
|
-
|
21
8
|
gem 'mail', '2.2.14'
|
22
9
|
|
23
10
|
if respond_to? :fake_gem
|
@@ -25,4 +12,21 @@ if respond_to? :fake_gem
|
|
25
12
|
fake_gem 'vfs'
|
26
13
|
fake_gem 'micon'
|
27
14
|
fake_gem 'class_loader'
|
28
|
-
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Gems for specs
|
19
|
+
#
|
20
|
+
# gem 'nokogiri', '1.4.4'
|
21
|
+
|
22
|
+
|
23
|
+
#
|
24
|
+
# Old stuff
|
25
|
+
#
|
26
|
+
# core gems dependencies
|
27
|
+
# gem 'i18n', '0.5.0'
|
28
|
+
# gem 'polyglot', '0.3.1'
|
29
|
+
# gem 'treetop', '1.4.9'
|
30
|
+
# gem 'mime-types', '1.16'
|
31
|
+
# gem 'builder', '2.1.2'
|
32
|
+
#
|
data/lib/rad/spec/controller.rb
CHANGED
data/lib/rad/spec/mailer.rb
CHANGED
data/lib/rad/spec.rb
CHANGED
@@ -21,11 +21,13 @@ describe "FormHelper" do
|
|
21
21
|
@t.file_field_tag('item').should == %(<input class=" file_input" name="item" type="file"></input>)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
id: 'the_form', action: '/', content: 'content', method: 'post'
|
28
|
-
|
24
|
+
if String.method_defined? :to_xhtml
|
25
|
+
it "form_tag" do
|
26
|
+
@t.form_tag(id: 'the_form', action: '/'){"content"}
|
27
|
+
@t.buffer.to_xhtml('#the_form').to_fuzzy_hash.should == {id: 'the_form', action: '/', content: 'content', method: 'post'}
|
28
|
+
end
|
29
|
+
else
|
30
|
+
warn "WARN: skipping spec"
|
29
31
|
end
|
30
32
|
|
31
33
|
it "hidden_field_tag" do
|
@@ -9,76 +9,78 @@ describe "ModelHelper" do
|
|
9
9
|
@t = MockModelHelperContext.new
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
id: 'the_form', action: '/', content: 'content', method: 'post'
|
16
|
-
|
17
|
-
end
|
12
|
+
if String.method_defined? :to_xhtml
|
13
|
+
it "form_for" do
|
14
|
+
@t.form_for(:aname, nil, id: 'the_form', action: '/'){"content"}
|
15
|
+
@t.buffer.to_xhtml('#the_form').to_fuzzy_hash.should == {id: 'the_form', action: '/', content: 'content', method: 'post'}
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
it "error_messages" do
|
19
|
+
@t.form_for(:aname, nil){|f| f.error_messages}
|
20
|
+
lambda{@t.buffer.to_xhtml('form div')}.should raise_error(/not found/)
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
model = {errors: {base: ['some error']}}
|
23
|
+
@t.buffer = ""
|
24
|
+
@t.form_for(:book, model){|f| f.error_messages}
|
25
|
+
@t.buffer.to_xhtml('form div').to_fuzzy_hash.should == {class: 'error_messages', content: 'some error'}
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
it "field error" do
|
29
|
+
model = {
|
30
|
+
title: "Super Hero",
|
31
|
+
errors: {title: ['some error in title']}
|
32
|
+
}
|
33
|
+
@t.form_for(:book, model){|f| f.text_field(:title)}
|
34
|
+
doc = @t.buffer.to_xhtml
|
35
|
+
doc.css("form div.field_error_messages").first.content.should == "some error in title"
|
36
|
+
doc.css("form span.field_with_errors input").first.to_fuzzy_hash.should == {name: "book[title]", value: "Super Hero"}
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
it "should insert human readable label if not specified" do
|
40
|
+
model = {}
|
41
|
+
model.stub(:t).and_return{|k| "translated #{k}"}
|
43
42
|
|
44
|
-
|
45
|
-
|
43
|
+
@t.form_for(:book, model){|f| f.text_field(:title)}
|
44
|
+
@t.buffer.should =~ /translated title/
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
@t.form_for(:book, model){|f| f.text_field(:title, label: 'some label')}
|
47
|
+
@t.buffer.should =~ /some label/
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
it "field_helpers" do
|
51
|
+
model = {
|
52
|
+
available: false,
|
53
|
+
title: "Super Hero",
|
54
|
+
theme: 'simple'
|
55
|
+
}
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
@t.form_for(:book, model){|f| %{
|
58
|
+
#{f.check_box :available}
|
59
|
+
#{f.file_field :title}
|
60
|
+
#{f.hidden_field :title}
|
61
|
+
#{f.password_field :title}
|
62
|
+
#{f.radio_button :available}
|
63
|
+
#{f.submit 'Ok'}
|
64
|
+
#{f.text_field :title}
|
65
|
+
#{f.text_area :title}
|
66
|
+
#{f.select :theme, %w(a b)}
|
67
|
+
} }
|
68
|
+
doc = @t.buffer.to_xhtml
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
# checkbox is special case, we are using it with <input type='hidden' .../> tag.
|
71
|
+
doc.css("*[type='hidden']").first.to_fuzzy_hash.should == {name: "book[available]", value: '0'}
|
72
|
+
doc.css("*[type='checkbox']").first.to_fuzzy_hash.should == {name: "book[available]", value: '1'}
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
doc.css("*[type='file']").first.to_fuzzy_hash.should == {name: "book[title]"}
|
75
|
+
doc.css("*[type='hidden']").last.to_fuzzy_hash.should == {name: "book[title]", value: 'Super Hero'}
|
76
|
+
doc.css("*[type='password']").first.to_fuzzy_hash.should == {name: "book[title]"}
|
77
|
+
doc.css("*[type='radio']").first.to_fuzzy_hash.should == {name: "book[available]", value: '1'}
|
78
|
+
doc.css("*[type='submit']").first.to_fuzzy_hash.should == {value: 'Ok'}
|
79
|
+
doc.css("*[type='text']").first.to_fuzzy_hash.should == {name: "book[title]", value: 'Super Hero'}
|
80
|
+
doc.css("textarea").first.to_fuzzy_hash.should == {name: "book[title]", content: 'Super Hero'}
|
81
|
+
doc.css("select").first.to_fuzzy_hash.should == {name: "book[theme]"}
|
82
|
+
end
|
83
|
+
else
|
84
|
+
warn "WARN: skipping spec"
|
83
85
|
end
|
84
86
|
end
|
data/spec/html/spec_helper.rb
CHANGED
@@ -54,89 +54,93 @@ describe "UrlHelper" do
|
|
54
54
|
@t = MockUrlHelperContext.new
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
if String.method_defined? :to_xhtml
|
58
|
+
describe "link_to" do
|
59
|
+
it "should works with url_for attributes" do
|
60
|
+
@t.link_to('Book', Object, :method, {format: 'html'}, class: 'highlight').to_xhtml('a').
|
61
|
+
to_fuzzy_hash.should == {class: "highlight", href: "url_for: Object.method?format=html", content: 'Book'}
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
@t.link_to(Object, :method, {format: 'html'}, class: 'highlight'){'Book'}.to_xhtml('a').
|
64
|
+
to_fuzzy_hash.should == {class: "highlight", href: "url_for: Object.method?format=html", content: 'Book'}
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
@t.link_to('Book', :method).to_xhtml('a').
|
67
|
+
to_fuzzy_hash.should == {href: "url_for: .method", content: 'Book'}
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
it "should works with url_for_path attributes" do
|
71
|
+
@t.link_to('Book', '/some_book', class: 'highlight').to_xhtml('a').
|
72
|
+
to_fuzzy_hash.should == {class: "highlight", href: "/some_book", content: 'Book'}
|
72
73
|
|
73
|
-
|
74
|
-
|
74
|
+
@t.link_to('/some_book', class: 'highlight'){'Book'}.to_xhtml('a').
|
75
|
+
to_fuzzy_hash.should == {class: "highlight", href: "/some_book", content: 'Book'}
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
@t.link_to('/some_book'){'Book'}.to_xhtml('a').
|
78
|
+
to_fuzzy_hash.should == {href: "/some_book", content: 'Book'}
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
it "links for 'js', 'json' formats should be automatically became remote" do
|
82
|
+
@t.link_to('Book', @t.url_for('/some_book', format: 'json')).to_xhtml('a').to_fuzzy_hash.should == {
|
83
|
+
href: '#', content: 'Book',
|
84
|
+
'data-action' => 'url_for: /some_book?format=json', 'data-method' => 'post', 'data-remote' => 'true'
|
85
|
+
}
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
@t.link_to('Book', :method, format: 'js').to_xhtml('a').to_fuzzy_hash.should == {
|
88
|
+
href: '#', content: 'Book',
|
89
|
+
'data-action' => 'url_for: .method?format=js', 'data-method' => 'post', 'data-remote' => 'true'
|
90
|
+
}
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
@t.link_to('Book', :method, {format: 'js'}, class: 'highlight').to_xhtml('a').to_fuzzy_hash.should == {
|
93
|
+
href: '#', content: 'Book', class: 'highlight',
|
94
|
+
'data-action' => 'url_for: .method?format=js', 'data-method' => 'post', 'data-remote' => 'true'
|
95
|
+
}
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
98
|
+
it "confirm" do
|
99
|
+
attrs = @t.link_to('Book', '/some_book', confirm: 'Are you shure?').to_xhtml('a')
|
100
|
+
attrs.should_not include('data-remote')
|
101
|
+
attrs.should_not include('data-action')
|
102
|
+
attrs.should_not include('data-method')
|
103
|
+
attrs.to_fuzzy_hash.should == {
|
104
|
+
href: "/some_book", content: 'Book',
|
105
|
+
'data-confirm' => "Are you shure?"
|
106
|
+
}
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
it "POST method" do
|
110
|
+
attrs = @t.link_to('Book', '/some_book', method: :post).to_xhtml('a')
|
111
|
+
attrs.should_not include('data-remote')
|
112
|
+
attrs.to_fuzzy_hash.should == {
|
113
|
+
href: "#", content: 'Book',
|
114
|
+
'data-action' => '/some_book', 'data-method' => 'post'
|
115
|
+
}
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
118
|
+
it "remote" do
|
119
|
+
@t.link_to('Book', '/some_book', remote: true).to_xhtml('a').to_fuzzy_hash.should == {
|
120
|
+
href: "#", content: 'Book',
|
121
|
+
'data-action' => '/some_book', 'data-method' => 'post', 'data-remote' => 'true'
|
122
|
+
}
|
123
|
+
end
|
123
124
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
125
|
+
it ":back" do
|
126
|
+
env = Object.new
|
127
|
+
env.stub(:[]).and_return('/go_back')
|
128
|
+
request = Object.new
|
129
|
+
request.stub(:env).and_return(env)
|
130
|
+
workspace = Object.new
|
131
|
+
workspace.stub(:request).and_return(request)
|
132
|
+
@t.stub(:workspace).and_return(workspace)
|
132
133
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
@t.link_to('Book', :back).to_xhtml('a').to_fuzzy_hash.should == {href: "/go_back", content: 'Book'}
|
135
|
+
@t.link_to('Book', :back, class: '_some_js_mark').to_xhtml('a').
|
136
|
+
to_fuzzy_hash.should == {href: "/go_back", class: '_some_js_mark', content: 'Book'}
|
137
|
+
end
|
137
138
|
|
138
|
-
|
139
|
-
|
139
|
+
it "#" do
|
140
|
+
@t.link_to('Book', '#').to_xhtml('a').to_fuzzy_hash.should == {href: "#", content: 'Book'}
|
141
|
+
end
|
140
142
|
end
|
143
|
+
else
|
144
|
+
warn "WARN: skipping spec"
|
141
145
|
end
|
142
146
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rad_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -307,7 +307,6 @@ files:
|
|
307
307
|
- lib/rad/spec/router.rb
|
308
308
|
- lib/rad/spec/template.rb
|
309
309
|
- lib/rad/spec/web.rb
|
310
|
-
- lib/rad/spec/xhtml.rb
|
311
310
|
- lib/rad/spec.rb
|
312
311
|
- lib/rad/tasks.rb
|
313
312
|
- lib/rad/template/_context.rb
|
data/lib/rad/spec/xhtml.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
class String
|
4
|
-
def to_xhtml css = nil
|
5
|
-
node = Nokogiri::HTML(self)
|
6
|
-
unless css
|
7
|
-
node
|
8
|
-
else
|
9
|
-
nodes = node.css(css)
|
10
|
-
raise "Elements for '#{css}' CSS query not found!" if nodes.size < 1
|
11
|
-
raise "Found more than one elment for '#{css}' CSS query!" if nodes.size > 1
|
12
|
-
nodes.first
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'nokogiri'
|
18
|
-
::Nokogiri::XML::Node.class_eval do
|
19
|
-
def should_be_fuzzy_equal_to attributes
|
20
|
-
node_attributes = {}
|
21
|
-
|
22
|
-
attributes.each do |k, v|
|
23
|
-
nv = if k.to_s == 'content'
|
24
|
-
self.content
|
25
|
-
else
|
26
|
-
self[k.to_s]
|
27
|
-
end
|
28
|
-
node_attributes[k] = nv
|
29
|
-
end
|
30
|
-
|
31
|
-
node_attributes.should == attributes
|
32
|
-
end
|
33
|
-
end
|