rspec-check-auth 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,3 @@
1
+ v0.5.2 - Default params for RESTful actions that require 'em
2
+ v0.5.1 - Adding :only as an argument to CheckAuth#resource_actions
1
3
  v0.5 - Public Release
2
- v0.5.1 - Adding :only as an argument to CheckAuth#resource_actions
data/README.md CHANGED
@@ -55,7 +55,11 @@ By default it tests via HTMl and XML, but adding more or less formats is no issu
55
55
  c.parent_info :format => [:html, :json]
56
56
  end
57
57
 
58
- Only want some of the usual crowd? No problem, just pass the `:except` param and `resource_actions` will shun those specified.
58
+ Only want some of the usual crowd? No problem, just pass the `:only` param and `resource_actions` will only include those specified.
59
+
60
+ check_auth_for {|c| c.resource_actions :only => [:new, :create, :edit, :update] }
61
+
62
+ And if you don't want some, but want everything else? Pass `:except` and those specified will be left out.
59
63
 
60
64
  check_auth_for {|c| c.resource_actions :except => [:new, :create, :edit, :update] }
61
65
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -5,18 +5,26 @@ class CheckAuth
5
5
  class Request
6
6
  attr_reader :action, :method, :params, :format
7
7
 
8
- def initialize action, format, params
8
+ def initialize action, format, opts
9
9
  @action = action
10
10
  @format = format
11
- @method = params[:method] || default_method
12
- @params = params.except(:method)
11
+ @method = opts[:method] || default_method
12
+ self.params = opts.except(:method)
13
13
  end
14
14
 
15
- # Adds the format into the params
16
- # unless it's HTML
17
- def params
18
- return @params.merge(:format => @format.to_s) unless @format == :html
19
- @params
15
+ # Sets up the params hash
16
+ #
17
+ # Adds :format => self.format if self.format != :html
18
+ # Merges any passed params into default params for this action
19
+ #
20
+ def params= param_hash
21
+ @params = default_params.merge(param_hash)
22
+
23
+ if @format == :html
24
+ @params.delete(:format)
25
+ else
26
+ @params.merge!(:format => format.to_s)
27
+ end
20
28
  end
21
29
 
22
30
  # Works out the default method
@@ -33,5 +41,16 @@ class CheckAuth
33
41
  :get
34
42
  end
35
43
  end
44
+
45
+ # Adds an id for actions that require it
46
+ def default_params
47
+ case @action.to_s
48
+ when /(show|edit|update|destroy)/
49
+ {:id => "some_id"}
50
+ else
51
+ {}
52
+ end
53
+ end
54
+
36
55
  end
37
56
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-check-auth}
8
- s.version = "0.5.1"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Caius Durling"]
12
- s.date = %q{2010-06-28}
12
+ s.date = %q{2010-07-02}
13
13
  s.description = %q{Quickly check your rails controller actions require authentication}
14
14
  s.email = %q{hello@brightbox.co.uk}
15
15
  s.extra_rdoc_files = [
@@ -30,7 +30,8 @@ Gem::Specification.new do |s|
30
30
  "lib/rspec_check_auth/extend_hash.rb",
31
31
  "lib/rspec_check_auth/extend_object.rb",
32
32
  "rspec-check-auth.gemspec",
33
- "spec/rspec_check_auth_spec.rb",
33
+ "spec/lib/request_spec.rb",
34
+ "spec/lib/rspec_check_auth_spec.rb",
34
35
  "spec/spec.opts",
35
36
  "spec/spec_helper.rb"
36
37
  ]
@@ -40,7 +41,8 @@ Gem::Specification.new do |s|
40
41
  s.rubygems_version = %q{1.3.7}
41
42
  s.summary = %q{Quickly check your rails controller actions require authentication}
42
43
  s.test_files = [
43
- "spec/rspec_check_auth_spec.rb",
44
+ "spec/lib/request_spec.rb",
45
+ "spec/lib/rspec_check_auth_spec.rb",
44
46
  "spec/spec_helper.rb"
45
47
  ]
46
48
 
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe CheckAuth::Request do
4
+
5
+ it "should create a valid instance" do
6
+ CheckAuth::Request.new(:index, :html, {}).should_not be_nil
7
+ end
8
+
9
+ it "should have default params when not overridden" do
10
+ r = CheckAuth::Request.new(:update, :html, {})
11
+ r.params.should == {:id => "some_id"}
12
+ end
13
+
14
+ it "should have a default id for show, edit, update, destroy actions" do
15
+ [:show, :edit, :update, :destroy].each do |action|
16
+ r = CheckAuth::Request.new(action, :html, {})
17
+ r.params.should == {:id => "some_id"}
18
+ end
19
+ end
20
+
21
+ it "should have no default params for index, new, create" do
22
+ [:index, :new, :create].each do |action|
23
+ r = CheckAuth::Request.new(action, :html, {})
24
+ r.params.should == {}
25
+ end
26
+ end
27
+
28
+ it "should override default params with custom ones" do
29
+ r = CheckAuth::Request.new(:update, :html, {:id => "blah blah"})
30
+ r.params.should == {:id => "blah blah"}
31
+ end
32
+
33
+ it "should not include :format in the params when format is html" do
34
+ r = CheckAuth::Request.new(nil, :html, {})
35
+ r.params.should == {}
36
+ end
37
+
38
+ it "should include :format in the params when format is not html" do
39
+ r = CheckAuth::Request.new(nil, :xml, {})
40
+ r.params.should == {:format => "xml"}
41
+ end
42
+
43
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "RspecCheckAuth" do
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-check-auth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Caius Durling
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-28 00:00:00 +01:00
18
+ date: 2010-07-02 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,8 @@ files:
55
55
  - lib/rspec_check_auth/extend_hash.rb
56
56
  - lib/rspec_check_auth/extend_object.rb
57
57
  - rspec-check-auth.gemspec
58
- - spec/rspec_check_auth_spec.rb
58
+ - spec/lib/request_spec.rb
59
+ - spec/lib/rspec_check_auth_spec.rb
59
60
  - spec/spec.opts
60
61
  - spec/spec_helper.rb
61
62
  has_rdoc: true
@@ -93,5 +94,6 @@ signing_key:
93
94
  specification_version: 3
94
95
  summary: Quickly check your rails controller actions require authentication
95
96
  test_files:
96
- - spec/rspec_check_auth_spec.rb
97
+ - spec/lib/request_spec.rb
98
+ - spec/lib/rspec_check_auth_spec.rb
97
99
  - spec/spec_helper.rb