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.
data/lib/restful_spec.rb
CHANGED
@@ -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.
|
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 :
|
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.
|
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[:
|
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
|
data/lib/restful_spec/version.rb
CHANGED
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.
|
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-
|
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:
|