cancan_strong_parameters 0.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +6 -6
- data/lib/cancan_strong_parameters.rb +1 -0
- data/lib/cancan_strong_parameters/controller.rb +6 -2
- data/lib/cancan_strong_parameters/version.rb +1 -1
- data/test/app/controllers/posts_controller.rb +9 -1
- data/test/app/controllers/title_controller.rb +5 -0
- data/test/app/models/post.rb +18 -1
- data/test/{test_cancan_strong_parameters.rb → functional/posts_controller_test.rb} +2 -11
- data/test/functional/title_controller_test.rb +17 -0
- data/test/rails_helper.rb +3 -1
- data/test/test_helper.rb +10 -0
- metadata +10 -5
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
|
2
|
+
$: << File.dirname(__FILE__)
|
3
3
|
|
4
|
+
require "bundler/gem_tasks"
|
4
5
|
require 'rake/testtask'
|
5
|
-
|
6
|
-
Rake::TestTask.new do |t|
|
7
|
-
t.libs << 'test'
|
8
|
-
end
|
6
|
+
require 'test/rails_helper'
|
9
7
|
|
10
8
|
desc "Run tests"
|
11
|
-
task :default => :test
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
Rails.application.load_tasks
|
@@ -94,8 +94,12 @@ module CancanStrongParameters
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
def resource_name
|
98
|
-
|
97
|
+
def resource_name(name_to_set=nil)
|
98
|
+
unless name_to_set.present?
|
99
|
+
@resource_name ||= self.to_s.sub("Controller", "").underscore.split('/').last.singularize
|
100
|
+
else
|
101
|
+
@resource_name = name_to_set
|
102
|
+
end
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
@@ -11,6 +11,14 @@ class PostsController < ActionController::Base
|
|
11
11
|
@post_attributes = params[:post]
|
12
12
|
render json: @post
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
def update
|
16
|
+
@post = Post.find(params[:id])
|
17
|
+
if @post.update_attributes(params[:post])
|
18
|
+
render json: @post
|
19
|
+
else
|
20
|
+
render json: { errors: @post.errors.full_messages }, status: :unprocessable_entity
|
21
|
+
end
|
22
|
+
end
|
15
23
|
|
16
24
|
end
|
data/test/app/models/post.rb
CHANGED
@@ -3,9 +3,26 @@ class Post
|
|
3
3
|
include ActiveModel::MassAssignmentSecurity
|
4
4
|
include ActiveModel::AttributeMethods
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :title, :body
|
7
|
+
attr_accessible :title, :body
|
7
8
|
|
8
9
|
def initialize(attributes = {})
|
9
10
|
@attributes = attributes
|
10
11
|
end
|
12
|
+
|
13
|
+
# Fake persistence
|
14
|
+
def self.sample_post
|
15
|
+
new(title: "Sample post", body: "Sample body")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(*args)
|
19
|
+
sample_post
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_attributes(params)
|
23
|
+
params.map do |k,v|
|
24
|
+
setter = :"#{k}=" # setter
|
25
|
+
self.send(setter, v) if self.respond_to?(setter)
|
26
|
+
end
|
27
|
+
end
|
11
28
|
end
|
@@ -1,13 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'require_all'
|
4
|
-
|
5
|
-
require 'strong_parameters'
|
6
|
-
require 'cancan_strong_parameters'
|
7
|
-
|
8
|
-
## Boot up an instance of rails
|
9
|
-
require 'rails_helper'
|
10
|
-
require 'rails/test_help'
|
1
|
+
require 'test_helper'
|
11
2
|
|
12
3
|
class PostsControllerTest < ActionController::TestCase
|
13
4
|
test "should not clip off deep params" do
|
@@ -37,7 +28,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
37
28
|
}
|
38
29
|
}
|
39
30
|
|
40
|
-
|
31
|
+
post :create, params
|
41
32
|
assert_equal \
|
42
33
|
ActiveSupport::HashWithIndifferentAccess.new(assigns(:post_attributes)),
|
43
34
|
ActiveSupport::HashWithIndifferentAccess.new(params[:post])
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TitleControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "can manually change resource_name" do
|
6
|
+
|
7
|
+
new_title = 'Changed title'
|
8
|
+
put :update,
|
9
|
+
id: 1,
|
10
|
+
post: {
|
11
|
+
title: new_title
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_equal assigns[:post].title, new_title
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/rails_helper.rb
CHANGED
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancan_strong_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.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-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cancan
|
@@ -142,11 +142,14 @@ files:
|
|
142
142
|
- lib/cancan_strong_parameters/rails/controller/base.rb
|
143
143
|
- lib/cancan_strong_parameters/version.rb
|
144
144
|
- test/app/controllers/posts_controller.rb
|
145
|
+
- test/app/controllers/title_controller.rb
|
145
146
|
- test/app/models/post.rb
|
146
147
|
- test/config.ru
|
148
|
+
- test/functional/posts_controller_test.rb
|
149
|
+
- test/functional/title_controller_test.rb
|
147
150
|
- test/rails_helper.rb
|
148
151
|
- test/script/rails
|
149
|
-
- test/
|
152
|
+
- test/test_helper.rb
|
150
153
|
homepage: https://github.com/colinyoung/cancan_strong_parameters
|
151
154
|
licenses: []
|
152
155
|
post_install_message:
|
@@ -173,9 +176,11 @@ specification_version: 3
|
|
173
176
|
summary: make CanCan work with strong_parameters
|
174
177
|
test_files:
|
175
178
|
- test/app/controllers/posts_controller.rb
|
179
|
+
- test/app/controllers/title_controller.rb
|
176
180
|
- test/app/models/post.rb
|
177
181
|
- test/config.ru
|
182
|
+
- test/functional/posts_controller_test.rb
|
183
|
+
- test/functional/title_controller_test.rb
|
178
184
|
- test/rails_helper.rb
|
179
185
|
- test/script/rails
|
180
|
-
- test/
|
181
|
-
has_rdoc:
|
186
|
+
- test/test_helper.rb
|