gnip-gnip 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +144 -0
- data/Rakefile +221 -0
- data/TODO +72 -0
- data/bin/gnip +651 -0
- data/doc/api.html +1201 -0
- data/gemspec.rb +25 -0
- data/gnip-ruby.gemspec +26 -0
- data/lib/gnip.rb +71 -0
- data/lib/gnip/activity.rb +665 -0
- data/lib/gnip/api.rb +191 -0
- data/lib/gnip/arguments.rb +21 -0
- data/lib/gnip/blankslate.rb +5 -0
- data/lib/gnip/config.rb +144 -0
- data/lib/gnip/filter.rb +311 -0
- data/lib/gnip/list.rb +126 -0
- data/lib/gnip/options.rb +96 -0
- data/lib/gnip/orderedhash.rb +199 -0
- data/lib/gnip/publisher.rb +316 -0
- data/lib/gnip/resource.rb +301 -0
- data/lib/gnip/template.rb +44 -0
- data/lib/gnip/util.rb +120 -0
- data/sample/data/activity.yml +21 -0
- data/test/auth.rb +60 -0
- data/test/config.yml +2 -0
- data/test/data/activity.xml +14 -0
- data/test/data/activity_only_required.xml +4 -0
- data/test/data/activity_with_payload.xml +22 -0
- data/test/data/activity_with_place.xml +18 -0
- data/test/data/activity_with_place_wo_bounds.xml +36 -0
- data/test/data/activity_with_unbounded_media_urls.xml +44 -0
- data/test/data/activity_without_bounds.xml +24 -0
- data/test/helper.rb +115 -0
- data/test/integration/auth.rb +12 -0
- data/test/integration/publisher.rb +86 -0
- data/test/lib/shoulda.rb +9 -0
- data/test/lib/shoulda/action_controller.rb +28 -0
- data/test/lib/shoulda/action_controller/helpers.rb +47 -0
- data/test/lib/shoulda/action_controller/macros.rb +277 -0
- data/test/lib/shoulda/action_controller/matchers.rb +37 -0
- data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
- data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
- data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
- data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
- data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
- data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
- data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
- data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
- data/test/lib/shoulda/action_mailer.rb +10 -0
- data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
- data/test/lib/shoulda/action_view.rb +10 -0
- data/test/lib/shoulda/action_view/macros.rb +56 -0
- data/test/lib/shoulda/active_record.rb +16 -0
- data/test/lib/shoulda/active_record/assertions.rb +69 -0
- data/test/lib/shoulda/active_record/helpers.rb +40 -0
- data/test/lib/shoulda/active_record/macros.rb +586 -0
- data/test/lib/shoulda/active_record/matchers.rb +42 -0
- data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
- data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
- data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
- data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
- data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
- data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
- data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
- data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
- data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
- data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
- data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
- data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
- data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
- data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
- data/test/lib/shoulda/assertions.rb +59 -0
- data/test/lib/shoulda/autoload_macros.rb +46 -0
- data/test/lib/shoulda/context.rb +304 -0
- data/test/lib/shoulda/helpers.rb +8 -0
- data/test/lib/shoulda/macros.rb +73 -0
- data/test/lib/shoulda/private_helpers.rb +20 -0
- data/test/lib/shoulda/proc_extensions.rb +14 -0
- data/test/lib/shoulda/rails.rb +13 -0
- data/test/lib/shoulda/rspec.rb +9 -0
- data/test/lib/shoulda/tasks.rb +3 -0
- data/test/lib/shoulda/tasks/list_tests.rake +29 -0
- data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
- data/test/lib/shoulda/test_unit.rb +19 -0
- data/test/lib/xmlsimple.rb +1021 -0
- data/test/loader.rb +25 -0
- data/test/unit/activity.rb +26 -0
- data/test/unit/util.rb +39 -0
- metadata +158 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures that filter_parameter_logging is set for the specified key.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# it { should filter_param(:password) }
|
10
|
+
def filter_param(key)
|
11
|
+
FilterParamMatcher.new(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
class FilterParamMatcher # :nodoc:
|
15
|
+
|
16
|
+
def initialize(key)
|
17
|
+
@key = key.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(controller)
|
21
|
+
@controller = controller
|
22
|
+
filters_params? && filters_key?
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message
|
26
|
+
"Expected #{@key} to be filtered"
|
27
|
+
end
|
28
|
+
|
29
|
+
def negative_failure_message
|
30
|
+
"Did not expect #{@key} to be filtered"
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
"filter #{@key}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def filters_params?
|
40
|
+
@controller.respond_to?(:filter_parameters)
|
41
|
+
end
|
42
|
+
|
43
|
+
def filters_key?
|
44
|
+
filtered_value == '[FILTERED]'
|
45
|
+
end
|
46
|
+
|
47
|
+
def filtered_value
|
48
|
+
filtered = @controller.send(:filter_parameters,
|
49
|
+
@key.to_s => @key.to_s)
|
50
|
+
filtered[@key.to_s]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures that the controller rendered with the given layout.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# it { should render_with_layout }
|
10
|
+
# it { should render_with_layout(:special) }
|
11
|
+
# it { should_not render_with_layout }
|
12
|
+
def render_with_layout(layout = nil)
|
13
|
+
RenderWithLayout.new(layout)
|
14
|
+
end
|
15
|
+
|
16
|
+
class RenderWithLayout # :nodoc:
|
17
|
+
|
18
|
+
def initialize(layout)
|
19
|
+
@layout = layout.to_s unless layout.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def matches?(controller)
|
23
|
+
@controller = controller
|
24
|
+
rendered_with_layout? && rendered_with_expected_layout?
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"Expected #{expectation}, but #{result}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def negative_failure_message
|
32
|
+
"Did not expect #{expectation}, but #{result}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def description
|
36
|
+
description = "render with "
|
37
|
+
if @layout.nil?
|
38
|
+
description << "a layout"
|
39
|
+
else
|
40
|
+
description << "the #{@layout.inspect} layout"
|
41
|
+
end
|
42
|
+
description
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def rendered_with_layout?
|
48
|
+
!layout.blank?
|
49
|
+
end
|
50
|
+
|
51
|
+
def rendered_with_expected_layout?
|
52
|
+
return true if @layout.nil?
|
53
|
+
layout == @layout
|
54
|
+
end
|
55
|
+
|
56
|
+
def layout
|
57
|
+
layout = @controller.response.layout
|
58
|
+
if layout.nil?
|
59
|
+
nil
|
60
|
+
else
|
61
|
+
layout.split('/').last
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def expectation
|
66
|
+
"to #{description}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def result
|
70
|
+
if rendered_with_layout?
|
71
|
+
"rendered with the #{layout.inspect} layout"
|
72
|
+
else
|
73
|
+
"rendered without a layout"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures a controller responded with expected 'response' content type.
|
6
|
+
#
|
7
|
+
# You can pass an explicit content type such as 'application/rss+xml'
|
8
|
+
# or its symbolic equivalent :rss
|
9
|
+
# or a regular expression such as /rss/
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# it { should respond_with_content_type(:xml) }
|
14
|
+
# it { should respond_with_content_type(:csv) }
|
15
|
+
# it { should respond_with_content_type(:atom) }
|
16
|
+
# it { should respond_with_content_type(:yaml) }
|
17
|
+
# it { should respond_with_content_type(:text) }
|
18
|
+
# it { should respond_with_content_type('application/rss+xml') }
|
19
|
+
# it { should respond_with_content_type(/json/) }
|
20
|
+
def respond_with_content_type(content_type)
|
21
|
+
RespondWithContentTypeMatcher.new(content_type)
|
22
|
+
end
|
23
|
+
|
24
|
+
class RespondWithContentTypeMatcher # :nodoc:
|
25
|
+
|
26
|
+
def initialize(content_type)
|
27
|
+
@content_type = if content_type.is_a?(Symbol)
|
28
|
+
lookup_by_extension(content_type)
|
29
|
+
else
|
30
|
+
content_type
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def matches?(controller)
|
35
|
+
@controller = controller
|
36
|
+
if @content_type.is_a?(Regexp)
|
37
|
+
response_content_type =~ @content_type
|
38
|
+
else
|
39
|
+
response_content_type == @content_type
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def failure_message
|
44
|
+
"Expected #{expectation}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def negative_failure_message
|
48
|
+
"Did not expect #{expectation}"
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def response_content_type
|
54
|
+
@controller.response.content_type
|
55
|
+
end
|
56
|
+
|
57
|
+
def lookup_by_extension(extension)
|
58
|
+
Mime::Type.lookup_by_extension(extension.to_s).to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def expectation
|
62
|
+
"content type to be #{@content_type}, " <<
|
63
|
+
"but was #{response_content_type}"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures a controller responded with expected 'response' status code.
|
6
|
+
#
|
7
|
+
# You can pass an explicit status number like 200, 301, 404, 500
|
8
|
+
# or its symbolic equivalent :success, :redirect, :missing, :error.
|
9
|
+
# See ActionController::StatusCodes for a full list.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# it { should respond_with(:success) }
|
14
|
+
# it { should respond_with(:redirect) }
|
15
|
+
# it { should respond_with(:missing) }
|
16
|
+
# it { should respond_with(:error) }
|
17
|
+
# it { should respond_with(501) }
|
18
|
+
def respond_with(status)
|
19
|
+
RespondWithMatcher.new(status)
|
20
|
+
end
|
21
|
+
|
22
|
+
class RespondWithMatcher # :nodoc:
|
23
|
+
|
24
|
+
def initialize(status)
|
25
|
+
@status = symbol_to_status_code(status)
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches?(controller)
|
29
|
+
@controller = controller
|
30
|
+
correct_status_code? || correct_status_code_range?
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message
|
34
|
+
"Expected #{expectation}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def negative_failure_message
|
38
|
+
"Did not expect #{expectation}"
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def correct_status_code?
|
44
|
+
response_code == @status
|
45
|
+
end
|
46
|
+
|
47
|
+
def correct_status_code_range?
|
48
|
+
@status.is_a?(Range) &&
|
49
|
+
@status.include?(response_code)
|
50
|
+
end
|
51
|
+
|
52
|
+
def response_code
|
53
|
+
@controller.response.response_code
|
54
|
+
end
|
55
|
+
|
56
|
+
def symbol_to_status_code(potential_symbol)
|
57
|
+
case potential_symbol
|
58
|
+
when :success then 200
|
59
|
+
when :redirect then 300..399
|
60
|
+
when :missing then 404
|
61
|
+
when :error then 500..599
|
62
|
+
when Symbol
|
63
|
+
::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[potential_symbol]
|
64
|
+
else
|
65
|
+
potential_symbol
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def expectation
|
70
|
+
"response to be a #{@status}, but was #{response_code}"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures that requesting +path+ using +method+ routes to +options+.
|
6
|
+
#
|
7
|
+
# If you don't specify a controller, it will use the controller from the
|
8
|
+
# example group.
|
9
|
+
#
|
10
|
+
# +to_param+ is called on the +options+ given.
|
11
|
+
#
|
12
|
+
# Examples:
|
13
|
+
#
|
14
|
+
# it { should route(:get, "/posts").
|
15
|
+
# to(:controller => :posts, :action => :index) }
|
16
|
+
# it { should route(:get, "/posts/new").to(:action => :new) }
|
17
|
+
# it { should route(:post, "/posts").to(:action => :create) }
|
18
|
+
# it { should route(:get, "/posts/1").to(:action => :show, :id => 1) }
|
19
|
+
# it { should route(:edit, "/posts/1").to(:action => :show, :id => 1) }
|
20
|
+
# it { should route(:put, "/posts/1").to(:action => :update, :id => 1) }
|
21
|
+
# it { should route(:delete, "/posts/1").
|
22
|
+
# to(:action => :destroy, :id => 1) }
|
23
|
+
# it { should route(:get, "/users/1/posts/1").
|
24
|
+
# to(:action => :show, :id => 1, :user_id => 1) }
|
25
|
+
def route(method, path)
|
26
|
+
RouteMatcher.new(method, path, self)
|
27
|
+
end
|
28
|
+
|
29
|
+
class RouteMatcher # :nodoc:
|
30
|
+
|
31
|
+
def initialize(method, path, context)
|
32
|
+
@method = method
|
33
|
+
@path = path
|
34
|
+
@context = context
|
35
|
+
end
|
36
|
+
|
37
|
+
def to(params)
|
38
|
+
@params = params
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def in_context(context)
|
43
|
+
@context = context
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def matches?(controller)
|
48
|
+
@controller = controller
|
49
|
+
guess_controller!
|
50
|
+
stringify_params!
|
51
|
+
route_recognized?
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :failure_message, :negative_failure_message
|
55
|
+
|
56
|
+
def description
|
57
|
+
"route #{@method.to_s.upcase} #{@path} to/from #{@params.inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def guess_controller!
|
63
|
+
@params[:controller] ||= @controller.controller_path
|
64
|
+
end
|
65
|
+
|
66
|
+
def stringify_params!
|
67
|
+
@params.each do |key, value|
|
68
|
+
@params[key] = value.to_param
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def route_recognized?
|
73
|
+
begin
|
74
|
+
@context.send(:assert_routing,
|
75
|
+
{ :method => @method, :path => @path },
|
76
|
+
@params)
|
77
|
+
|
78
|
+
@negative_failure_message = "Didn't expect to #{description}"
|
79
|
+
true
|
80
|
+
rescue ::ActionController::RoutingError => error
|
81
|
+
@failure_message = error.message
|
82
|
+
false
|
83
|
+
rescue Test::Unit::AssertionFailedError => error
|
84
|
+
@failure_message = error.message
|
85
|
+
false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module ActionController # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures that a session key was set to the expected value.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# it { should set_session(:message) }
|
10
|
+
# it { should set_session(:user_id).to(@user.id) }
|
11
|
+
# it { should_not set_session(:user_id) }
|
12
|
+
def set_session(key)
|
13
|
+
SetSessionMatcher.new(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
class SetSessionMatcher # :nodoc:
|
17
|
+
|
18
|
+
def initialize(key)
|
19
|
+
@key = key.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def to(value)
|
23
|
+
@value = value
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def matches?(controller)
|
28
|
+
@controller = controller
|
29
|
+
assigned_value? && assigned_correct_value?
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message
|
33
|
+
"Expected #{expectation}, but #{result}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def negative_failure_message
|
37
|
+
"Didn't expect #{expectation}, but #{result}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def description
|
41
|
+
description = "set session variable #{@key.inspect}"
|
42
|
+
description << " to #{@value.inspect}" if @value
|
43
|
+
description
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def assigned_value?
|
49
|
+
!assigned_value.blank?
|
50
|
+
end
|
51
|
+
|
52
|
+
def assigned_correct_value?
|
53
|
+
return true if @value.nil?
|
54
|
+
assigned_value == @value
|
55
|
+
end
|
56
|
+
|
57
|
+
def assigned_value
|
58
|
+
session[@key]
|
59
|
+
end
|
60
|
+
|
61
|
+
def session
|
62
|
+
@controller.response.session.data
|
63
|
+
end
|
64
|
+
|
65
|
+
def expectation
|
66
|
+
expectation = "session variable #{@key} to be set"
|
67
|
+
expectation << " to #{@value.inspect}" if @value
|
68
|
+
expectation
|
69
|
+
end
|
70
|
+
|
71
|
+
def result
|
72
|
+
if session.empty?
|
73
|
+
"no session variables were set"
|
74
|
+
else
|
75
|
+
"the session was #{session.inspect}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|