http-error 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +1 -0
  3. data/{easier-instance-variable-access/LICENSE → LICENSE} +4 -2
  4. data/README.markdown +43 -0
  5. data/http-error.gemspec +17 -0
  6. data/lib/cody_robbins/http_error/instance_methods.rb +36 -0
  7. data/{http-error/lib → lib}/cody_robbins/http_error/railtie.rb +0 -0
  8. data/{http-error/lib → lib}/http-error.rb +0 -0
  9. metadata +17 -46
  10. data/classifyize-1.0.gem +0 -0
  11. data/classifyize/LICENSE +0 -8
  12. data/classifyize/classifyize.gemspec +0 -15
  13. data/classifyize/lib/classifyize.rb +0 -6
  14. data/classifyize/lib/cody_robbins/classifyize.rb +0 -7
  15. data/classifyize/spec/classifyize_spec.rb +0 -7
  16. data/easier-instance-variable-access-1.0.gem +0 -0
  17. data/easier-instance-variable-access/easier-instance-variable-access.gemspec +0 -13
  18. data/easier-instance-variable-access/lib/cody_robbins/easier_instance_variable_access.rb +0 -18
  19. data/easier-instance-variable-access/lib/easier-instance-variable-access.rb +0 -3
  20. data/easier-instance-variable-access/spec/easier_instance_variable_access_spec.rb +0 -44
  21. data/http-error/Gemfile +0 -4
  22. data/http-error/Gemfile.lock +0 -86
  23. data/http-error/LICENSE +0 -8
  24. data/http-error/README +0 -48
  25. data/http-error/http-error.gemspec +0 -13
  26. data/http-error/lib/cody_robbins/http_error/instance_methods.rb +0 -14
  27. data/http-error/spec/http_error_spec.rb +0 -28
  28. data/http-error/spec/spec_helper.rb +0 -17
  29. data/lookup-record/LICENSE +0 -8
  30. data/lookup-record/lib/cody_robbins/lookup_record/class_methods.rb +0 -19
  31. data/lookup-record/lib/cody_robbins/lookup_record/railtie.rb +0 -11
  32. data/lookup-record/lib/lookup-record.rb +0 -2
  33. data/lookup-record/lookup-record.gemspec +0 -17
  34. data/lookup-record/spec/lookup_record_spec.rb +0 -77
@@ -0,0 +1,2 @@
1
+ .yardoc
2
+ doc
@@ -0,0 +1 @@
1
+ --protected --charset UTF-8 --markup markdown lib/**/*.rb - LICENSE
@@ -1,7 +1,9 @@
1
1
  The MIT License
2
- Copyright © 2011 Cody Robbins
2
+ ===============
3
3
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+ © 2011 Cody Robbins
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
7
 
6
8
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
9
 
@@ -0,0 +1,43 @@
1
+ HTTP Error for Rails
2
+ ====================
3
+
4
+ This Rails plugin makes an `http_error` method available in `ApplicationController` which
5
+
6
+ * returns the specified HTTP code in the response,
7
+ * renders the correspondingly named HTML error document in `public`, and
8
+ * returns `false`.
9
+
10
+ Returning `false` allows you to use `http_error` in `before_filter`’s to halt the filter chain.
11
+
12
+ Example
13
+ --------
14
+
15
+ The following will return a 404 HTTP code, render `public/404.html`, and halt the filter chain so that `@user.destroy!` is never executed.
16
+
17
+ class UserController < ApplicationController
18
+ before_filter(:get_user)
19
+
20
+ def delete
21
+ @user.destroy
22
+ end
23
+
24
+ protected
25
+
26
+ def get_user
27
+ @user = User.find_by_id(params[:id])
28
+ http_error(404) unless @user
29
+ end
30
+ end
31
+
32
+ Tested with
33
+ -----------
34
+
35
+ * Rails 3.0.5 — 20 May 2011
36
+
37
+ Credits
38
+ -------
39
+
40
+ © 2011 [Cody Robbins](http://codyrobbins.com/)
41
+
42
+ * [Homepage](http://codyrobbins.com/software/http-error)
43
+ * [Follow me on Twitter](http://twitter.com/codyrobbins)
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'http-error'
3
+ s.version = '1.1'
4
+ s.summary = 'Return HTTP error codes while rendering the corresponding error page in Rails.'
5
+ s.homepage = 'http://codyrobbins.com/software/http-error'
6
+ s.author = 'Cody Robbins'
7
+ s.email = 'cody@codyrobbins.com'
8
+
9
+ s.post_install_message = '
10
+ -------------------------------------------------------------
11
+ Follow me on Twitter: http://twitter.com/codyrobbins
12
+ -------------------------------------------------------------
13
+
14
+ '
15
+
16
+ s.files = `git ls-files`.split
17
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ module CodyRobbins
4
+ module HttpError
5
+ module InstanceMethods
6
+ protected
7
+
8
+ # Returns the specified HTTP code in the action’s response, renders the correspondingly named HTML error document in `public`, and returns `false`. If a corresponding HTML error document doesn’t exist, you’ll probably get some sort of exception.
9
+ #
10
+ # @param code [Integer] The HTTP status code to return—for example, 404.
11
+ # @return [boolean] Returns `false` in order to halt any filter chain it may be invoked from.
12
+ #
13
+ # @example The following will return a 404 HTTP code, render `public/404.html`, and halt the filter chain so that `@user.destroy!` is never executed.
14
+ # class UserController < ApplicationController
15
+ # before_filter(:get_user)
16
+ #
17
+ # def delete
18
+ # @user.destroy
19
+ # end
20
+ #
21
+ # protected
22
+ #
23
+ # def get_user
24
+ # @user = User.find_by_id(params[:id])
25
+ # http_error(404) unless @user
26
+ # end
27
+ # end
28
+ def http_error(code)
29
+ render(:file => Rails.root.join('public', "#{code}.html"),
30
+ :layout => false,
31
+ :status => code)
32
+ return(false)
33
+ end
34
+ end
35
+ end
36
+ end
File without changes
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-error
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- version: "1.0"
4
+ prerelease:
5
+ version: "1.1"
10
6
  platform: ruby
11
7
  authors:
12
8
  - Cody Robbins
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-05-20 00:00:00 -04:00
13
+ date: 2011-05-23 00:00:00 -04:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
@@ -27,41 +23,22 @@ extensions: []
27
23
  extra_rdoc_files: []
28
24
 
29
25
  files:
30
- - classifyize/classifyize.gemspec
31
- - classifyize/lib/classifyize.rb
32
- - classifyize/lib/cody_robbins/classifyize.rb
33
- - classifyize/LICENSE
34
- - classifyize/spec/classifyize_spec.rb
35
- - classifyize-1.0.gem
36
- - easier-instance-variable-access/easier-instance-variable-access.gemspec
37
- - easier-instance-variable-access/lib/cody_robbins/easier_instance_variable_access.rb
38
- - easier-instance-variable-access/lib/easier-instance-variable-access.rb
39
- - easier-instance-variable-access/LICENSE
40
- - easier-instance-variable-access/spec/easier_instance_variable_access_spec.rb
41
- - easier-instance-variable-access-1.0.gem
42
- - http-error/Gemfile
43
- - http-error/Gemfile.lock
44
- - http-error/http-error.gemspec
45
- - http-error/lib/cody_robbins/http_error/instance_methods.rb
46
- - http-error/lib/cody_robbins/http_error/railtie.rb
47
- - http-error/lib/http-error.rb
48
- - http-error/LICENSE
49
- - http-error/README
50
- - http-error/spec/http_error_spec.rb
51
- - http-error/spec/spec_helper.rb
52
- - lookup-record/lib/cody_robbins/lookup_record/class_methods.rb
53
- - lookup-record/lib/cody_robbins/lookup_record/railtie.rb
54
- - lookup-record/lib/lookup-record.rb
55
- - lookup-record/LICENSE
56
- - lookup-record/lookup-record.gemspec
57
- - lookup-record/spec/lookup_record_spec.rb
26
+ - .gitignore
27
+ - .yardopts
28
+ - LICENSE
29
+ - README.markdown
30
+ - http-error.gemspec
31
+ - lib/cody_robbins/http_error/instance_methods.rb
32
+ - lib/cody_robbins/http_error/railtie.rb
33
+ - lib/http-error.rb
58
34
  has_rdoc: true
59
35
  homepage: http://codyrobbins.com/software/http-error
60
36
  licenses: []
61
37
 
62
- post_install_message: |-
63
- Please follow me on Twitter!
64
- http://twitter.com/codyrobbins
38
+ post_install_message: "\n\
39
+ -------------------------------------------------------------\n\
40
+ Follow me on Twitter: http://twitter.com/codyrobbins\n\
41
+ -------------------------------------------------------------\n\n"
65
42
  rdoc_options: []
66
43
 
67
44
  require_paths:
@@ -71,25 +48,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
48
  requirements:
72
49
  - - ">="
73
50
  - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
51
  version: "0"
78
52
  required_rubygems_version: !ruby/object:Gem::Requirement
79
53
  none: false
80
54
  requirements:
81
55
  - - ">="
82
56
  - !ruby/object:Gem::Version
83
- hash: 3
84
- segments:
85
- - 0
86
57
  version: "0"
87
58
  requirements: []
88
59
 
89
60
  rubyforge_project:
90
- rubygems_version: 1.3.7
61
+ rubygems_version: 1.6.2
91
62
  signing_key:
92
63
  specification_version: 3
93
- summary: Return HTTP error codes while rendering the corresponding error page in Rails
64
+ summary: Return HTTP error codes while rendering the corresponding error page in Rails.
94
65
  test_files: []
95
66
 
Binary file
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'classifyize'
3
- s.version = '1.0'
4
- s.summary = 'Get a class from a symbol or string of its name in one fell swoop'
5
- s.homepage = 'http://codyrobbins.com/software/classifyize'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
-
14
- s.add_dependency('activesupport')
15
- end
@@ -1,6 +0,0 @@
1
- require('cody_robbins/classifyize')
2
-
3
- [[Symbol, CodyRobbins::Classifyize],
4
- [ActiveSupport::Inflector, CodyRobbins::Classifyize]].each do |target, library|
5
- target.send(:include, library)
6
- end
@@ -1,7 +0,0 @@
1
- module CodyRobbins
2
- module Classifyize
3
- def classifyize
4
- to_s.classify.constantize
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::Classifyize do
4
- it 'returns a constantized class' do
5
- :object.classifyize.should == Object
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'easier-instance-variable-access'
3
- s.version = '1.0'
4
- s.summary = 'Access instance variables in Ruby the way you should be able to'
5
- s.homepage = 'http://codyrobbins.com/software/easier-instance-variable-access'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
- end
@@ -1,18 +0,0 @@
1
- module CodyRobbins
2
- module EasierInstanceVariableAccess
3
- def get_instance_variable(name)
4
- instance_variable_get(instance_variable_name(name))
5
- end
6
- alias :instance_variable :get_instance_variable
7
-
8
- def set_instance_variable(name, value)
9
- instance_variable_set(instance_variable_name(name), value)
10
- end
11
-
12
- protected
13
-
14
- def instance_variable_name(name)
15
- "@#{name}"
16
- end
17
- end
18
- end
@@ -1,3 +0,0 @@
1
- require('cody_robbins/easier_instance_variable_access')
2
-
3
- Object.send(:include, CodyRobbins::EasierInstanceVariableAccess)
@@ -1,44 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::EasierInstanceVariableAccess do
4
- class Dummy
5
- attr_reader(:variable)
6
-
7
- def initialize
8
- @variable = 'Value'
9
- end
10
-
11
- def get_with_get_instance_variable
12
- get_instance_variable(:variable)
13
- end
14
-
15
- def get_with_instance_variable
16
- instance_variable(:variable)
17
- end
18
-
19
- def set(value)
20
- set_instance_variable(:variable, value)
21
- end
22
- end
23
-
24
- let(:dummy) { Dummy.new }
25
-
26
- describe '#get_instance_variable' do
27
- it 'returns the instance variable' do
28
- dummy.get_with_get_instance_variable.should == 'Value'
29
- end
30
- end
31
-
32
- describe '#instance_variable' do
33
- it 'returns the instance variable' do
34
- dummy.get_with_instance_variable.should == 'Value'
35
- end
36
- end
37
-
38
- describe '#set_instance_variable' do
39
- it 'sets the instance variable' do
40
- dummy.set('New value')
41
- dummy.variable.should == 'New value'
42
- end
43
- end
44
- end
@@ -1,4 +0,0 @@
1
- source('http://rubygems.org')
2
-
3
- gem('rails', '3.0.5')
4
- gem('rspec-rails')
@@ -1,86 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.5)
6
- actionpack (= 3.0.5)
7
- mail (~> 2.2.15)
8
- actionpack (3.0.5)
9
- activemodel (= 3.0.5)
10
- activesupport (= 3.0.5)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.5)
19
- activesupport (= 3.0.5)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.5)
23
- activemodel (= 3.0.5)
24
- activesupport (= 3.0.5)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.5)
28
- activemodel (= 3.0.5)
29
- activesupport (= 3.0.5)
30
- activesupport (3.0.5)
31
- arel (2.0.10)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- i18n (0.5.0)
37
- mail (2.2.19)
38
- activesupport (>= 2.3.6)
39
- i18n (>= 0.4.0)
40
- mime-types (~> 1.16)
41
- treetop (~> 1.4.8)
42
- mime-types (1.16)
43
- polyglot (0.3.1)
44
- rack (1.2.2)
45
- rack-mount (0.6.14)
46
- rack (>= 1.0.0)
47
- rack-test (0.5.7)
48
- rack (>= 1.0)
49
- rails (3.0.5)
50
- actionmailer (= 3.0.5)
51
- actionpack (= 3.0.5)
52
- activerecord (= 3.0.5)
53
- activeresource (= 3.0.5)
54
- activesupport (= 3.0.5)
55
- bundler (~> 1.0)
56
- railties (= 3.0.5)
57
- railties (3.0.5)
58
- actionpack (= 3.0.5)
59
- activesupport (= 3.0.5)
60
- rake (>= 0.8.7)
61
- thor (~> 0.14.4)
62
- rake (0.9.0)
63
- rspec (2.6.0)
64
- rspec-core (~> 2.6.0)
65
- rspec-expectations (~> 2.6.0)
66
- rspec-mocks (~> 2.6.0)
67
- rspec-core (2.6.1)
68
- rspec-expectations (2.6.0)
69
- diff-lcs (~> 1.1.2)
70
- rspec-mocks (2.6.0)
71
- rspec-rails (2.6.0)
72
- actionpack (~> 3.0)
73
- activesupport (~> 3.0)
74
- railties (~> 3.0)
75
- rspec (~> 2.6.0)
76
- thor (0.14.6)
77
- treetop (1.4.9)
78
- polyglot (>= 0.3.1)
79
- tzinfo (0.3.27)
80
-
81
- PLATFORMS
82
- ruby
83
-
84
- DEPENDENCIES
85
- rails (= 3.0.5)
86
- rspec-rails
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,48 +0,0 @@
1
- HTTP Error for Rails
2
- ====================
3
-
4
- This Rails plugin is great! It makes an `http_error` method available in `ApplicationController` which
5
-
6
- * always returns the specified HTTP error code in the response (always!),
7
- * renders with aplomb the corresponding HTML error document in `public`, and
8
- * cheerfully returns `false`.
9
-
10
- An important feature is that the cheerfulness with which `http-error` returns `false` will surely brighten your day. Returning `false` also allows you to use `http_error` at the end of a `before_filter` to halt the filter chain. While halting a filter chain has some weighty moral and ethical implications—and I myself am a stauch proponent of the self-determination of filter chains—I have to take the pro-choice stance on this issue and admit that it is everyone's prerogative to terminate their own filter chains if they so choose.
11
-
12
- Examples
13
- --------
14
-
15
- class xfeOIh8<ApplicationController;before_filter(:oaoh8r_o823y);end
16
-
17
- Haha, just kidding—this isn't Java, after all!
18
-
19
- class UserController < ApplicationController
20
- before_filter(:get_user, :before => :show)
21
-
22
- def delete
23
- @user.destroy!
24
- end
25
-
26
- protected
27
-
28
- def get_user
29
- @user = User.find_by_id(params[:user])
30
- http_error(404) unless @user
31
- end
32
- end
33
-
34
- Tested with
35
- -----------
36
-
37
- * Rails 3.0.5 — 20 May 2011.
38
-
39
- Y2K-Compliance
40
- --------------
41
-
42
- This gem is Y2K-compliant.
43
-
44
- Credits
45
- ------
46
-
47
- * Programming: Cody Robbins
48
- * Translation: Ted Woolsey
@@ -1,13 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'http-error'
3
- s.version = '1.0'
4
- s.summary = 'Return HTTP error codes while rendering the corresponding error page in Rails'
5
- s.homepage = 'http://codyrobbins.com/software/http-error'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
- end
@@ -1,14 +0,0 @@
1
- module CodyRobbins
2
- module HttpError
3
- module InstanceMethods
4
- protected
5
-
6
- def http_error(code)
7
- render(:file => Rails.root.join('public', "#{code}.html"),
8
- :layout => false,
9
- :status => code)
10
- return(false)
11
- end
12
- end
13
- end
14
- end
@@ -1,28 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::HttpError, :type => :controller do
4
- controller do
5
- def index
6
- @result = http_error(404)
7
- end
8
- end
9
-
10
- describe '#http_error' do
11
- before { get(:index) }
12
-
13
- it 'responds with the correct status code' do
14
- response.code.should == '404'
15
- end
16
-
17
- it 'renders the error document' do
18
- path = File.join(Rails.root, 'public', '404.html')
19
- page = File.open(path).read
20
-
21
- response.body.should == page
22
- end
23
-
24
- it 'returns false' do
25
- assigns(:result).should be_false
26
- end
27
- end
28
- end
@@ -1,17 +0,0 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
-
3
- # Testing apparatus.
4
- require('action_controller')
5
- require('action_dispatch')
6
- require('rspec/rails')
7
-
8
- # Load the gem.
9
- require('http-error')
10
-
11
- # We need an empty application and controller for rspec-rails to do its job.
12
- class Application < Rails::Application; end
13
- class ApplicationController < ActionController::Base; end
14
-
15
- # We also need some default routes.
16
- # http://stackoverflow.com/questions/5970811/whats-the-proper-way-to-mock-rails-3-routes-and-controllers-in-a-plugin-test
17
- Application.routes.draw do; end
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,19 +0,0 @@
1
- module CodyRobbins
2
- module LookupRecord
3
- module ClassMethods
4
- def lookup_record(name, filter_options = {})
5
- before_filter(filter_options) do
6
- model = name.classifyize
7
- id = params[:id] || params[name]
8
- object = model.find_by_id(id)
9
-
10
- if object
11
- set_instance_variable(name, object)
12
- else
13
- http_error(404)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- module CodyRobbins
2
- module LookupRecord
3
- class Railtie < Rails::Railtie
4
- initializer('cody_robbins.lookup_record') do
5
- ActiveSupport.on_load(:action_controller) do
6
- ApplicationController.send(:extend, ClassMethods)
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,2 +0,0 @@
1
- require('cody_robbins/lookup_record/class_methods')
2
- require('cody_robbins/lookup_record/railtie')
@@ -1,17 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'lookup-record'
3
- s.version = '1.0'
4
- s.summary = 'Find records for Rails controller actions declaratively'
5
- s.homepage = 'http://codyrobbins.com/software/lookup-record'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
-
14
- s.add_dependency('easiser-instance-variable-access')
15
- s.add_dependency('classifyize')
16
- s.add_dependency('http-error')
17
- end
@@ -1,77 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::LookupRecord, :type => :controller do
4
- before { there_is_a_user }
5
-
6
- describe '#lookup_record' do
7
- shared_examples_for 'Successful lookup' do
8
- it 'sets the instance variable' do
9
- assigns(:user).should == user
10
- end
11
-
12
- it 'executes the action' do
13
- response.body.should == 'Success'
14
- end
15
- end
16
-
17
- controller do
18
- lookup_record(:user)
19
-
20
- def index
21
- @executed = true
22
- render(:text => 'Success')
23
- end
24
- end
25
-
26
- describe 'Existing record' do
27
- before { get(:index, :id => user) }
28
- it_should_behave_like 'Successful lookup'
29
- end
30
-
31
- describe 'Non-existent record' do
32
- before do
33
- get(:index, :id => 'X')
34
- end
35
-
36
- it 'does not set the instance variable' do
37
- assigns(:user).should be_nil
38
- end
39
-
40
- it 'does not execute the action' do
41
- assigns(:executed).should be_nil
42
- end
43
-
44
- it 'responds with a 404' do
45
- response.code.should == '404'
46
- end
47
-
48
- it 'renders the 404 page' do
49
- path = File.join(Rails.root, 'public', '404.html')
50
- page = File.open(path).read
51
-
52
- response.body.should == page
53
- end
54
- end
55
-
56
- describe 'Using the model name as the parameter' do
57
- before { get(:index, :user => user) }
58
- it_should_behave_like 'Successful lookup'
59
- end
60
-
61
- describe 'Filter options' do
62
- controller do
63
- lookup_record(:user, :except => :index)
64
-
65
- def index
66
- @executed = true
67
- render(:text => 'Success')
68
- end
69
- end
70
-
71
- it 'should not set the instance variable' do
72
- get(:index, :id => user)
73
- assigns(:user).should be_nil
74
- end
75
- end
76
- end
77
- end