2014-04-20 00:01:22 +00:00
|
|
|
require 'forwardable'
|
|
|
|
|
|
|
|
module Shoulda
|
|
|
|
module Matchers
|
2014-01-23 18:07:36 +00:00
|
|
|
# @private
|
2014-04-20 00:01:22 +00:00
|
|
|
module Doublespeak
|
|
|
|
class << self
|
|
|
|
extend Forwardable
|
|
|
|
|
2014-06-12 22:12:54 +00:00
|
|
|
def_delegators :world, :double_collection_for,
|
2014-04-20 00:01:22 +00:00
|
|
|
:with_doubles_activated
|
|
|
|
|
|
|
|
def world
|
|
|
|
@_world ||= World.new
|
|
|
|
end
|
Permit matcher now supports subparameters
Previously we were taking ActionController::Parameters and completely
overriding #require, forcing it to return `self`, i.e, the entire
ActionController::Parameters object. This meant that we broke its
functionality, which is to return a slice of the params hash instead.
The consequence of this is that attempting to call #permit on a slice of
the params hash obtained via #require would not work:
``` ruby
params = ActionController::Parameters.new(
{ "course" => { "foo" => "bar" } }
)
params.require(:course)
params.require(:course).permit(:foo)
```
This commit fixes the permit matcher so that #require is proxied
instead, retaining the existing behavior.
This commit also adds a qualifier, #on, for asserting that your action
places a restriction on a slice of the params hash. The `permit` matcher
will properly track calls on child `params` instances. For example:
``` ruby
class UsersController < ActionController::Base
def create
User.create!(user_params)
...
end
private
def user_params
params.require(:user).permit(:name, :age)
end
end
describe UsersController do
it { should permit(:name, :age).for(:create).on(:user) }
end
```
If this fails, you'll get the following error message:
```
Expected POST #create to restrict parameters for :user to :name and :age,
but restricted parameters were :first_name and :last_name.
```
2015-02-19 18:35:45 +00:00
|
|
|
|
|
|
|
def debugging_enabled?
|
|
|
|
ENV['DEBUG_DOUBLESPEAK'] == '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
def debug(&block)
|
|
|
|
if debugging_enabled?
|
|
|
|
puts block.call
|
|
|
|
end
|
|
|
|
end
|
2014-04-20 00:01:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'shoulda/matchers/doublespeak/double'
|
|
|
|
require 'shoulda/matchers/doublespeak/double_collection'
|
|
|
|
require 'shoulda/matchers/doublespeak/double_implementation_registry'
|
2015-03-01 03:47:39 +00:00
|
|
|
require 'shoulda/matchers/doublespeak/method_call'
|
2014-04-20 00:01:22 +00:00
|
|
|
require 'shoulda/matchers/doublespeak/object_double'
|
|
|
|
require 'shoulda/matchers/doublespeak/proxy_implementation'
|
|
|
|
require 'shoulda/matchers/doublespeak/stub_implementation'
|
|
|
|
require 'shoulda/matchers/doublespeak/world'
|