unobtrusive_flash 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +15 -4
  4. data/Appraisals +25 -0
  5. data/CHANGELOG.md +10 -1
  6. data/README.markdown +56 -22
  7. data/Rakefile +6 -0
  8. data/gemfiles/rails_3.2.gemfile +8 -0
  9. data/gemfiles/rails_3.2.gemfile.lock +155 -0
  10. data/gemfiles/rails_4.0.gemfile +10 -0
  11. data/gemfiles/rails_4.0.gemfile.lock +153 -0
  12. data/gemfiles/rails_4.1.gemfile +10 -0
  13. data/gemfiles/rails_4.1.gemfile.lock +159 -0
  14. data/gemfiles/rails_4.2.gemfile +10 -0
  15. data/gemfiles/rails_4.2.gemfile.lock +181 -0
  16. data/lib/assets/javascripts/unobtrusive_flash.js +16 -10
  17. data/lib/assets/javascripts/unobtrusive_flash_bootstrap.js +6 -4
  18. data/lib/assets/javascripts/unobtrusive_flash_ui.js +8 -5
  19. data/lib/unobtrusive_flash/version.rb +1 -1
  20. data/spec/integration/api_spec.rb +12 -0
  21. data/spec/integration/bootstrap_spec.rb +23 -0
  22. data/spec/integration/turbolinks_spec.rb +23 -0
  23. data/spec/integration/ui_spec.rb +10 -0
  24. data/spec/spec_helper.rb +18 -1
  25. data/spec/support/assets/javascripts/ajax_caller.js +4 -0
  26. data/spec/support/assets/javascripts/api.js +12 -0
  27. data/spec/support/assets/javascripts/bootstrap.js +4 -0
  28. data/spec/support/assets/javascripts/jquery_turbolinks_application.js +5 -0
  29. data/spec/support/assets/javascripts/turbolinks_application.js +11 -0
  30. data/spec/support/assets/javascripts/ui.js +4 -0
  31. data/spec/support/rails_app.rb +57 -0
  32. data/spec/support/views/test/api.html.erb +8 -0
  33. data/spec/support/views/test/bootstrap.html.erb +9 -0
  34. data/spec/support/views/test/jquery_turbolinks.html.erb +10 -0
  35. data/spec/support/views/test/turbolinks.html.erb +9 -0
  36. data/spec/support/views/test/turbolinks_target.html.erb +3 -0
  37. data/spec/support/views/test/ui.html.erb +8 -0
  38. data/unobtrusive_flash.gemspec +8 -2
  39. metadata +106 -7
@@ -4,8 +4,7 @@
4
4
  // Shows flash messages as translucent bars on top of the page
5
5
  window.UnobtrusiveFlash.flashOptions = {type: 'notice', timeout: 0};
6
6
 
7
- $(function() {
8
- $('<div id="unobtrusive-flash-messages"></div>').prependTo('body');
7
+ (function(){
9
8
 
10
9
  function hideFlash($flash) {
11
10
  $flash.slideUp(100,function(){
@@ -17,8 +16,11 @@ $(function() {
17
16
  options = $.extend(UnobtrusiveFlash.flashOptions, options);
18
17
 
19
18
  var $flash = $('<div class="unobtrusive-flash-message-wrapper unobtrusive-flash-'+options.type+'"><div class="unobtrusive-flash-message">'+message+'</div></div>');
20
-
21
- $('#unobtrusive-flash-messages').prepend($flash);
19
+ var $flashContainer = $('#unobtrusive-flash-messages');
20
+ if ($flashContainer.length==0) {
21
+ $flashContainer = $('<div/>').attr('id', 'unobtrusive-flash-messages').prependTo('body');
22
+ }
23
+ $flashContainer.prepend($flash);
22
24
  $flash.hide().delay(300).slideDown(100);
23
25
 
24
26
  $flash.click(function() {
@@ -37,4 +39,5 @@ $(function() {
37
39
  };
38
40
 
39
41
  $(window).bind('rails:flash', flashHandler);
40
- });
42
+
43
+ })();
@@ -1,3 +1,3 @@
1
1
  module UnobtrusiveFlash
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "api spec", type: :feature, js: true do
4
+ it 'should invoke the API for each flash message' do
5
+ visit '/test/api'
6
+ expect(page).to have_content 'Page loaded'
7
+ expect(evaluate_script('window.flashMessages')).to eq [
8
+ {'type' => 'notice', 'message' => 'Inline Notice'},
9
+ {'type' => 'error', 'message' => 'Ajax Error'}
10
+ ]
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "bootstrap spec", type: :feature, js: true do
4
+ it 'should show each flash message' do
5
+ visit '/test/bootstrap'
6
+ expect(page).to have_content 'Page loaded'
7
+ expect(page).to have_content 'Inline Notice', count: 1
8
+ expect(page).to have_content 'Ajax Error', count: 1
9
+ end
10
+
11
+ it 'should translate rails message types into bootstrap alert classes' do
12
+ visit '/test/bootstrap'
13
+ expect(page).to have_content 'Page loaded'
14
+ within('.alert.alert-info') { expect(page).to have_content 'Inline Notice' }
15
+ end
16
+
17
+ it 'should bind close buttons for the messages' do
18
+ visit '/test/bootstrap'
19
+ expect(page).to have_content 'Inline Notice'
20
+ find('.alert.alert-info .close').click
21
+ expect(page).to have_no_content 'Inline Notice'
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ if Rails.version =~ /^4\./ and Capybara.javascript_driver == :selenium
4
+ describe "turbolinks spec", type: :feature, js: true do
5
+ it 'should invoke the API for each flash message' do
6
+ visit '/test/turbolinks'
7
+ click_link 'This is a turbolink'
8
+ expect(page).to have_content 'Turbolink content'
9
+ expect(evaluate_script('window.flashMessages')).to eq [
10
+ {'type' => 'notice', 'message' => 'Inline Notice'},
11
+ {'type' => 'notice', 'message' => 'Turbolink Notice'}
12
+ ]
13
+ end
14
+
15
+ it 'should not duplicate messages when using the jquery.turbolinks plugin' do
16
+ visit '/test/jquery_turbolinks'
17
+ click_link 'This is a turbolink'
18
+ click_link 'One more turbolink'
19
+ expect(page).to have_content 'Turbolink content'
20
+ expect(page).to have_content 'Turbolink Notice', count: 1
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ui spec", type: :feature, js: true do
4
+ it 'should show each flash message' do
5
+ visit '/test/ui'
6
+ expect(page).to have_content 'Page loaded'
7
+ expect(page).to have_content 'Inline Notice', count: 1
8
+ expect(page).to have_content 'Ajax Error', count: 1
9
+ end
10
+ end
@@ -1,3 +1,20 @@
1
1
  require 'bundler'
2
2
  require 'rspec'
3
- require 'unobtrusive_flash'
3
+ require 'capybara/rspec'
4
+
5
+ ENV['JQUERY_VERSION'] ||= '2.1.1'
6
+
7
+ require 'rails'
8
+ require 'unobtrusive_flash'
9
+ require 'support/rails_app'
10
+
11
+ Capybara.app = TestApp
12
+
13
+ if ENV['TRAVIS']
14
+ # Selenium not available on TraviS CI without many pains.
15
+ require 'capybara/poltergeist'
16
+ Capybara.javascript_driver = :poltergeist
17
+ else
18
+ # But Selenium supports turbolinks and PhantomJS does not
19
+ Capybara.javascript_driver = :selenium
20
+ end
@@ -0,0 +1,4 @@
1
+ $(function() {
2
+ $.get('/test/ajax_flash');
3
+ $('<span>Page loaded</span>').appendTo('body');
4
+ });
@@ -0,0 +1,12 @@
1
+ //=require jquery_ujs
2
+ //=require unobtrusive_flash
3
+ //=require ajax_caller
4
+ //=require_self
5
+
6
+ // simple handler to log all flashes into a variable accessible from the test suite
7
+ loggingFlashHandler = function(e, params) {
8
+ if (typeof(window.flashMessages) == 'undefined') window.flashMessages = [];
9
+ window.flashMessages.push(params);
10
+ };
11
+
12
+ $(window).bind('rails:flash', loggingFlashHandler);
@@ -0,0 +1,4 @@
1
+ //=require jquery_ujs
2
+ //=require unobtrusive_flash
3
+ //=require unobtrusive_flash_bootstrap
4
+ //=require ajax_caller
@@ -0,0 +1,5 @@
1
+ //=require jquery.turbolinks
2
+ //=require jquery_ujs
3
+ //=require unobtrusive_flash
4
+ //=require unobtrusive_flash_bootstrap
5
+ //=require turbolinks
@@ -0,0 +1,11 @@
1
+ //=require turbolinks
2
+ //=require unobtrusive_flash
3
+ //=require_self
4
+
5
+ // simple handler to log all flashes into a variable accessible from the test suite
6
+ loggingFlashHandler = function(e, params) {
7
+ if (typeof(window.flashMessages) == 'undefined') window.flashMessages = [];
8
+ window.flashMessages.push(params);
9
+ };
10
+
11
+ $(window).bind('rails:flash', loggingFlashHandler);
@@ -0,0 +1,4 @@
1
+ //=require jquery_ujs
2
+ //=require unobtrusive_flash
3
+ //=require unobtrusive_flash_ui
4
+ //=require ajax_caller
@@ -0,0 +1,57 @@
1
+ # From https://gist.github.com/josevalim/1942658
2
+
3
+ require 'rails'
4
+ require 'action_controller/railtie'
5
+ require 'sprockets/railtie'
6
+ require 'jquery-rails'
7
+ if Rails.version =~ /^4\./
8
+ require 'turbolinks'
9
+ require 'jquery-turbolinks'
10
+ end
11
+
12
+
13
+ class TestApp < Rails::Application
14
+ routes.append do
15
+ %w(api ui bootstrap ajax_flash turbolinks jquery_turbolinks turbolinks_target).each do |action|
16
+ get "/test/#{action}" => "test##{action}"
17
+ end
18
+ end
19
+
20
+ # Enable cache classes. Production style.
21
+ config.cache_classes = true
22
+ config.eager_load = false
23
+
24
+ config.logger = Logger.new(STDOUT)
25
+ config.action_controller.view_paths = [ File.expand_path(__FILE__ + '/../views') ]
26
+ config.assets.paths = [ File.expand_path(__FILE__ + '/../assets/javascripts') ]
27
+ config.assets.enabled = true
28
+ config.assets.compile = true
29
+
30
+ config.middleware.delete "Rack::Lock"
31
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
32
+
33
+ # We need a secret token for session, cookies, etc.
34
+ config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
35
+ end
36
+
37
+ class TestController < ActionController::Base
38
+ layout false
39
+ before_filter :set_inline_flash, except: %w(ajax_flash turbolinks_target)
40
+ after_filter :prepare_unobtrusive_flash
41
+
42
+ def turbolinks_target
43
+ flash[:notice] = 'Turbolink Notice'
44
+ end
45
+
46
+ def ajax_flash
47
+ flash[:error] = 'Ajax Error'
48
+ head :ok
49
+ end
50
+
51
+ def set_inline_flash
52
+ flash[:notice] = 'Inline Notice'
53
+ end
54
+ end
55
+
56
+ # Initialize the app (originally in config/environment.rb)
57
+ TestApp.initialize!
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <%=javascript_include_tag "http://code.jquery.com/jquery-#{ENV['JQUERY_VERSION']}.min.js" %>
4
+ <%=javascript_include_tag "api" %>
5
+ </head>
6
+ <body>
7
+ </body>
8
+ </html>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <%=javascript_include_tag "http://code.jquery.com/jquery-#{ENV['JQUERY_VERSION']}.min.js" %>
4
+ <%=javascript_include_tag "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" %>
5
+ <%=javascript_include_tag "bootstrap" %>
6
+ </head>
7
+ <body>
8
+ </body>
9
+ </html>
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <%=javascript_include_tag "http://code.jquery.com/jquery-#{ENV['JQUERY_VERSION']}.min.js" %>
4
+ <%=javascript_include_tag "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" %>
5
+ <%=javascript_include_tag "jquery_turbolinks_application" %>
6
+ </head>
7
+ <body>
8
+ <a href="/test/turbolinks_target">This is a turbolink</a>
9
+ </body>
10
+ </html>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <%=javascript_include_tag "http://code.jquery.com/jquery-#{ENV['JQUERY_VERSION']}.min.js" %>
4
+ <%=javascript_include_tag "turbolinks_application" %>
5
+ </head>
6
+ <body>
7
+ <a href="/test/turbolinks_target">This is a turbolink</a>
8
+ </body>
9
+ </html>
@@ -0,0 +1,3 @@
1
+ Turbolink content
2
+
3
+ <a href="/test/turbolinks_target">One more turbolink</a>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <%=javascript_include_tag "http://code.jquery.com/jquery-#{ENV['JQUERY_VERSION']}.min.js" %>
4
+ <%=javascript_include_tag "ui" %>
5
+ </head>
6
+ <body>
7
+ </body>
8
+ </html>
@@ -25,6 +25,12 @@ EOT
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec", '>=3'
29
- spec.add_development_dependency "rspec-mocks", '>=3'
28
+ spec.add_development_dependency "rspec", '~>3'
29
+ spec.add_development_dependency "rspec-mocks", '~>3'
30
+ spec.add_development_dependency "appraisal"
31
+ spec.add_development_dependency "capybara", '>=2.5'
32
+ # for local tests
33
+ spec.add_development_dependency 'selenium-webdriver'
34
+ # for Travis CI
35
+ spec.add_development_dependency 'poltergeist'
30
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtrusive_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Shevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -56,30 +56,86 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-mocks
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: capybara
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '2.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '2.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: selenium-webdriver
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: poltergeist
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: |
84
140
  unobtrusive_flash takes your flash messages for the backend and automagically passes them to the frontend via HTTP cookies.
85
141
  This works with both regular page loads and AJAX requests, does not tamper with the page body and requires about 3 extra
@@ -92,10 +148,19 @@ extra_rdoc_files: []
92
148
  files:
93
149
  - ".gitignore"
94
150
  - ".travis.yml"
151
+ - Appraisals
95
152
  - CHANGELOG.md
96
153
  - Gemfile
97
154
  - README.markdown
98
155
  - Rakefile
156
+ - gemfiles/rails_3.2.gemfile
157
+ - gemfiles/rails_3.2.gemfile.lock
158
+ - gemfiles/rails_4.0.gemfile
159
+ - gemfiles/rails_4.0.gemfile.lock
160
+ - gemfiles/rails_4.1.gemfile
161
+ - gemfiles/rails_4.1.gemfile.lock
162
+ - gemfiles/rails_4.2.gemfile
163
+ - gemfiles/rails_4.2.gemfile.lock
99
164
  - lib/assets/javascripts/unobtrusive_flash.js
100
165
  - lib/assets/javascripts/unobtrusive_flash_bootstrap.js
101
166
  - lib/assets/javascripts/unobtrusive_flash_ui.js
@@ -105,8 +170,25 @@ files:
105
170
  - lib/unobtrusive_flash/engine.rb
106
171
  - lib/unobtrusive_flash/version.rb
107
172
  - spec/domain_spec.rb
173
+ - spec/integration/api_spec.rb
174
+ - spec/integration/bootstrap_spec.rb
175
+ - spec/integration/turbolinks_spec.rb
176
+ - spec/integration/ui_spec.rb
108
177
  - spec/sanitize_flash_spec.rb
109
178
  - spec/spec_helper.rb
179
+ - spec/support/assets/javascripts/ajax_caller.js
180
+ - spec/support/assets/javascripts/api.js
181
+ - spec/support/assets/javascripts/bootstrap.js
182
+ - spec/support/assets/javascripts/jquery_turbolinks_application.js
183
+ - spec/support/assets/javascripts/turbolinks_application.js
184
+ - spec/support/assets/javascripts/ui.js
185
+ - spec/support/rails_app.rb
186
+ - spec/support/views/test/api.html.erb
187
+ - spec/support/views/test/bootstrap.html.erb
188
+ - spec/support/views/test/jquery_turbolinks.html.erb
189
+ - spec/support/views/test/turbolinks.html.erb
190
+ - spec/support/views/test/turbolinks_target.html.erb
191
+ - spec/support/views/test/ui.html.erb
110
192
  - unobtrusive_flash.gemspec
111
193
  homepage: https://github.com/leonid-shevtsov/unobtrusive_flash
112
194
  licenses: []
@@ -127,11 +209,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
209
  version: '0'
128
210
  requirements: []
129
211
  rubyforge_project:
130
- rubygems_version: 2.2.2
212
+ rubygems_version: 2.4.5
131
213
  signing_key:
132
214
  specification_version: 4
133
215
  summary: Unobtrusive flash messages for Rails
134
216
  test_files:
135
217
  - spec/domain_spec.rb
218
+ - spec/integration/api_spec.rb
219
+ - spec/integration/bootstrap_spec.rb
220
+ - spec/integration/turbolinks_spec.rb
221
+ - spec/integration/ui_spec.rb
136
222
  - spec/sanitize_flash_spec.rb
137
223
  - spec/spec_helper.rb
224
+ - spec/support/assets/javascripts/ajax_caller.js
225
+ - spec/support/assets/javascripts/api.js
226
+ - spec/support/assets/javascripts/bootstrap.js
227
+ - spec/support/assets/javascripts/jquery_turbolinks_application.js
228
+ - spec/support/assets/javascripts/turbolinks_application.js
229
+ - spec/support/assets/javascripts/ui.js
230
+ - spec/support/rails_app.rb
231
+ - spec/support/views/test/api.html.erb
232
+ - spec/support/views/test/bootstrap.html.erb
233
+ - spec/support/views/test/jquery_turbolinks.html.erb
234
+ - spec/support/views/test/turbolinks.html.erb
235
+ - spec/support/views/test/turbolinks_target.html.erb
236
+ - spec/support/views/test/ui.html.erb