railslove-suspenders 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- railslove-suspenders (0.1.1)
4
+ railslove-suspenders (0.1.2)
5
5
  bundler (~> 1.3)
6
6
  rails (= 4.0.0)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Railslove Suspenders
2
- <!-- [![Build Status](https://secure.travis-ci.org/thoughtbot/suspenders.png?branch=master)](http://travis-ci.org/thoughtbot/suspenders) -->
2
+ [![Build Status](https://travis-ci.org/railslove/railslove-suspenders.png?branch=master)](https://travis-ci.org/railslove/railslove-suspenders)
3
3
 
4
4
  Suspenders is the base Rails application used at [railslove](http://railslove.com) originally developed at [thoughtbot](http://thoughtbot.com/community).
5
5
 
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'bundler/setup'
2
2
  require 'bundler/gem_tasks'
3
- # require 'cucumber/rake/task'
3
+ require 'cucumber/rake/task'
4
4
 
5
- # Cucumber::Rake::Task.new
5
+ Cucumber::Rake::Task.new
6
6
 
7
- # desc 'Run the test suite'
8
- # task :default => ['cucumber']
7
+ desc 'Run the test suite'
8
+ task :default => ['cucumber']
@@ -35,7 +35,7 @@ module RailsloveSuspenders
35
35
 
36
36
  def test_factories_first
37
37
  copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb'
38
- append_file 'Rakefile', factories_spec_rake_task
38
+ # append_file 'Rakefile', factories_spec_rake_task
39
39
  end
40
40
 
41
41
  def configure_smtp
@@ -127,6 +127,10 @@ module RailsloveSuspenders
127
127
  copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
128
128
  end
129
129
 
130
+ def enable_strong_parameter_matcher
131
+ copy_file 'strong_parameter_matcher.rb', 'spec/support/matchers/strong_parameter_matcher.rb'
132
+ end
133
+
130
134
  def configure_rspec
131
135
  remove_file '.rspec'
132
136
  copy_file 'rspec', '.rspec'
@@ -78,6 +78,7 @@ module RailsloveSuspenders
78
78
  # build :configure_background_jobs_for_rspec
79
79
  build :enable_database_cleaner
80
80
  build :configure_capybara_webkit
81
+ build :enable_strong_parameter_matcher
81
82
  # build :setup_guard_spork
82
83
  end
83
84
 
@@ -1,4 +1,4 @@
1
1
  module RailsloveSuspenders
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  # suspenders 1.3.0
4
4
  end
@@ -0,0 +1,76 @@
1
+ # usage:
2
+ #
3
+ # it { should permit_params(:email, :name) }
4
+ # it { should permit_params(:email, :name).for_class(SpecialUser) }
5
+ # it { should permit_params(:name).params_method(:my_params_method) }
6
+
7
+ module StrongParameterMatcher
8
+ class PermitMatcher
9
+ attr_reader :permitted_params, :errors_protected, :errors_permitted
10
+
11
+ def initialize(permitted_params)
12
+ @permitted_params = permitted_params
13
+ @errors_protected = []
14
+ @errors_permitted = []
15
+ end
16
+
17
+ def for_class(klass)
18
+ @klass_name = klass.name
19
+ @model = klass
20
+ self
21
+ end
22
+
23
+ def params_method(name)
24
+ @params_method = name
25
+ self
26
+ end
27
+
28
+ def matches?(controller)
29
+ @klass_name ||= controller.class.name.gsub("Controller", "").classify
30
+ @model ||= @klass_name.constantize
31
+ @params_method ||= "#{@klass_name.underscore}_params".to_sym
32
+
33
+ protected_params.each do |param|
34
+ controller.params = action_controller_parameters(param)
35
+ errors_protected << param if controller.send(@params_method)[param.to_sym]
36
+ end
37
+
38
+ permitted_params.each do |param|
39
+ controller.params = action_controller_parameters(param)
40
+ errors_permitted << param unless controller.send(@params_method).has_key?(param)
41
+ end
42
+
43
+ return errors_protected.empty? && errors_permitted.empty?
44
+ end
45
+
46
+ def failure_message
47
+ msg = "expected "
48
+ if !errors_protected.empty?
49
+ msg << "#{errors_protected} to be protected but is permitted"
50
+ else
51
+ msg << "#{errors_permitted} to be permitted but is not"
52
+ end
53
+ end
54
+
55
+ def description
56
+ "permit #{permitted_params} through :#{@params_method}"
57
+ end
58
+
59
+ private
60
+ def protected_params
61
+ @model.column_names - permitted_params.map(&:to_s)
62
+ end
63
+
64
+ def action_controller_parameters(param)
65
+ ActionController::Parameters.new(@klass_name.underscore.to_sym => {param => "random"})
66
+ end
67
+ end
68
+
69
+ def permit_params(*keys)
70
+ PermitMatcher.new(keys)
71
+ end
72
+ end
73
+
74
+ RSpec.configure do |config|
75
+ config.include(StrongParameterMatcher)
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railslove-suspenders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2013-09-11 00:00:00.000000000 Z
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - templates/sample.env
138
138
  - templates/simplecov_init.rb
139
139
  - templates/smtp.rb
140
+ - templates/strong_parameter_matcher.rb
140
141
  - templates/stylesheets/_shame.css.sass
141
142
  - templates/stylesheets/application.css.sass
142
143
  - templates/stylesheets/base/_colors.css.sass