actionview-link_to_blank 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882f89144dc2e878857d65ac92b50d38ca234072
4
- data.tar.gz: 3700974c556b62a290bff69c8fd5a061dbbce275
3
+ metadata.gz: c2a6bc97117487fb592975b61e030831d2158dc1
4
+ data.tar.gz: 0a076c6e6476238bc5e8f04090f331c2f88f018e
5
5
  SHA512:
6
- metadata.gz: d2299f2ee20a6a6f901f7ed8aabff6a2b002ac3d9d617f0435022969571598c16a1477ecb6d79a669811074b8a47c13dad4e8edcd4c793c48809c71fb3621385
7
- data.tar.gz: 4332768310ecab9833f07ba114080efc482b54a59d6232f19c65b52a83033db84b1d4de70ade7d0268a61459a09ac0fe92bb36fbaa02c0107b6e0bfc1d6a7734
6
+ metadata.gz: c25435e9170635c4166247381facb01c89298d62674d83a49d5e0cd4bdf0dfe3f2f2fd4946e2103b0508795a59c0e2f24d99df31f788d1171b4ae2b02005c167
7
+ data.tar.gz: 0a0a5ce22aac9360437ea6a4614266c2ad10e99e6a25fccdf491a4b086aeffcc6c28c6be8fcace11a37e5e0c7c16141c175ea6b1f71fd231a2e103265e02d2a8
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - gemfiles/rails3.2/Gemfile
7
+ - gemfiles/rails4.0/Gemfile
8
+ branches:
9
+ only:
10
+ - master
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Actionview::LinkToBlank
1
+ # ActionView::LinkToBlank
2
2
 
3
- TODO: Write a gem description
3
+ [![Build Status](https://api.travis-ci.org/sanemat/actionview-link_to_blank.png?branch=master)](https://travis-ci.org/sanemat/actionview-link_to_blank)
4
+
5
+ Add helper method, link_to with target _blank
4
6
 
5
7
  ## Installation
6
8
 
@@ -20,6 +22,20 @@ Or install it yourself as:
20
22
 
21
23
  TODO: Write usage instructions here
22
24
 
25
+ ## Testing
26
+
27
+ $ bundle exec rake
28
+
29
+ If you want to run against actionpack v3 and v4, run below:
30
+
31
+ $ bundle --gemfile=gemfiles/rails3.2/Gemfile --path=.bundle
32
+ # this install gems to gemfiles/rails3.2/.bundle/xxx
33
+ $ bundle exec rake BUNDLE_GEMFILE=gemfiles/rails3.2/Gemfile
34
+
35
+ $ bundle --gemfile=gemfiles/rails4.0/Gemfile --path=.bundle
36
+ # this install gems to gemfiles/rails4.0/.bundle/xxx
37
+ $ bundle exec rake BUNDLE_GEMFILE=gemfiles/rails4.0/Gemfile
38
+
23
39
  ## Contributing
24
40
 
25
41
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Default Task'
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/test_*.rb'
10
+ end
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'minitest'
24
+ spec.add_development_dependency 'pry'
23
25
 
24
26
  spec.add_dependency 'actionpack'
27
+ spec.add_dependency 'activesupport'
25
28
  end
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ version = '~> 3.2'
4
+ gem 'actionpack', version
5
+ gem 'activesupport', version
6
+
7
+ # Specify your gem's dependencies in actionview-link_to_blank.gemspec
8
+ gemspec path: File.join('..', '..')
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ version = '~> 4.0.0.beta'
4
+ gem 'actionpack', version
5
+ gem 'activesupport', version
6
+
7
+ # Specify your gem's dependencies in actionview-link_to_blank.gemspec
8
+ gemspec path: File.join('..', '..')
@@ -1,5 +1,5 @@
1
1
  module ActionView
2
2
  module LinkToBlank
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,285 @@
1
+ #coding: utf-8
2
+ require 'minitest/autorun'
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext'
5
+ require 'active_support/testing/deprecation'
6
+ require 'action_view'
7
+ require 'action_view/link_to_blank/link_to_blank'
8
+ require 'action_dispatch'
9
+
10
+ # Copy from actionpack/test/abstract_unit.rb
11
+ module RenderERBUtils
12
+ def render_erb(string)
13
+ @virtual_path = nil
14
+
15
+ template = ActionView::Template.new(
16
+ string.strip,
17
+ "test template",
18
+ ActionView::Template::Handlers::ERB,
19
+ {})
20
+
21
+ template.render(self, {}).strip
22
+ end
23
+ end
24
+
25
+ class TestActionViewLinkToBlank < MiniTest::Unit::TestCase
26
+
27
+ # In a few cases, the helper proxies to 'controller'
28
+ # or request.
29
+ #
30
+ # In those cases, we'll set up a simple mock
31
+ attr_accessor :controller, :request
32
+
33
+ routes = ActionDispatch::Routing::RouteSet.new
34
+ routes.draw do
35
+ get "/" => "foo#bar"
36
+ get "/other" => "foo#other"
37
+ get "/article/:id" => "foo#article", :as => :article
38
+ end
39
+
40
+ include ActionView::Helpers::UrlHelper
41
+ include routes.url_helpers
42
+
43
+ include ActionDispatch::Assertions::DomAssertions
44
+ include ActiveSupport::Testing::Deprecation
45
+ include ActionView::Context
46
+ include RenderERBUtils
47
+
48
+ def hash_for(options = {})
49
+ { controller: "foo", action: "bar" }.merge!(options)
50
+ end
51
+ alias url_hash hash_for
52
+
53
+ def test_initialization
54
+ [:link_to_blank].each do |method|
55
+ assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
56
+ end
57
+ end
58
+
59
+ def test_link_tag_with_straight_url
60
+ assert_dom_equal %{<a href="http://www.example.com" target="_blank">Hello</a>}, link_to_blank("Hello", "http://www.example.com")
61
+ end
62
+
63
+ def test_link_tag_without_host_option
64
+ assert_dom_equal(%{<a href="/" target="_blank">Test Link</a>}, link_to_blank('Test Link', url_hash))
65
+ end
66
+
67
+ def test_link_tag_with_host_option
68
+ hash = hash_for(host: "www.example.com")
69
+ expected = %{<a href="http://www.example.com/" target="_blank">Test Link</a>}
70
+ assert_dom_equal(expected, link_to_blank('Test Link', hash))
71
+ end
72
+
73
+ def test_link_tag_with_query
74
+ expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2" target="_blank">Hello</a>}
75
+ assert_dom_equal expected, link_to_blank("Hello", "http://www.example.com?q1=v1&q2=v2")
76
+ end
77
+
78
+ def test_link_tag_with_query_and_no_name
79
+ expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2" target="_blank">http://www.example.com?q1=v1&amp;q2=v2</a>}
80
+ assert_dom_equal expected, link_to_blank(nil, "http://www.example.com?q1=v1&q2=v2")
81
+ end
82
+
83
+ def test_link_tag_with_back
84
+ env = {"HTTP_REFERER" => "http://www.example.com/referer"}
85
+ @controller = Struct.new(:request).new(Struct.new(:env).new(env))
86
+ expected = %{<a href="#{env["HTTP_REFERER"]}" target="_blank">go back</a>}
87
+ assert_dom_equal expected, link_to_blank('go back', :back)
88
+ end
89
+
90
+ def test_link_tag_with_back_and_no_referer
91
+ @controller = Struct.new(:request).new(Struct.new(:env).new({}))
92
+ link = link_to_blank('go back', :back)
93
+ assert_dom_equal %{<a href="javascript:history.back()" target="_blank">go back</a>}, link
94
+ end
95
+
96
+ def test_link_tag_with_img
97
+ link = link_to_blank("<img src='/favicon.jpg' />".html_safe, "/")
98
+ expected = %{<a href="/" target="_blank"><img src='/favicon.jpg' /></a>}
99
+ assert_dom_equal expected, link
100
+ end
101
+
102
+ def test_link_with_nil_html_options
103
+ link = link_to_blank("Hello", url_hash, nil)
104
+ assert_dom_equal %{<a href="/" target="_blank">Hello</a>}, link
105
+ end
106
+
107
+ def test_link_tag_with_custom_onclick
108
+ link = link_to_blank("Hello", "http://www.example.com", onclick: "alert('yay!')")
109
+ escaped_onclick = ActionPack::VERSION::MAJOR == 3 ? %{alert(&#x27;yay!&#x27;)} : %{alert(&#39;yay!&#39;)}
110
+ expected = %{<a href="http://www.example.com" onclick="#{escaped_onclick}" target="_blank">Hello</a>}
111
+ assert_dom_equal expected, link
112
+ end
113
+
114
+ def test_link_tag_with_javascript_confirm
115
+ assert_dom_equal(
116
+ %{<a href="http://www.example.com" data-confirm="Are you sure?" target="_blank">Hello</a>},
117
+ link_to_blank("Hello", "http://www.example.com", data: { confirm: "Are you sure?" })
118
+ )
119
+ assert_dom_equal(
120
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?" target="_blank">Hello</a>},
121
+ link_to_blank("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure, can you?" })
122
+ )
123
+ assert_dom_equal(
124
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?" target="_blank">Hello</a>},
125
+ link_to_blank("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure,\n can you?" })
126
+ )
127
+ end
128
+
129
+ def test_link_tag_with_deprecated_confirm
130
+ skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
131
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
132
+ assert_dom_equal(
133
+ %{<a href="http://www.example.com" data-confirm="Are you sure?" target="_blank">Hello</a>},
134
+ link_to_blank("Hello", "http://www.example.com", confirm: "Are you sure?")
135
+ )
136
+ end
137
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
138
+ assert_dom_equal(
139
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?" target="_blank">Hello</a>},
140
+ link_to_blank("Hello", "http://www.example.com", confirm: "You cant possibly be sure, can you?")
141
+ )
142
+ end
143
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
144
+ assert_dom_equal(
145
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?" target="_blank">Hello</a>},
146
+ link_to_blank("Hello", "http://www.example.com", confirm: "You cant possibly be sure,\n can you?")
147
+ )
148
+ end
149
+ end
150
+
151
+ def test_link_to_with_remote
152
+ assert_dom_equal(
153
+ %{<a href="http://www.example.com" data-remote="true" target="_blank">Hello</a>},
154
+ link_to_blank("Hello", "http://www.example.com", remote: true)
155
+ )
156
+ end
157
+
158
+ def test_link_to_with_remote_false
159
+ assert_dom_equal(
160
+ %{<a href="http://www.example.com" target="_blank">Hello</a>},
161
+ link_to_blank("Hello", "http://www.example.com", remote: false)
162
+ )
163
+ end
164
+
165
+ def test_link_to_with_symbolic_remote_in_non_html_options
166
+ assert_dom_equal(
167
+ %{<a href="/" data-remote="true" target="_blank">Hello</a>},
168
+ link_to_blank("Hello", hash_for(remote: true), {})
169
+ )
170
+ end
171
+
172
+ def test_link_to_with_string_remote_in_non_html_options
173
+ assert_dom_equal(
174
+ %{<a href="/" data-remote="true" target="_blank">Hello</a>},
175
+ link_to_blank("Hello", hash_for('remote' => true), {})
176
+ )
177
+ end
178
+
179
+ def test_link_tag_using_post_javascript
180
+ assert_dom_equal(
181
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" target="_blank">Hello</a>},
182
+ link_to_blank("Hello", "http://www.example.com", method: :post)
183
+ )
184
+ end
185
+
186
+ def test_link_tag_using_delete_javascript
187
+ assert_dom_equal(
188
+ %{<a href="http://www.example.com" rel="nofollow" data-method="delete" target="_blank">Destroy</a>},
189
+ link_to_blank("Destroy", "http://www.example.com", method: :delete)
190
+ )
191
+ end
192
+
193
+ def test_link_tag_using_delete_javascript_and_href
194
+ assert_dom_equal(
195
+ %{<a href="\#" rel="nofollow" data-method="delete" target="_blank">Destroy</a>},
196
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#')
197
+ )
198
+ end
199
+
200
+ def test_link_tag_using_post_javascript_and_rel
201
+ assert_dom_equal(
202
+ %{<a href="http://www.example.com" data-method="post" rel="example nofollow" target="_blank">Hello</a>},
203
+ link_to_blank("Hello", "http://www.example.com", method: :post, rel: 'example')
204
+ )
205
+ end
206
+
207
+ def test_link_tag_using_post_javascript_and_confirm
208
+ assert_dom_equal(
209
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?" target="_blank">Hello</a>},
210
+ link_to_blank("Hello", "http://www.example.com", method: :post, data: { confirm: "Are you serious?" })
211
+ )
212
+ end
213
+
214
+ def test_link_tag_using_post_javascript_and_with_deprecated_confirm
215
+ skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
216
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
217
+ assert_dom_equal(
218
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?" target="_blank">Hello</a>},
219
+ link_to_blank("Hello", "http://www.example.com", method: :post, confirm: "Are you serious?")
220
+ )
221
+ end
222
+ end
223
+
224
+ def test_link_tag_using_delete_javascript_and_href_and_confirm
225
+ assert_dom_equal(
226
+ %{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete" target="_blank">Destroy</a>},
227
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#', data: { confirm: "Are you serious?" })
228
+ )
229
+ end
230
+
231
+ def test_link_tag_using_delete_javascript_and_href_and_with_deprecated_confirm
232
+ skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
233
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
234
+ assert_dom_equal(
235
+ %{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete" target="_blank">Destroy</a>},
236
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#', confirm: "Are you serious?")
237
+ )
238
+ end
239
+ end
240
+
241
+ def test_link_tag_with_block
242
+ assert_dom_equal %{<a href="/" target="_blank"><span>Example site</span></a>},
243
+ link_to_blank('/') { content_tag(:span, 'Example site') }
244
+ end
245
+
246
+ def test_link_tag_with_block_and_html_options
247
+ assert_dom_equal %{<a class="special" href="/" target="_blank"><span>Example site</span></a>},
248
+ link_to_blank('/', class: "special") { content_tag(:span, 'Example site') }
249
+ end
250
+
251
+ def test_link_tag_using_block_in_erb
252
+ out = render_erb %{<%= link_to_blank('/') do %>Example site<% end %>}
253
+ assert_equal '<a href="/" target="_blank">Example site</a>', out
254
+ end
255
+
256
+ def test_link_tag_with_html_safe_string
257
+ assert_dom_equal(
258
+ %{<a href="/article/Gerd_M%C3%BCller" target="_blank">Gerd Müller</a>},
259
+ link_to_blank("Gerd Müller", article_path("Gerd_Müller".html_safe))
260
+ )
261
+ end
262
+
263
+ def test_link_tag_escapes_content
264
+ assert_dom_equal %{<a href="/" target="_blank">Malicious &lt;script&gt;content&lt;/script&gt;</a>},
265
+ link_to_blank("Malicious <script>content</script>", "/")
266
+ end
267
+
268
+ def test_link_tag_does_not_escape_html_safe_content
269
+ assert_dom_equal %{<a href="/" target="_blank">Malicious <script>content</script></a>},
270
+ link_to_blank("Malicious <script>content</script>".html_safe, "/")
271
+ end
272
+
273
+ private
274
+ # MiniTest does not have build_message method, so I copy from below:
275
+ # https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/assertions/dom.rb
276
+ # Test::Unit
277
+ # http://doc.ruby-lang.org/ja/1.9.3/method/Test=3a=3aUnit=3a=3aAssertions/i/build_message.html
278
+ # Test::Unit (based on MiniTest)
279
+ # http://www.ruby-doc.org/stdlib-2.0/libdoc/test/unit/rdoc/Test/Unit/Assertions.html#method-i-message
280
+ def assert_dom_equal(expected, actual, message = "")
281
+ expected_dom = HTML::Document.new(expected).root
282
+ actual_dom = HTML::Document.new(actual).root
283
+ assert_equal expected_dom, actual_dom
284
+ end
285
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-link_to_blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: actionpack
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - '>='
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: Alias link_to with target _blank
56
98
  email:
57
99
  - o.gata.ken@gmail.com
@@ -60,15 +102,19 @@ extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
62
104
  - .gitignore
105
+ - .travis.yml
63
106
  - Gemfile
64
107
  - LICENSE.txt
65
108
  - README.md
66
109
  - Rakefile
67
110
  - actionview-link_to_blank.gemspec
111
+ - gemfiles/rails3.2/Gemfile
112
+ - gemfiles/rails4.0/Gemfile
68
113
  - lib/action_view/link_to_blank/link_to_blank.rb
69
114
  - lib/action_view/link_to_blank/railtie.rb
70
115
  - lib/action_view/link_to_blank/version.rb
71
116
  - lib/actionview-link_to_blank.rb
117
+ - test/test_actionview-link_to_blank.rb
72
118
  homepage: https://github.com/sanemat/actionview-link_to_blank
73
119
  licenses:
74
120
  - MIT
@@ -93,4 +139,5 @@ rubygems_version: 2.0.0
93
139
  signing_key:
94
140
  specification_version: 4
95
141
  summary: Alias link_to with target _blank
96
- test_files: []
142
+ test_files:
143
+ - test/test_actionview-link_to_blank.rb