actionview-link_to_blank 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23e426373922150a81e24f62484e001d7c8ac8f0
4
+ data.tar.gz: 35fd5f9ceed3fddebbc34483c60dd8720a89686c
5
+ SHA512:
6
+ metadata.gz: 5a0aadf6bdb801c1435cfa6d18ffa51c5c0982cce362fc35176031c10e3cde4b438b9a5e3e67aaf5612e90db503c3ed86a9266925c272f5ea2d7ade4a2c99bfe
7
+ data.tar.gz: 64329e4d5a6780b4c2feca2ee74e3568c25790c95be15be5327bbf4aea54973d149d82717cd8f996572de76765adbf59ca7703f0a582321d71e46dba51f3684a
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.gemfile.lock
@@ -0,0 +1 @@
1
+ strategy: 'none'
@@ -0,0 +1,26 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
8
+ before_install:
9
+ - gem update bundler
10
+ gemfile:
11
+ - gemfiles/rails_3_2.gemfile
12
+ - gemfiles/rails_4_0.gemfile
13
+ - gemfiles/rails_4_1.gemfile
14
+ - gemfiles/rails_4_2.gemfile
15
+ - gemfiles/rails_5_0.gemfile
16
+ - gemfiles/rails_master.gemfile
17
+ matrix:
18
+ exclude:
19
+ - rvm: 2.0.0
20
+ gemfile: gemfiles/rails_5_0.gemfile
21
+ - rvm: 2.0.0
22
+ gemfile: gemfiles/rails_master.gemfile
23
+ - rvm: 2.1.8
24
+ gemfile: gemfiles/rails_5_0.gemfile
25
+ - rvm: 2.1.8
26
+ gemfile: gemfiles/rails_master.gemfile
@@ -0,0 +1,42 @@
1
+ appraise 'rails_3_2' do
2
+ version = '~> 3.2.0'
3
+ gem 'actionpack', version
4
+ gem 'activesupport', version
5
+ gem 'minitest', '~> 4.7.5'
6
+ gem 'test-unit', '~> 3.0'
7
+ end
8
+
9
+ appraise 'rails_4_0' do
10
+ version = '~> 4.0.0'
11
+ gem 'actionpack', version
12
+ gem 'activesupport', version
13
+ end
14
+
15
+ appraise 'rails_4_1' do
16
+ version = '~> 4.1.0'
17
+ gem 'actionpack', version
18
+ gem 'activesupport', version
19
+ end
20
+
21
+ appraise 'rails_4_2' do
22
+ version = '~> 4.2.0'
23
+ gem 'actionview', version
24
+ gem 'actionpack', version
25
+ gem 'activesupport', version
26
+ gem 'rails-dom-testing'
27
+ end
28
+
29
+ appraise 'rails_5_0' do
30
+ version = '~> 5.0.0.beta'
31
+ gem 'actionview', version
32
+ gem 'actionpack', version
33
+ gem 'activesupport', version
34
+ gem 'rails-dom-testing'
35
+ end
36
+
37
+ appraise 'rails_master' do
38
+ gem 'actionview', github: 'rails/rails', branch: 'master'
39
+ gem 'actionpack', github: 'rails/rails', branch: 'master'
40
+ gem 'activesupport', github: 'rails/rails', branch: 'master'
41
+ gem 'rails-dom-testing'
42
+ end
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in actionview-link_to_blank.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
6
+ gem 'pry'
7
+ gem 'appraisal', github: 'thoughtbot/appraisal'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 sanemat
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # ActionView::LinkToBlank
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/actionview-link_to_blank.png)](http://badge.fury.io/rb/actionview-link_to_blank)
4
+ [![Build Status](https://api.travis-ci.org/sanemat/actionview-link_to_blank.png?branch=master)](https://travis-ci.org/sanemat/actionview-link_to_blank)
5
+ [![Code Climate](https://codeclimate.com/github/sanemat/actionview-link_to_blank.png)](https://codeclimate.com/github/sanemat/actionview-link_to_blank)
6
+ [![Coverage Status](https://coveralls.io/repos/sanemat/actionview-link_to_blank/badge.png?branch=master)](https://coveralls.io/r/sanemat/actionview-link_to_blank)
7
+ [![Dependency Status](https://gemnasium.com/sanemat/actionview-link_to_blank.png)](https://gemnasium.com/sanemat/actionview-link_to_blank)
8
+
9
+ Add helper method, link_to_blank, equal to link_to with target _blank
10
+ Add helper method, link_to_blank_if, link_to_blank_unless, link_to_blank_unless_current.
11
+ This is symmetrical to link_to_if, link_to_unless, link_to_unless_current.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'actionview-link_to_blank'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install actionview-link_to_blank
26
+
27
+ ## Usage
28
+
29
+ Use the `link_to_blank` helper method, equal `link_to('foo', target: '_blank')`
30
+
31
+ ### Signatures
32
+
33
+ link_to_blank(body, url, html_options = {})
34
+ # url is a String; you can use URL helpers like
35
+ # posts_path
36
+
37
+ link_to_blank(body, url_options = {}, html_options = {})
38
+ # url_options, except :confirm or :method,
39
+ # is passed to url_for
40
+
41
+ link_to_blank(options = {}, html_options = {}) do
42
+ # name
43
+ end
44
+
45
+ link_to_blank(url, html_options = {}) do
46
+ # name
47
+ end
48
+
49
+ link_to_blank_if(condition, name, options = {}, html_options = {})
50
+ # if condition is true, create a link tag
51
+ # otherwise only name
52
+
53
+ link_to_blank_unless(condition, name, options = {}, html_options = {})
54
+ # if condition is true, only name
55
+ # otherwise create a link tag
56
+
57
+ link_to_blank_unless_current(name, options = {}, html_options = {})
58
+ # create a link tag of the given name unless current page is the same
59
+
60
+ ### Examples
61
+
62
+ link_to_blank "Profile", profile_path(@profile)
63
+ # => <a href="/profiles/1" target="_blank">Profile</a>
64
+
65
+ <%= link_to_blank(@profile) do %>
66
+ <strong><%= @profile.name %></strong> -- <span>Check it out!</span>
67
+ <% end %>
68
+ # => <a href="/profiles/1" target="_blank">
69
+ <strong>David</strong> -- <span>Check it out!</span>
70
+ </a>
71
+
72
+ ## Testing
73
+
74
+ $ bundle exec rake
75
+
76
+ If you want to run against actionpack v3.2, v4.0, v4.1, v4.2, v5.0 and master run below:
77
+
78
+ $ bundle exec appraisal install
79
+ $ bundle exec appraisal rake
80
+
81
+ Test for specific version:
82
+
83
+ $ bundle exec appraisal install
84
+ $ bundle exec appraisal rails_4_0 rake
85
+
86
+ Prepare rails_3_2(gem), rails_4_0(gem), rails_4_1(gem),
87
+ rails_4_2(gem), rails_5_0(gem), rails_master(github)
88
+
89
+ ## Contributing
90
+
91
+ 1. Fork it
92
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
93
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
94
+ 4. Push to the branch (`git push origin my-new-feature`)
95
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'appraisal'
4
+
5
+ desc 'Default Task'
6
+ task default: :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'test'
10
+ t.pattern = 'test/test_*.rb'
11
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'action_view/link_to_blank/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'actionview-link_to_blank'
8
+ spec.version = ActionView::LinkToBlank::VERSION
9
+ spec.authors = ['sanemat']
10
+ spec.email = ['o.gata.ken@gmail.com']
11
+ spec.description = %q(Alias link_to with target _blank)
12
+ spec.summary = %q(Alias link_to with target _blank)
13
+ spec.homepage = 'https://github.com/sanemat/actionview-link_to_blank'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '>= 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest'
24
+
25
+ spec.add_dependency 'actionpack'
26
+ spec.add_dependency 'activesupport'
27
+ end
@@ -0,0 +1,6 @@
1
+ # ChangeLog
2
+
3
+ ## 1.0.4
4
+
5
+ * Update dependencies
6
+ * Support rails v5
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionpack", "~> 3.2.0"
9
+ gem "activesupport", "~> 3.2.0"
10
+ gem "minitest", "~> 4.7.5"
11
+ gem "test-unit", "~> 3.0"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionpack", "~> 4.0.0"
9
+ gem "activesupport", "~> 4.0.0"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionpack", "~> 4.1.0"
9
+ gem "activesupport", "~> 4.1.0"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionview", "~> 4.2.0"
9
+ gem "actionpack", "~> 4.2.0"
10
+ gem "activesupport", "~> 4.2.0"
11
+ gem "rails-dom-testing"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionview", "~> 5.0.0.beta"
9
+ gem "actionpack", "~> 5.0.0.beta"
10
+ gem "activesupport", "~> 5.0.0.beta"
11
+ gem "rails-dom-testing"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require => false
6
+ gem "pry"
7
+ gem "appraisal", :github => "thoughtbot/appraisal"
8
+ gem "actionview", :github => "rails/rails", :branch => "master"
9
+ gem "actionpack", :github => "rails/rails", :branch => "master"
10
+ gem "activesupport", :github => "rails/rails", :branch => "master"
11
+ gem "rails-dom-testing"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,44 @@
1
+ module LinkToBlank
2
+ module ::ActionView
3
+ module Helpers
4
+ module UrlHelper
5
+ def link_to_blank(*args, &block)
6
+ if block_given?
7
+ options = args.first || {}
8
+ html_options = args.second || {}
9
+ link_to_blank(capture(&block), options, html_options)
10
+ else
11
+ name = args[0]
12
+ options = args[1] || {}
13
+ html_options = args[2] || {}
14
+
15
+ # override
16
+ html_options.reverse_merge! target: '_blank'
17
+
18
+ link_to(name, options, html_options)
19
+ end
20
+ end
21
+
22
+ def link_to_blank_unless(condition, name, options = {}, html_options = {}, &block)
23
+ if condition
24
+ if block_given?
25
+ block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
26
+ else
27
+ ERB::Util.html_escape(name)
28
+ end
29
+ else
30
+ link_to_blank(name, options, html_options)
31
+ end
32
+ end
33
+
34
+ def link_to_blank_if(condition, name, options = {}, html_options = {}, &block)
35
+ link_to_blank_unless !condition, name, options, html_options, &block
36
+ end
37
+
38
+ def link_to_blank_unless_current(name, options = {}, html_options = {}, &block)
39
+ link_to_blank_unless current_page?(options), name, options, html_options, &block
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ module ActionView
2
+ module LinkToBlank
3
+ class Railtie < ::Rails::Railtie
4
+ initializer 'actionview-link_to_blank' do |app|
5
+ ActiveSupport.on_load(:action_view) do
6
+ require 'action_view/link_to_blank/link_to_blank'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module ActionView
2
+ module LinkToBlank
3
+ VERSION = '1.0.4'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'action_view/link_to_blank/version'
2
+ require 'action_view/link_to_blank/railtie' if defined? Rails
@@ -0,0 +1,398 @@
1
+ # coding: utf-8
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'minitest/autorun'
6
+ require 'active_support'
7
+ require 'active_support/concern'
8
+ require 'active_support/deprecation'
9
+ require 'active_support/core_ext'
10
+ require 'active_support/testing/deprecation'
11
+ require 'action_controller'
12
+ require 'action_view'
13
+ require 'action_view/link_to_blank/link_to_blank'
14
+ require 'action_dispatch'
15
+ require 'rails-dom-testing' if Gem::Version.new(ActionPack::VERSION::STRING) >= Gem::Version.new("4.2")
16
+
17
+ # Copy from actionpack/test/abstract_unit.rb
18
+ module RenderERBUtils
19
+ def render_erb(string)
20
+ @virtual_path = nil
21
+
22
+ template = ActionView::Template.new(
23
+ string.strip,
24
+ "test template",
25
+ ActionView::Template::Handlers::ERB,
26
+ {})
27
+
28
+ template.render(self, {}).strip
29
+ end
30
+ end
31
+
32
+ # Rails4.1, this code is here:
33
+ # actionview/test/template/url_helper_test.rb
34
+ # and base class is ActiveSupport::TestCase
35
+
36
+ # Ensure backward compatibility with Minitest 4
37
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
38
+
39
+ class TestActionViewLinkToBlank < MiniTest::Test
40
+ # In a few cases, the helper proxies to 'controller'
41
+ # or request.
42
+ #
43
+ # In those cases, we'll set up a simple mock
44
+ attr_accessor :controller, :request
45
+
46
+ cattr_accessor :request_forgery
47
+ self.request_forgery = false
48
+
49
+ routes = ActionDispatch::Routing::RouteSet.new
50
+ routes.draw do
51
+ get "/" => "foo#bar"
52
+ get "/other" => "foo#other"
53
+ get "/article/:id" => "foo#article", :as => :article
54
+ end
55
+
56
+ include ActionView::Helpers::UrlHelper
57
+ include routes.url_helpers
58
+
59
+ dom_assertion = Gem::Version.new(ActionPack::VERSION::STRING) < Gem::Version.new("4.2")\
60
+ ? ActionDispatch::Assertions::DomAssertions
61
+ : Rails::Dom::Testing::Assertions::DomAssertions
62
+
63
+ include dom_assertion
64
+ include ActiveSupport::Testing::Deprecation
65
+ include ActionView::Context
66
+ include RenderERBUtils
67
+
68
+ def hash_for(options = {})
69
+ { controller: "foo", action: "bar" }.merge!(options)
70
+ end
71
+ alias url_hash hash_for
72
+
73
+ def test_initialization
74
+ [:link_to_blank].each do |method|
75
+ assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
76
+ end
77
+ end
78
+
79
+ def test_link_tag_with_straight_url
80
+ assert_dom_equal %{<a href="http://www.example.com" target="_blank">Hello</a>}, link_to_blank("Hello", "http://www.example.com")
81
+ end
82
+
83
+ def test_link_tag_without_host_option
84
+ assert_dom_equal(%{<a href="/" target="_blank">Test Link</a>}, link_to_blank('Test Link', url_hash))
85
+ end
86
+
87
+ def test_link_tag_with_host_option
88
+ hash = hash_for(host: "www.example.com")
89
+ expected = %{<a href="http://www.example.com/" target="_blank">Test Link</a>}
90
+ assert_dom_equal(expected, link_to_blank('Test Link', hash))
91
+ end
92
+
93
+ def test_link_tag_with_query
94
+ expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2" target="_blank">Hello</a>}
95
+ assert_dom_equal expected, link_to_blank("Hello", "http://www.example.com?q1=v1&q2=v2")
96
+ end
97
+
98
+ def test_link_tag_with_query_and_no_name
99
+ expected = %{<a href="http://www.example.com?q1=v1&amp;q2=v2" target="_blank">http://www.example.com?q1=v1&amp;q2=v2</a>}
100
+ assert_dom_equal expected, link_to_blank(nil, "http://www.example.com?q1=v1&q2=v2")
101
+ end
102
+
103
+ def test_link_tag_with_back
104
+ env = {"HTTP_REFERER" => "http://www.example.com/referer"}
105
+ @controller = Struct.new(:request).new(Struct.new(:env).new(env))
106
+ expected = %{<a href="#{env["HTTP_REFERER"]}" target="_blank">go back</a>}
107
+ assert_dom_equal expected, link_to_blank('go back', :back)
108
+ end
109
+
110
+ def test_link_tag_with_back_and_no_referer
111
+ @controller = Struct.new(:request).new(Struct.new(:env).new({}))
112
+ link = link_to_blank('go back', :back)
113
+ assert_dom_equal %{<a href="javascript:history.back()" target="_blank">go back</a>}, link
114
+ end
115
+
116
+ def test_link_tag_with_img
117
+ link = link_to_blank("<img src='/favicon.jpg' />".html_safe, "/")
118
+ expected = %{<a href="/" target="_blank"><img src='/favicon.jpg' /></a>}
119
+ assert_dom_equal expected, link
120
+ end
121
+
122
+ def test_link_with_nil_html_options
123
+ link = link_to_blank("Hello", url_hash, nil)
124
+ assert_dom_equal %{<a href="/" target="_blank">Hello</a>}, link
125
+ end
126
+
127
+ def test_link_tag_with_custom_onclick
128
+ link = link_to_blank("Hello", "http://www.example.com", onclick: "alert('yay!')")
129
+ # NOTE: differences between AP v3 and v4
130
+ escaped_onclick = ActionPack::VERSION::MAJOR == 3 ? %{alert(&#x27;yay!&#x27;)} : %{alert(&#39;yay!&#39;)}
131
+ expected = %{<a href="http://www.example.com" onclick="#{escaped_onclick}" target="_blank">Hello</a>}
132
+ assert_dom_equal expected, link
133
+ end
134
+
135
+ def test_link_tag_with_javascript_confirm
136
+ assert_dom_equal(
137
+ %{<a href="http://www.example.com" data-confirm="Are you sure?" target="_blank">Hello</a>},
138
+ link_to_blank("Hello", "http://www.example.com", data: { confirm: "Are you sure?" })
139
+ )
140
+ assert_dom_equal(
141
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?" target="_blank">Hello</a>},
142
+ link_to_blank("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure, can you?" })
143
+ )
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", data: { confirm: "You cant possibly be sure,\n can you?" })
147
+ )
148
+ end
149
+
150
+ def test_link_tag_with_deprecated_confirm
151
+ skip('Not deprecate in Rails3.2') if Gem::Version.new(ActionPack::VERSION::STRING) < Gem::Version.new('4')
152
+ skip('Remove in Rails4.1') if Gem::Version.new(ActionPack::VERSION::STRING) >= Gem::Version.new('4.1')
153
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
154
+ assert_dom_equal(
155
+ %{<a href="http://www.example.com" data-confirm="Are you sure?" target="_blank">Hello</a>},
156
+ link_to_blank("Hello", "http://www.example.com", confirm: "Are you sure?")
157
+ )
158
+ end
159
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
160
+ assert_dom_equal(
161
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?" target="_blank">Hello</a>},
162
+ link_to_blank("Hello", "http://www.example.com", confirm: "You cant possibly be sure, can you?")
163
+ )
164
+ end
165
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
166
+ assert_dom_equal(
167
+ %{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?" target="_blank">Hello</a>},
168
+ link_to_blank("Hello", "http://www.example.com", confirm: "You cant possibly be sure,\n can you?")
169
+ )
170
+ end
171
+ end
172
+
173
+ def test_link_to_with_remote
174
+ assert_dom_equal(
175
+ %{<a href="http://www.example.com" data-remote="true" target="_blank">Hello</a>},
176
+ link_to_blank("Hello", "http://www.example.com", remote: true)
177
+ )
178
+ end
179
+
180
+ def test_link_to_with_remote_false
181
+ assert_dom_equal(
182
+ %{<a href="http://www.example.com" target="_blank">Hello</a>},
183
+ link_to_blank("Hello", "http://www.example.com", remote: false)
184
+ )
185
+ end
186
+
187
+ def test_link_to_with_symbolic_remote_in_non_html_options
188
+ assert_dom_equal(
189
+ %{<a href="/" data-remote="true" target="_blank">Hello</a>},
190
+ link_to_blank("Hello", hash_for(remote: true), {})
191
+ )
192
+ end
193
+
194
+ def test_link_to_with_string_remote_in_non_html_options
195
+ assert_dom_equal(
196
+ %{<a href="/" data-remote="true" target="_blank">Hello</a>},
197
+ link_to_blank("Hello", hash_for('remote' => true), {})
198
+ )
199
+ end
200
+
201
+ def test_link_tag_using_post_javascript
202
+ assert_dom_equal(
203
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" target="_blank">Hello</a>},
204
+ link_to_blank("Hello", "http://www.example.com", method: :post)
205
+ )
206
+ end
207
+
208
+ def test_link_tag_using_delete_javascript
209
+ assert_dom_equal(
210
+ %{<a href="http://www.example.com" rel="nofollow" data-method="delete" target="_blank">Destroy</a>},
211
+ link_to_blank("Destroy", "http://www.example.com", method: :delete)
212
+ )
213
+ end
214
+
215
+ def test_link_tag_using_delete_javascript_and_href
216
+ assert_dom_equal(
217
+ %{<a href="\#" rel="nofollow" data-method="delete" target="_blank">Destroy</a>},
218
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#')
219
+ )
220
+ end
221
+
222
+ def test_link_tag_using_post_javascript_and_rel
223
+ assert_dom_equal(
224
+ %{<a href="http://www.example.com" data-method="post" rel="example nofollow" target="_blank">Hello</a>},
225
+ link_to_blank("Hello", "http://www.example.com", method: :post, rel: 'example')
226
+ )
227
+ end
228
+
229
+ def test_link_tag_using_post_javascript_and_confirm
230
+ assert_dom_equal(
231
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?" target="_blank">Hello</a>},
232
+ link_to_blank("Hello", "http://www.example.com", method: :post, data: { confirm: "Are you serious?" })
233
+ )
234
+ end
235
+
236
+ def test_link_tag_using_post_javascript_and_with_deprecated_confirm
237
+ skip('Not deprecate in Rails3.2') if Gem::Version.new(ActionPack::VERSION::STRING) < Gem::Version.new('4')
238
+ skip('Remove in Rails4.1') if Gem::Version.new(ActionPack::VERSION::STRING) >= Gem::Version.new('4.1')
239
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
240
+ assert_dom_equal(
241
+ %{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?" target="_blank">Hello</a>},
242
+ link_to_blank("Hello", "http://www.example.com", method: :post, confirm: "Are you serious?")
243
+ )
244
+ end
245
+ end
246
+
247
+ def test_link_tag_using_delete_javascript_and_href_and_confirm
248
+ assert_dom_equal(
249
+ %{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete" target="_blank">Destroy</a>},
250
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#', data: { confirm: "Are you serious?" })
251
+ )
252
+ end
253
+
254
+ def test_link_tag_using_delete_javascript_and_href_and_with_deprecated_confirm
255
+ skip('Not deprecate in Rails3.2') if Gem::Version.new(ActionPack::VERSION::STRING) < Gem::Version.new('4')
256
+ skip('Remove in Rails4.1') if Gem::Version.new(ActionPack::VERSION::STRING) >= Gem::Version.new('4.1')
257
+ assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
258
+ assert_dom_equal(
259
+ %{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete" target="_blank">Destroy</a>},
260
+ link_to_blank("Destroy", "http://www.example.com", method: :delete, href: '#', confirm: "Are you serious?")
261
+ )
262
+ end
263
+ end
264
+
265
+ def test_link_tag_with_block
266
+ assert_dom_equal %{<a href="/" target="_blank"><span>Example site</span></a>},
267
+ link_to_blank('/') { content_tag(:span, 'Example site') }
268
+ end
269
+
270
+ def test_link_tag_with_block_and_html_options
271
+ assert_dom_equal %{<a class="special" href="/" target="_blank"><span>Example site</span></a>},
272
+ link_to_blank('/', class: "special") { content_tag(:span, 'Example site') }
273
+ end
274
+
275
+ def test_link_tag_using_block_and_hash
276
+ assert_dom_equal(
277
+ %{<a href="/" target="_blank"><span>Example site</span></a>},
278
+ link_to_blank(url_hash) { content_tag(:span, 'Example site') }
279
+ )
280
+ end
281
+
282
+ def test_link_tag_using_block_in_erb
283
+ out = render_erb %{<%= link_to_blank('/') do %>Example site<% end %>}
284
+ assert_dom_equal '<a href="/" target="_blank">Example site</a>', out
285
+ end
286
+
287
+ def test_link_tag_with_html_safe_string
288
+ assert_dom_equal(
289
+ %{<a href="/article/Gerd_M%C3%BCller" target="_blank">Gerd Müller</a>},
290
+ link_to_blank("Gerd Müller", article_path("Gerd_Müller".html_safe))
291
+ )
292
+ end
293
+
294
+ def test_link_tag_escapes_content
295
+ assert_dom_equal %{<a href="/" target="_blank">Malicious &lt;script&gt;content&lt;/script&gt;</a>},
296
+ link_to_blank("Malicious <script>content</script>", "/")
297
+ end
298
+
299
+ def test_link_tag_does_not_escape_html_safe_content
300
+ assert_dom_equal %{<a href="/" target="_blank">Malicious <script>content</script></a>},
301
+ link_to_blank("Malicious <script>content</script>".html_safe, "/")
302
+ end
303
+
304
+ def test_link_tag_override_specific
305
+ assert_dom_equal %{<a href="http://www.example.com" target="override">Hello</a>}, link_to_blank("Hello", "http://www.example.com", target: 'override')
306
+ end
307
+
308
+ def test_link_to_unless
309
+ assert_equal "Showing", link_to_blank_unless(true, "Showing", url_hash)
310
+
311
+ assert_dom_equal %{<a href="/" target="_blank">Listing</a>},
312
+ link_to_blank_unless(false, "Listing", url_hash)
313
+
314
+ assert_equal "Showing", link_to_blank_unless(true, "Showing", url_hash)
315
+
316
+ assert_equal "<strong>Showing</strong>",
317
+ link_to_blank_unless(true, "Showing", url_hash) { |name|
318
+ "<strong>#{name}</strong>".html_safe
319
+ }
320
+
321
+ assert_equal "test",
322
+ link_to_blank_unless(true, "Showing", url_hash) {
323
+ "test"
324
+ }
325
+
326
+ # FIXME
327
+ assert_equal %{&lt;b&gt;Showing&lt;/b&gt;}, link_to_blank_unless(true, "<b>Showing</b>", url_hash)
328
+ assert_equal %{<a href="/">&lt;b&gt;Showing&lt;/b&gt;</a>}, link_to_unless(false, "<b>Showing</b>", url_hash)
329
+ assert_equal %{<b>Showing</b>}, link_to_unless(true, "<b>Showing</b>".html_safe, url_hash)
330
+ assert_equal %{<a href="/"><b>Showing</b></a>}, link_to_unless(false, "<b>Showing</b>".html_safe, url_hash)
331
+ end
332
+
333
+ def test_link_to_if
334
+ assert_equal "Showing", link_to_blank_if(false, "Showing", url_hash)
335
+ assert_dom_equal %{<a href="/" target="_blank">Listing</a>}, link_to_blank_if(true, "Listing", url_hash)
336
+ end
337
+
338
+ def request_for_url(url, opts = {})
339
+ env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
340
+ ActionDispatch::Request.new(env)
341
+ end
342
+
343
+ def test_link_unless_current
344
+ @request = request_for_url("/")
345
+
346
+ assert_equal "Showing",
347
+ link_to_blank_unless_current("Showing", url_hash)
348
+ assert_equal "Showing",
349
+ link_to_blank_unless_current("Showing", "http://www.example.com/")
350
+
351
+ @request = request_for_url("/?order=desc")
352
+
353
+ assert_equal "Showing",
354
+ link_to_blank_unless_current("Showing", url_hash)
355
+ assert_equal "Showing",
356
+ link_to_blank_unless_current("Showing", "http://www.example.com/")
357
+
358
+ @request = request_for_url("/?order=desc&page=1")
359
+
360
+ assert_equal "Showing",
361
+ link_to_blank_unless_current("Showing", hash_for(order: 'desc', page: '1'))
362
+ assert_equal "Showing",
363
+ link_to_blank_unless_current("Showing", "http://www.example.com/?order=desc&page=1")
364
+
365
+ @request = request_for_url("/?order=desc")
366
+
367
+ assert_dom_equal %{<a href="/?order=asc" target="_blank">Showing</a>},
368
+ link_to_blank_unless_current("Showing", hash_for(order: :asc))
369
+ assert_dom_equal %{<a href="http://www.example.com/?order=asc" target="_blank">Showing</a>},
370
+ link_to_blank_unless_current("Showing", "http://www.example.com/?order=asc")
371
+
372
+ @request = request_for_url("/?order=desc")
373
+ assert_dom_equal %{<a href="/?order=desc&amp;page=2\" target="_blank">Showing</a>},
374
+ link_to_blank_unless_current("Showing", hash_for(order: "desc", page: 2))
375
+ assert_dom_equal %{<a href="http://www.example.com/?order=desc&amp;page=2" target="_blank">Showing</a>},
376
+ link_to_blank_unless_current("Showing", "http://www.example.com/?order=desc&page=2")
377
+
378
+ @request = request_for_url("/show")
379
+
380
+ assert_dom_equal %{<a href="/" target="_blank">Listing</a>},
381
+ link_to_blank_unless_current("Listing", url_hash)
382
+ assert_dom_equal %{<a href="http://www.example.com/" target="_blank">Listing</a>},
383
+ link_to_blank_unless_current("Listing", "http://www.example.com/")
384
+ end
385
+
386
+ private
387
+ # MiniTest does not have build_message method, so I copy from below:
388
+ # https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/assertions/dom.rb
389
+ # Test::Unit
390
+ # http://doc.ruby-lang.org/ja/1.9.3/method/Test=3a=3aUnit=3a=3aAssertions/i/build_message.html
391
+ # Test::Unit (based on MiniTest)
392
+ # http://www.ruby-doc.org/stdlib-2.0/libdoc/test/unit/rdoc/Test/Unit/Assertions.html#method-i-message
393
+ def assert_dom_equal(expected, actual, message = "")
394
+ expected_dom = HTML::Document.new(expected).root
395
+ actual_dom = HTML::Document.new(actual).root
396
+ assert_equal expected_dom, actual_dom
397
+ end
398
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionview-link_to_blank
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - sanemat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
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: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Alias link_to with target _blank
84
+ email:
85
+ - o.gata.ken@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".tachikoma.yml"
92
+ - ".travis.yml"
93
+ - Appraisals
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - actionview-link_to_blank.gemspec
99
+ - changelog.md
100
+ - gemfiles/rails_3_2.gemfile
101
+ - gemfiles/rails_4_0.gemfile
102
+ - gemfiles/rails_4_1.gemfile
103
+ - gemfiles/rails_4_2.gemfile
104
+ - gemfiles/rails_5_0.gemfile
105
+ - gemfiles/rails_master.gemfile
106
+ - lib/action_view/link_to_blank/link_to_blank.rb
107
+ - lib/action_view/link_to_blank/railtie.rb
108
+ - lib/action_view/link_to_blank/version.rb
109
+ - lib/actionview-link_to_blank.rb
110
+ - test/test_actionview-link_to_blank.rb
111
+ homepage: https://github.com/sanemat/actionview-link_to_blank
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Alias link_to with target _blank
135
+ test_files:
136
+ - test/test_actionview-link_to_blank.rb