restful_spec 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ module RestfulSpec
16
16
 
17
17
  specification do
18
18
  accepts_parameters for: %w(PUT POST)
19
+ rejects_parameters for: %w(PUT POST)
19
20
  accepts_formats :json, :xml
20
21
  responds_with :member, for: %w(GET POST)
21
22
  responds_with :specification, for: 'OPTIONS'
@@ -40,6 +40,10 @@ class RestfulSpec::Specification
40
40
  resource.respond_to?(:accessible_attributes) ? resource.accessible_attributes : Set.new
41
41
  end
42
42
 
43
+ def protected_attributes
44
+ resource.respond_to?(:protected_attributes) ? resource.protected_attributes : Set.new
45
+ end
46
+
43
47
  def accepts_parameters(options={})
44
48
 
45
49
  raise RestfulSpec::Error::InvalidAction,
@@ -57,7 +61,7 @@ class RestfulSpec::Specification
57
61
  raise RestfulSpec::Error::InvalidAction,
58
62
  "#{action_string} is not a valid action for #{@controller.class.name}!", self.actions unless action.present?
59
63
 
60
- action.parameters = params.to_a.select(&:present?)
64
+ action.accepts_parameters = params.to_a.select(&:present?)
61
65
  action_map << action
62
66
  end
63
67
 
@@ -65,6 +69,31 @@ class RestfulSpec::Specification
65
69
 
66
70
  alias :accepts_parameter :accepts_parameters
67
71
 
72
+ def rejects_parameters(options={})
73
+
74
+ raise RestfulSpec::Error::InvalidAction,
75
+ "rejects_parameter requires a valid action!",
76
+ actions unless (actions = Array.wrap(options.delete :for)).present?
77
+
78
+ actions = actions.map { |a| get_action(a) }.flatten
79
+
80
+ params = SmartSelect.new(protected_attributes, options[:attributes]) do
81
+ select :only
82
+ reject :except
83
+ end
84
+
85
+ actions.reduce([]) do |action_map, action|
86
+ raise RestfulSpec::Error::InvalidAction,
87
+ "#{action_string} is not a valid action for #{@controller.class.name}!", self.actions unless action.present?
88
+
89
+ action.rejects_parameters = params.to_a.select(&:present?)
90
+ action_map << action
91
+ end
92
+
93
+ end
94
+
95
+ alias :rejects_parameter :rejects_parameters
96
+
68
97
  def responds_with(responder, options)
69
98
  raise RestfulSpec::Error::InvalidAction,
70
99
  "responds_with requires a valid action!",
@@ -1,6 +1,6 @@
1
1
  class RestfulSpec::Specification::Action
2
2
 
3
- attr_accessor :parameters, :responds_with
3
+ attr_accessor :rejects_parameters, :accepts_parameters, :responds_with
4
4
  attr_reader :route
5
5
 
6
6
  def self.from_routes(controller)
@@ -32,7 +32,8 @@ class RestfulSpec::Specification::Action
32
32
  @path.gsub!(/\(\.:format\)$/,'')
33
33
  @method = verb
34
34
 
35
- self.parameters = Set.new
35
+ self.accepts_parameters = Set.new
36
+ self.rejects_parameters = Set.new
36
37
  self.responds_with = nil
37
38
  end
38
39
 
@@ -45,7 +46,8 @@ class RestfulSpec::Specification::Action
45
46
  hash[:method] = @method
46
47
  hash[:path] = @path
47
48
  hash[:name] = @name
48
- hash[:parameters] = parameters
49
+ hash[:accepts_parameters] = accepts_parameters
50
+ hash[:rejects_parameters] = rejects_parameters
49
51
  hash[:responds_with] = responds_with
50
52
  hash.as_json(*args)
51
53
  end
@@ -1,3 +1,3 @@
1
1
  module RestfulSpec
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -74,4 +74,3 @@ signing_key:
74
74
  specification_version: 3
75
75
  summary: Specifications your your rest API's
76
76
  test_files: []
77
- has_rdoc: