wj-jquery-rails 4.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "mime-types", "< 3", group: :test
4
+
5
+ if RUBY_VERSION >= '2.2.2'
6
+ gem 'rails'
7
+ gem 'rack'
8
+ gem 'json', '>= 2'
9
+ else
10
+ gem 'rails', '~> 4.2.0'
11
+ gem 'rack', '~>1.6'
12
+ gem 'json', '~> 1.8.0'
13
+ end
14
+
15
+ # Specify your gem's dependencies in jquery-rails.gemspec
16
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010-2016 Andre Arko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ # jquery-rails
2
+
3
+ jQuery! For Rails! So great.
4
+
5
+ This gem provides:
6
+
7
+ * jQuery 1, 2 and 3
8
+ * the jQuery UJS adapter
9
+ * assert_select_jquery to test jQuery responses in Ruby tests
10
+
11
+ ## Versions
12
+
13
+ Starting with v2.1, the jquery-rails gem follows these version guidelines
14
+ to provide more control over your app's jQuery version from your Gemfile:
15
+
16
+ ```
17
+ patch version bump = updates to jquery-ujs, jquery-rails, and patch-level updates to jQuery
18
+ minor version bump = minor-level updates to jQuery
19
+ major version bump = major-level updates to jQuery and updates to Rails which may be backwards-incompatible
20
+ ```
21
+
22
+ See [VERSIONS.md](VERSIONS.md) to see which versions of jquery-rails bundle which
23
+ versions of jQuery.
24
+
25
+ ## Installation
26
+
27
+ The jquery and jquery-ujs files will be added to the asset pipeline and available for you to use. If they're not already in `app/assets/javascripts/application.js` by default, add these lines:
28
+
29
+ ```js
30
+ //= require jquery
31
+ //= require jquery_ujs
32
+ ```
33
+
34
+ If you want to use jQuery 2, you can require `jquery2` instead:
35
+
36
+ ```js
37
+ //= require jquery2
38
+ //= require jquery_ujs
39
+ ```
40
+
41
+ And if you want to use jQuery 3, you can require `jquery3`:
42
+
43
+ ```js
44
+ //= require jquery3
45
+ //= require jquery_ujs
46
+ ```
47
+
48
+ For jQuery UI, we recommend the [jquery-ui-rails](https://github.com/joliss/jquery-ui-rails) gem, as it includes the jquery-ui css and allows easier customization.
49
+
50
+ *As of v3.0, jquery-rails no longer includes jQuery UI. Use the
51
+ jquery-ui-rails gem above.*
52
+
53
+ ## Contributing to jquery-rails
54
+
55
+ jquery-rails is work of many contributors. You're encouraged to submit pull requests, propose
56
+ features and discuss issues.
57
+
58
+ * If it's an issue pertaining to the jquery-ujs javascript, please report it to the [jquery-ujs project](https://github.com/rails/jquery-ujs).
59
+
60
+ * If the jQuery scripts are outdated (i.e. maybe a new version of jquery was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated jQuery scripts.
61
+
62
+ See [CONTRIBUTING](CONTRIBUTING.md).
63
+
64
+ ## License
65
+ jquery-rails is released under the [MIT License](MIT-LICENSE).
66
+
67
+ ## Acknowledgements
68
+
69
+ Many thanks are due to all of [the jquery-rails contributors](https://github.com/rails/jquery-rails/graphs/contributors). Special thanks to [JangoSteve](http://github.com/JangoSteve) for tirelessly answering questions and accepting patches, and the [Rails Core Team](https://github.com/organizations/rails/teams/617) for making jquery-rails an official part of Rails 3.1.
@@ -0,0 +1,59 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ task default: :test
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.warning = true
11
+ t.verbose = true
12
+ end
13
+
14
+ # Check if versions are correct between VERSION constants and .js files
15
+ #
16
+ task :release => [:guard_version]
17
+
18
+ task :guard_version do
19
+ def check_version(file, pattern, constant)
20
+ body = File.read("vendor/assets/javascripts/#{file}")
21
+ match = body.match(pattern) or abort "Version check failed: no pattern matched in #{file}"
22
+ file_version = match[1]
23
+ constant_version = Jquery::Rails.const_get(constant)
24
+
25
+ unless constant_version == file_version
26
+ abort "Jquery::Rails::#{constant} was #{constant_version} but it should be #{file_version}"
27
+ end
28
+ end
29
+
30
+ check_version('jquery.js', /jQuery JavaScript Library v([\S]+)/, 'JQUERY_VERSION')
31
+ check_version('jquery2.js', /jQuery JavaScript Library v([\S]+)/, 'JQUERY_2_VERSION')
32
+ check_version('jquery3.js', /jQuery JavaScript Library v([\S]+)/, 'JQUERY_3_VERSION')
33
+ end
34
+
35
+ desc "Update jQuery versions"
36
+ task :update_jquery do
37
+ def download_jquery(filename, version)
38
+ suffix = "-#{version}"
39
+
40
+ puts "Downloading #{filename}.js"
41
+ puts `curl -o vendor/assets/javascripts/#{filename}.js https://code.jquery.com/jquery#{suffix}.js`
42
+ puts "Downloading #{filename}.min.js"
43
+ puts `curl -o vendor/assets/javascripts/#{filename}.min.js https://code.jquery.com/jquery#{suffix}.min.js`
44
+ puts "Downloading #{filename}.min.map"
45
+ puts `curl -o vendor/assets/javascripts/#{filename}.min.map https://code.jquery.com/jquery#{suffix}.min.map`
46
+ end
47
+
48
+ download_jquery('jquery', Jquery::Rails::JQUERY_VERSION)
49
+ download_jquery('jquery2', Jquery::Rails::JQUERY_2_VERSION)
50
+ download_jquery('jquery3', Jquery::Rails::JQUERY_3_VERSION)
51
+ puts "\e[32mDone!\e[0m"
52
+ end
53
+
54
+ desc "Update jQuery UJS version"
55
+ task :update_jquery_ujs do
56
+ puts "Downloading jquery_ujs.js"
57
+ puts `curl -o vendor/assets/javascripts/jquery_ujs.js https://raw.githubusercontent.com/rails/jquery-ujs/v#{Jquery::Rails::JQUERY_UJS_VERSION}/src/rails.js`
58
+ puts "\e[32mDone!\e[0m"
59
+ end
@@ -0,0 +1,58 @@
1
+ # Bundled Versions
2
+
3
+ | Gem | jQuery | jQuery UJS | jQuery UI |
4
+ |--------|--------|------------| ----------|
5
+ | 4.2.2 | 1.12.4 & 2.2.4 & 3.1.1 | 1.2.2 | - |
6
+ | 4.2.1 | 1.12.4 & 2.2.4 & 3.1.0 | 1.2.2 | - |
7
+ | 4.2.0 | 1.12.4 & 2.2.4 & 3.0.0 | 1.2.2 | - |
8
+ | 4.1.1 | 1.12.1 & 2.2.1 | 1.2.1 | - |
9
+ | 4.1.0 | 1.12.0 & 2.2.0 | 1.2.0 | - |
10
+ | 4.0.5 | 1.11.3 & 2.1.4 | 1.1.0 | - |
11
+ | 4.0.4 | 1.11.2 & 2.1.3 | 1.0.4 | - |
12
+ | 4.0.3 | 1.11.2 & 2.1.3 | 1.0.3 | - |
13
+ | 4.0.2 | - | - | - |
14
+ | 4.0.1 | - | - | - |
15
+ | 4.0.0 | 1.11.1 & 2.1.1 | 1.0.2 | - |
16
+ | 3.1.3 | 1.11.1 | 1.0.4 | - |
17
+ | 3.1.2 | 1.11.1 | 1.0.1 | - |
18
+ | 3.1.1 | 1.11.1 | 1.0.0 | - |
19
+ | 3.1.0 | 1.11.0 | - | - |
20
+ | 3.0.5 | 1.11.0 | - | - |
21
+ | 3.0.4 | ↾ | - | - |
22
+ | 3.0.3 | 1.10.2 | - | - |
23
+ | 3.0.2 | ↾ | - | - |
24
+ | 3.0.1 | 1.10.1 | - | - |
25
+ | 3.0.0 | ↾ | - | - |
26
+ | 2.3.0 | 1.10.0 | - | 1.10.3 |
27
+ | 2.2.2 | ↾ | - | ↾ |
28
+ | 2.2.1 | 1.9.1 | - | ↾ |
29
+ | 2.2.0 | 1.9.0 | - | ↾ |
30
+ | 2.1.4 | 1.8.3 | - | 1.9.2 |
31
+ | 2.1.3 | 1.8.2 | - | ↾ |
32
+ | 2.1.2 | 1.8.1 | - | ↾ |
33
+ | 2.1.1 | ↾ | - | ↾ |
34
+ | 2.1.0 | 1.8.0 | - | 1.8.23 |
35
+ | 2.0.3 | ↾ | - | ↾ |
36
+ | 2.0.2 | 1.7.2 | - | 1.8.18 |
37
+ | 2.0.1 | ↾ | - | ↾ |
38
+ | 2.0.0 | ↾ | - | ↾ |
39
+ | 1.0.19 | 1.7.1 | - | ↾ |
40
+ | 1.0.18 | ↾ | - | ↾ |
41
+ | 1.0.17 | 1.7.0 | - | ↾ |
42
+ | 1.0.16 | 1.6.4 | - | 1.8.16 |
43
+ | 1.0.15 | ↾ | - | ↾ |
44
+ | 1.0.14 | ↾ | - | ↾ |
45
+ | 1.0.13 | 1.6.2 | - | 1.8.14 |
46
+ | 1.0.12 | ↾ | - | ↾ |
47
+ | 1.0.11 | ↾ | - | ↾ |
48
+ | 1.0.10 | ↾ | - | ↾ |
49
+ | 1.0.9 | ↾ | - | ↾ |
50
+ | 1.0.8 | ↾ | - | ↾ |
51
+ | 1.0.7 | ↾ | - | ↾ |
52
+ | 1.0.6 | ↾ | - | ↾ |
53
+ | 1.0.5 | ↾ | - | ↾ |
54
+ | 1.0.4 | ↾ | - | ↾ |
55
+ | 1.0.3 | 1.6.1 | - | ↾ |
56
+ | 1.0.2 | ↾ | - | ↾ |
57
+ | 1.0.1 | ↾ | - | 1.8.12 |
58
+ | 1.0.0 | 1.6.0 | - | - |
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "wj-jquery-rails"
6
+ s.version = '4.2.2.1'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["André Arko","wordjelly"]
9
+ s.email = ["bhargav.r.raut@gmail.com"]
10
+ s.homepage = "https://github.com/rails/jquery-rails"
11
+ s.summary = "Use jQuery with Rails 4+"
12
+ s.description = "This gem provides jQuery and the jQuery-ujs driver for your Rails 4+ application."
13
+ s.license = "MIT"
14
+
15
+ s.required_ruby_version = ">= 1.9.3"
16
+ s.required_rubygems_version = ">= 1.3.6"
17
+
18
+ s.add_dependency "railties", ">= 4.2.0"
19
+ s.add_dependency "thor", ">= 0.14", "< 2.0"
20
+
21
+ s.add_dependency "rails-dom-testing", ">= 1", "< 3"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
25
+ s.require_path = 'lib'
26
+ end
@@ -0,0 +1 @@
1
+ require 'jquery/rails'
@@ -0,0 +1,131 @@
1
+ require 'rails/dom/testing/assertions/selector_assertions'
2
+
3
+ module Rails::Dom::Testing::Assertions::SelectorAssertions
4
+ # Selects content from a JQuery response. Patterned loosely on
5
+ # assert_select_rjs.
6
+ #
7
+ # === Narrowing down
8
+ #
9
+ # With no arguments, asserts that one or more method calls are made.
10
+ #
11
+ # Use the +method+ argument to narrow down the assertion to only
12
+ # statements that call that specific method.
13
+ #
14
+ # Use the +opt+ argument to narrow down the assertion to only statements
15
+ # that pass +opt+ as the first argument.
16
+ #
17
+ # Use the +id+ argument to narrow down the assertion to only statements
18
+ # that invoke methods on the result of using that identifier as a
19
+ # selector.
20
+ #
21
+ # === Using blocks
22
+ #
23
+ # Without a block, +assert_select_jquery_ merely asserts that the
24
+ # response contains one or more statements that match the conditions
25
+ # specified above
26
+ #
27
+ # With a block +assert_select_jquery_ also asserts that the method call
28
+ # passes a javascript escaped string containing HTML. All such HTML
29
+ # fragments are selected and passed to the block. Nested assertions are
30
+ # supported.
31
+ #
32
+ # === Examples
33
+ #
34
+ # # asserts that the #notice element is hidden
35
+ # assert_select :hide, '#notice'
36
+ #
37
+ # # asserts that the #cart element is shown with a blind parameter
38
+ # assert_select :show, :blind, '#cart'
39
+ #
40
+ # # asserts that #cart content contains a #current_item
41
+ # assert_select :html, '#cart' do
42
+ # assert_select '#current_item'
43
+ # end
44
+ #
45
+ # # asserts that #product append to a #product_list
46
+ # assert_select_jquery :appendTo, '#product_list' do
47
+ # assert_select '.product'
48
+ # end
49
+
50
+ PATTERN_HTML = "['\"]((\\\\\"|[^\"])*)['\"]"
51
+ PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
52
+ SKELETAL_PATTERN = "(?:jQuery|\\$)\\(%s\\)\\.%s\\(%s\\);"
53
+
54
+ def assert_select_jquery(*args, &block)
55
+ jquery_method = args.first.is_a?(Symbol) ? args.shift : nil
56
+ jquery_opt = args.first.is_a?(Symbol) ? args.shift : nil
57
+ id = args.first.is_a?(String) ? args.shift : nil
58
+
59
+ target_pattern = "['\"]#{id || '.*'}['\"]"
60
+ method_pattern = "#{jquery_method || '\\w+'}"
61
+ argument_pattern = jquery_opt ? "['\"]#{jquery_opt}['\"].*" : PATTERN_HTML
62
+
63
+ # $("#id").show('blind', 1000);
64
+ # $("#id").html("<div>something</div>");
65
+ # $("#id").replaceWith("<div>something</div>");
66
+ target_as_receiver_pattern = SKELETAL_PATTERN % [target_pattern, method_pattern, argument_pattern]
67
+
68
+ # $("<div>something</div>").appendTo("#id");
69
+ # $("<div>something</div>").prependTo("#id");
70
+ target_as_argument_pattern = SKELETAL_PATTERN % [argument_pattern, method_pattern, target_pattern]
71
+
72
+ # $("#id").remove();
73
+ # $("#id").hide();
74
+ argumentless_pattern = SKELETAL_PATTERN % [target_pattern, method_pattern, '']
75
+
76
+ patterns = [target_as_receiver_pattern, target_as_argument_pattern]
77
+ patterns << argumentless_pattern unless jquery_opt
78
+
79
+ matched_pattern = nil
80
+ patterns.each do |pattern|
81
+ if response.body.match(Regexp.new(pattern))
82
+ matched_pattern = pattern
83
+ break
84
+ end
85
+ end
86
+
87
+ unless matched_pattern
88
+ opts = [jquery_method, jquery_opt, id].compact
89
+ flunk "No JQuery call matches #{opts.inspect}"
90
+ end
91
+
92
+ if block_given?
93
+ @selected ||= nil
94
+ fragments = Nokogiri::HTML::Document.new
95
+
96
+ if matched_pattern
97
+ response.body.scan(Regexp.new(matched_pattern)).each do |match|
98
+ flunk 'This function can\'t have HTML argument' if match.is_a?(String)
99
+
100
+ doc = Nokogiri::HTML::Document.parse(unescape_js(match.first))
101
+ doc.root.children.each do |child|
102
+ fragments << child if child.element?
103
+ end
104
+ end
105
+ end
106
+
107
+ begin
108
+ in_scope, @selected = @selected, fragments
109
+ yield
110
+ ensure
111
+ @selected = in_scope
112
+ end
113
+ end
114
+ end
115
+
116
+ private
117
+
118
+ # Unescapes a JS string.
119
+ def unescape_js(js_string)
120
+ # js encodes double quotes and line breaks.
121
+ unescaped= js_string.gsub('\"', '"')
122
+ unescaped.gsub!('\\\'', "'")
123
+ unescaped.gsub!(/\\\//, '/')
124
+ unescaped.gsub!('\n', "\n")
125
+ unescaped.gsub!('\076', '>')
126
+ unescaped.gsub!('\074', '<')
127
+ # js encodes non-ascii characters.
128
+ unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')}
129
+ unescaped
130
+ end
131
+ end
@@ -0,0 +1,8 @@
1
+ require 'jquery/assert_select' if ::Rails.env.test?
2
+ require 'jquery/rails/engine'
3
+ require 'jquery/rails/version'
4
+
5
+ module Jquery
6
+ module Rails
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Jquery
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Jquery
2
+ module Rails
3
+ VERSION = "4.2.2"
4
+ JQUERY_VERSION = "1.12.4"
5
+ JQUERY_2_VERSION = "2.2.4"
6
+ JQUERY_3_VERSION = "3.1.1"
7
+ JQUERY_UJS_VERSION = "1.2.2"
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ require_relative 'test_helper'
2
+ require_relative '../lib/jquery/assert_select'
3
+
4
+ class AssertSelectJQueryTest < ActiveSupport::TestCase
5
+ include Rails::Dom::Testing::Assertions::SelectorAssertions
6
+ attr_reader :response
7
+
8
+ JAVASCRIPT_TEST_OUTPUT = <<-JS
9
+ $("#card").show("blind", 1000);
10
+ $("#id").html('<div><p>something</p></div>');
11
+ jQuery("#id").replaceWith("<div><p>something</p></div>");
12
+ $("<div><p>something</p></div>").appendTo("#id");
13
+ jQuery("<div><p>something</p></div>").prependTo("#id");
14
+ $('#id').remove();
15
+ jQuery("#id").hide();
16
+ JS
17
+
18
+ setup do
19
+ @response = OpenStruct.new(content_type: 'text/javascript', body: JAVASCRIPT_TEST_OUTPUT)
20
+ end
21
+
22
+ def test_target_as_receiver
23
+ assert_nothing_raised do
24
+ assert_select_jquery :show, :blind, '#card'
25
+ assert_select_jquery :html, '#id' do
26
+ assert_select 'p', 'something'
27
+ end
28
+ assert_select_jquery :replaceWith, '#id' do
29
+ assert_select 'p', 'something'
30
+ end
31
+ end
32
+
33
+ assert_raise Minitest::Assertion, "No JQuery call matches [:show, :some_wrong]" do
34
+ assert_select_jquery :show, :some_wrong
35
+ end
36
+ end
37
+
38
+ def test_target_as_argument
39
+ assert_nothing_raised do
40
+ assert_select_jquery :appendTo, '#id' do
41
+ assert_select 'p', 'something'
42
+ end
43
+ assert_select_jquery :prependTo, '#id' do
44
+ assert_select 'p', 'something'
45
+ end
46
+ end
47
+
48
+ assert_raise Minitest::Assertion, 'No JQuery call matches [:prependTo, "#wrong_id"]' do
49
+ assert_select_jquery :prependTo, '#wrong_id'
50
+ end
51
+ end
52
+
53
+ def test_argumentless
54
+ assert_nothing_raised do
55
+ assert_select_jquery :remove
56
+ assert_select_jquery :hide
57
+ end
58
+
59
+ assert_raise Minitest::Assertion, 'No JQuery call matches [:wrong_function]' do
60
+ assert_select_jquery :wrong_function
61
+ end
62
+ end
63
+ end