responders 0.9.3 → 1.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de01024464852eb08914a193b19d0f915877c0ac
4
+ data.tar.gz: 6df0e03ed0128f02e604e86b41b633fbc374ddfc
5
+ SHA512:
6
+ metadata.gz: a7eeff649c82736af6c3873899d731395014acca97a914db15069d9d94d64fb84912a7fa8646535118e3816190174a6bf378bdd252abe7d6ee966ec8d1253ca8
7
+ data.tar.gz: 3b78f0a5d481abf8b667613355e064f586b1918890c8a04c216ef99283433b74f362bbe5ff724480b40a5b9027031c73f66b9dfb759c557bb31c9916f12fa469
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.0.0.rc
2
+
3
+ * Drop support for Rails 3.1 and Ruby 1.8, keep support for Rails 3.2
4
+ * Support for Rails 4.0 onward
5
+ * Fix flash message on destroy failure. Fixes #61
6
+
1
7
  ## 0.9.3
2
8
 
3
9
  * Fix url generation for namespaced models
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Responders
2
2
 
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/responders.png)](http://badge.fury.io/rb/responders)
4
+ [![Build Status](https://api.travis-ci.org/plataformatec/responders.png?branch=master)](http://travis-ci.org/plataformatec/responders)
5
+ [![Code Climate](https://codeclimate.com/github/plataformatec/responders.png)](https://codeclimate.com/github/plataformatec/responders)
6
+
3
7
  A set of responders modules to dry up your Rails 3+ app.
4
8
 
5
9
  ## Responders Types
@@ -24,7 +28,8 @@ does not contain errors, it will automatically set the flash message to
24
28
  ```
25
29
 
26
30
  In case the resource contains errors, you should use the failure key on I18n. This is
27
- useful to dry up flash messages from your controllers. If you need a specific message
31
+ useful to dry up flash messages from your controllers. Note: by default alerts for `update`
32
+ and `destroy` actions are commented in generated I18n file. If you need a specific message
28
33
  for a controller, let's say, for `PostsController`, you can also do:
29
34
 
30
35
  ```yaml
@@ -119,6 +124,29 @@ class InvitationsController < ApplicationController
119
124
  end
120
125
  ```
121
126
 
127
+ ## Interpolation Options
128
+
129
+ You can pass in extra interpolation options for the translation by adding an `interpolation_options` method to your controller:
130
+
131
+ ```ruby
132
+ class InvitationsController < ApplicationController
133
+ responders :flash, :http_cache
134
+
135
+ def create
136
+ @invitation = Invitation.create(params[:invitation])
137
+ respond_with @invitation
138
+ end
139
+
140
+ private
141
+
142
+ def interpolation_options
143
+ { resource_name: @invitation.email }
144
+ end
145
+ end
146
+ ```
147
+
148
+ Now you would see the message "bob@bob.com was successfully created" instead of the default "Invitation was successfully created."
149
+
122
150
  ## Generator
123
151
 
124
152
  This gem also includes a responders controller generator, so your scaffold can be customized
@@ -135,7 +135,8 @@ module Responders
135
135
  end
136
136
 
137
137
  def set_flash_now?
138
- (@flash_now == true) || (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success) || (format == :js)
138
+ @flash_now == true || format == :js ||
139
+ (default_action && (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success))
139
140
  end
140
141
 
141
142
  def set_flash_message? #:nodoc:
@@ -3,8 +3,10 @@ en:
3
3
  actions:
4
4
  create:
5
5
  notice: '%{resource_name} was successfully created.'
6
+ # alert: '%{resource_name} could not be created.'
6
7
  update:
7
8
  notice: '%{resource_name} was successfully updated.'
9
+ # alert: '%{resource_name} could not be updated.'
8
10
  destroy:
9
11
  notice: '%{resource_name} was successfully destroyed.'
10
- alert: '%{resource_name} could not be destroyed.'
12
+ alert: '%{resource_name} could not be destroyed.'
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.9.3".freeze
2
+ VERSION = "1.0.0.rc".freeze
3
3
  end
@@ -28,7 +28,7 @@ class CollectionController < ApplicationController
28
28
  end
29
29
 
30
30
  def isolated_namespace
31
- respond_with MyEngine::Business.new
31
+ respond_with MyEngine::Business
32
32
  end
33
33
 
34
34
  def uncountable
@@ -174,6 +174,12 @@ class FlashResponderTest < ActionController::TestCase
174
174
  assert_flash_now :failure
175
175
  end
176
176
 
177
+ def test_does_not_set_flash_message_to_now_with_errors_and_redirect
178
+ delete :with_html, :fail => true
179
+ assert_not_flash_now :failure
180
+ assert_equal "<strong>OH NOES!</strong> You did it wrong!", flash[:failure]
181
+ end
182
+
177
183
  def test_never_set_flash_now
178
184
  post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
179
185
  assert_not_flash_now :failure
@@ -181,13 +187,13 @@ class FlashResponderTest < ActionController::TestCase
181
187
 
182
188
  # If we have flash.now, it's always marked as used.
183
189
  def assert_flash_now(k)
184
- assert flash.instance_variable_get(:@used).to_a.include?(k.to_sym),
190
+ assert flash.used_keys.include?(k.to_sym),
185
191
  "Expected #{k} to be in flash.now, but it's not."
186
192
  end
187
193
 
188
194
  def assert_not_flash_now(k)
189
195
  assert flash[k], "Expected #{k} to be set"
190
- assert !flash.instance_variable_get(:@used).include?(k.to_sym),
196
+ assert !flash.used_keys.include?(k.to_sym),
191
197
  "Expected #{k} to not be in flash.now, but it is."
192
198
  end
193
199
  end
@@ -51,7 +51,7 @@ class HttpCacheResponderTest < ActionController::TestCase
51
51
  @request.env["HTTP_IF_MODIFIED_SINCE"] = Time.utc(2009, 6).httpdate
52
52
  get :single
53
53
  assert_equal 304, @response.status
54
- assert_equal " ", @response.body
54
+ assert_includes [" ", ""], @response.body
55
55
  end
56
56
 
57
57
  def test_refreshes_last_modified_if_cache_is_expired
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ require 'bundler'
3
3
 
4
4
  Bundler.setup
5
5
  require 'test/unit'
6
- require 'mocha'
6
+ require 'mocha/setup'
7
7
 
8
8
  # Configure Rails
9
9
  ENV["RAILS_ENV"] = "test"
@@ -11,6 +11,7 @@ ENV["RAILS_ENV"] = "test"
11
11
  require 'active_support'
12
12
  require 'action_controller'
13
13
  require 'active_model'
14
+ require 'rails/engine'
14
15
  require 'rails/railtie'
15
16
 
16
17
  $:.unshift File.expand_path('../../lib', __FILE__)
@@ -22,8 +23,8 @@ I18n.reload!
22
23
  Responders::Routes = ActionDispatch::Routing::RouteSet.new
23
24
  Responders::Routes.draw do
24
25
  resources :news
25
- match '/admin/:action', :controller => "admin/addresses"
26
- match '/:controller(/:action(/:id))'
26
+ get '/admin/:action', :controller => "admin/addresses"
27
+ get '/:controller(/:action(/:id))'
27
28
  end
28
29
 
29
30
  class ApplicationController < ActionController::Base
@@ -39,6 +40,17 @@ class ActiveSupport::TestCase
39
40
  end
40
41
  end
41
42
 
43
+ module ActionDispatch
44
+ class Flash
45
+ class FlashHash
46
+ def used_keys
47
+ # Rails 3 || Rails 4
48
+ @used || @discard
49
+ end
50
+ end
51
+ end
52
+ end
53
+
42
54
  class Model
43
55
  include ActiveModel::Conversion
44
56
  include ActiveModel::Validations
@@ -70,10 +82,8 @@ class News < Model
70
82
  end
71
83
 
72
84
  module MyEngine
73
- def self.use_relative_model_naming?
74
- true
75
- end
76
-
77
- class Business < Model
85
+ class Business < Rails::Engine
86
+ isolate_namespace MyEngine
87
+ extend ActiveModel::Naming
78
88
  end
79
89
  end
metadata CHANGED
@@ -1,58 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
5
- prerelease:
4
+ version: 1.0.0.rc
6
5
  platform: ruby
7
6
  authors:
8
7
  - José Valim
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
11
+ date: 2013-05-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: railties
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '3.1'
19
+ version: '3.2'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ~>
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - <
28
31
  - !ruby/object:Gem::Version
29
- version: '3.1'
30
- description: A set of Rails 3 responders to dry up your application
32
+ version: '5'
33
+ description: A set of Rails responders to dry up your application
31
34
  email: contact@plataformatec.com.br
32
35
  executables: []
33
36
  extensions: []
34
37
  extra_rdoc_files: []
35
38
  files:
36
- - .travis.yml
37
39
  - CHANGELOG.md
38
- - Gemfile
39
- - Gemfile.lock
40
40
  - MIT-LICENSE
41
41
  - README.md
42
- - Rakefile
43
- - gemfiles/Gemfile-rails.3.1.x
44
- - lib/generators/rails/USAGE
45
42
  - lib/generators/rails/responders_controller_generator.rb
46
43
  - lib/generators/rails/templates/controller.rb
44
+ - lib/generators/rails/USAGE
47
45
  - lib/generators/responders/install_generator.rb
48
- - lib/responders.rb
49
46
  - lib/responders/collection_responder.rb
50
47
  - lib/responders/controller_method.rb
51
48
  - lib/responders/flash_responder.rb
52
49
  - lib/responders/http_cache_responder.rb
53
50
  - lib/responders/locales/en.yml
54
51
  - lib/responders/version.rb
55
- - responders.gemspec
52
+ - lib/responders.rb
56
53
  - test/collection_responder_test.rb
57
54
  - test/controller_method_test.rb
58
55
  - test/flash_responder_test.rb
@@ -63,29 +60,29 @@ files:
63
60
  - test/views/addresses/edit.html.erb
64
61
  - test/views/addresses/new.html.erb
65
62
  homepage: http://github.com/plataformatec/responders
66
- licenses: []
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
67
66
  post_install_message:
68
67
  rdoc_options: []
69
68
  require_paths:
70
69
  - lib
71
70
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
71
  requirements:
74
- - - ! '>='
72
+ - - '>='
75
73
  - !ruby/object:Gem::Version
76
74
  version: '0'
77
75
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
76
  requirements:
80
- - - ! '>='
77
+ - - '>'
81
78
  - !ruby/object:Gem::Version
82
- version: '0'
79
+ version: 1.3.1
83
80
  requirements: []
84
81
  rubyforge_project: responders
85
- rubygems_version: 1.8.23
82
+ rubygems_version: 2.0.3
86
83
  signing_key:
87
- specification_version: 3
88
- summary: A set of Rails 3 responders to dry up your application
84
+ specification_version: 4
85
+ summary: A set of Rails responders to dry up your application
89
86
  test_files:
90
87
  - test/collection_responder_test.rb
91
88
  - test/controller_method_test.rb
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - ree
5
- - jruby-18mode
6
- gemfile:
7
- - gemfiles/Gemfile-rails.3.1.x
8
- - Gemfile
9
- notifications:
10
- recipients:
11
- - jose.valim@plataformatec.com.br
12
- - carlos@plataformatec.com.br
13
- - rafael.franca@plataformatec.com.br
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
4
-
5
- # Fixed 3.2.1 because 3.2.2 is broken
6
- gem 'railties', '~> 3.2.3'
7
-
8
- gem 'mocha'
9
-
10
- gem 'ruby-debug', :platform => :mri_18
data/Gemfile.lock DELETED
@@ -1,76 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- responders (0.9.3)
5
- railties (~> 3.1)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionpack (3.2.8)
11
- activemodel (= 3.2.8)
12
- activesupport (= 3.2.8)
13
- builder (~> 3.0.0)
14
- erubis (~> 2.7.0)
15
- journey (~> 1.0.4)
16
- rack (~> 1.4.0)
17
- rack-cache (~> 1.2)
18
- rack-test (~> 0.6.1)
19
- sprockets (~> 2.1.3)
20
- activemodel (3.2.8)
21
- activesupport (= 3.2.8)
22
- builder (~> 3.0.0)
23
- activesupport (3.2.8)
24
- i18n (~> 0.6)
25
- multi_json (~> 1.0)
26
- builder (3.0.3)
27
- columnize (0.3.6)
28
- erubis (2.7.0)
29
- hike (1.2.1)
30
- i18n (0.6.1)
31
- journey (1.0.4)
32
- json (1.7.5)
33
- linecache (0.46)
34
- rbx-require-relative (> 0.0.4)
35
- metaclass (0.0.1)
36
- mocha (0.10.4)
37
- metaclass (~> 0.0.1)
38
- multi_json (1.3.6)
39
- rack (1.4.1)
40
- rack-cache (1.2)
41
- rack (>= 0.4)
42
- rack-ssl (1.3.2)
43
- rack
44
- rack-test (0.6.2)
45
- rack (>= 1.0)
46
- railties (3.2.8)
47
- actionpack (= 3.2.8)
48
- activesupport (= 3.2.8)
49
- rack-ssl (~> 1.3.2)
50
- rake (>= 0.8.7)
51
- rdoc (~> 3.4)
52
- thor (>= 0.14.6, < 2.0)
53
- rake (0.9.2.2)
54
- rbx-require-relative (0.0.9)
55
- rdoc (3.12)
56
- json (~> 1.4)
57
- ruby-debug (0.10.4)
58
- columnize (>= 0.1)
59
- ruby-debug-base (~> 0.10.4.0)
60
- ruby-debug-base (0.10.4)
61
- linecache (>= 0.3)
62
- sprockets (2.1.3)
63
- hike (~> 1.2)
64
- rack (~> 1.0)
65
- tilt (~> 1.1, != 1.3.0)
66
- thor (0.16.0)
67
- tilt (1.3.3)
68
-
69
- PLATFORMS
70
- ruby
71
-
72
- DEPENDENCIES
73
- mocha
74
- railties (~> 3.2.3)
75
- responders!
76
- ruby-debug
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- require 'rake/testtask'
6
- require 'rdoc/task'
7
- require File.join(File.dirname(__FILE__), 'lib', 'responders', 'version')
8
-
9
- desc 'Default: run unit tests'
10
- task :default => :test
11
-
12
- desc 'Test Responders'
13
- Rake::TestTask.new(:test) do |t|
14
- t.libs << 'test'
15
- t.pattern = 'test/**/*_test.rb'
16
- t.verbose = true
17
- end
18
-
19
- desc 'Generate documentation for Responders'
20
- Rake::RDocTask.new(:rdoc) do |rdoc|
21
- rdoc.rdoc_dir = 'rdoc'
22
- rdoc.title = 'Responders'
23
- rdoc.options << '--line-numbers' << '--inline-source'
24
- rdoc.rdoc_files.include('README.rdoc')
25
- rdoc.rdoc_files.include('lib/**/*.rb')
26
- end
@@ -1,6 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'responders', :path => '..'
4
-
5
- gem 'railties', '~> 3.1.0'
6
- gem 'mocha'
data/responders.gemspec DELETED
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "responders/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "responders"
7
- s.version = Responders::VERSION.dup
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = "A set of Rails 3 responders to dry up your application"
10
- s.email = "contact@plataformatec.com.br"
11
- s.homepage = "http://github.com/plataformatec/responders"
12
- s.description = "A set of Rails 3 responders to dry up your application"
13
- s.authors = ['José Valim']
14
-
15
- s.rubyforge_project = "responders"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.require_paths = ["lib"]
20
-
21
- s.add_dependency "railties", "~> 3.1"
22
- end