gnip 0.4.2

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.
Files changed (89) hide show
  1. data/README +144 -0
  2. data/Rakefile +53 -0
  3. data/TODO +72 -0
  4. data/bin/gnip +651 -0
  5. data/doc/api.html +1201 -0
  6. data/gemspec.rb +47 -0
  7. data/gnip-0.4.2.gem +0 -0
  8. data/lib/gnip.rb +71 -0
  9. data/lib/gnip/activity.rb +663 -0
  10. data/lib/gnip/api.rb +191 -0
  11. data/lib/gnip/arguments.rb +21 -0
  12. data/lib/gnip/blankslate.rb +5 -0
  13. data/lib/gnip/config.rb +144 -0
  14. data/lib/gnip/filter.rb +304 -0
  15. data/lib/gnip/list.rb +126 -0
  16. data/lib/gnip/options.rb +96 -0
  17. data/lib/gnip/orderedhash.rb +199 -0
  18. data/lib/gnip/publisher.rb +309 -0
  19. data/lib/gnip/resource.rb +301 -0
  20. data/lib/gnip/template.rb +44 -0
  21. data/lib/gnip/util.rb +120 -0
  22. data/sample/data/activity.yml +21 -0
  23. data/test/auth.rb +60 -0
  24. data/test/config.yml +2 -0
  25. data/test/data/activity.xml +14 -0
  26. data/test/data/activity_only_required.xml +4 -0
  27. data/test/data/activity_with_payload.xml +22 -0
  28. data/test/data/activity_with_place.xml +18 -0
  29. data/test/data/activity_with_place_wo_bounds.xml +36 -0
  30. data/test/data/activity_with_unbounded_media_urls.xml +44 -0
  31. data/test/data/activity_without_bounds.xml +24 -0
  32. data/test/helper.rb +115 -0
  33. data/test/helper.rb.bak +28 -0
  34. data/test/integration/auth.rb +12 -0
  35. data/test/integration/publisher.rb +86 -0
  36. data/test/lib/shoulda.rb +9 -0
  37. data/test/lib/shoulda/action_controller.rb +28 -0
  38. data/test/lib/shoulda/action_controller/helpers.rb +47 -0
  39. data/test/lib/shoulda/action_controller/macros.rb +277 -0
  40. data/test/lib/shoulda/action_controller/matchers.rb +37 -0
  41. data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  42. data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  43. data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  44. data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  45. data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
  46. data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  47. data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  48. data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  49. data/test/lib/shoulda/action_mailer.rb +10 -0
  50. data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
  51. data/test/lib/shoulda/action_view.rb +10 -0
  52. data/test/lib/shoulda/action_view/macros.rb +56 -0
  53. data/test/lib/shoulda/active_record.rb +16 -0
  54. data/test/lib/shoulda/active_record/assertions.rb +69 -0
  55. data/test/lib/shoulda/active_record/helpers.rb +40 -0
  56. data/test/lib/shoulda/active_record/macros.rb +586 -0
  57. data/test/lib/shoulda/active_record/matchers.rb +42 -0
  58. data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  59. data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  60. data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  61. data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  62. data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  63. data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  64. data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  65. data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  66. data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  67. data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  68. data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  69. data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  70. data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  71. data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  72. data/test/lib/shoulda/assertions.rb +59 -0
  73. data/test/lib/shoulda/autoload_macros.rb +46 -0
  74. data/test/lib/shoulda/context.rb +304 -0
  75. data/test/lib/shoulda/helpers.rb +8 -0
  76. data/test/lib/shoulda/macros.rb +73 -0
  77. data/test/lib/shoulda/private_helpers.rb +20 -0
  78. data/test/lib/shoulda/proc_extensions.rb +14 -0
  79. data/test/lib/shoulda/rails.rb +13 -0
  80. data/test/lib/shoulda/rspec.rb +9 -0
  81. data/test/lib/shoulda/tasks.rb +3 -0
  82. data/test/lib/shoulda/tasks/list_tests.rake +29 -0
  83. data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  84. data/test/lib/shoulda/test_unit.rb +19 -0
  85. data/test/lib/xmlsimple.rb +1021 -0
  86. data/test/loader.rb +25 -0
  87. data/test/unit/activity.rb +26 -0
  88. data/test/unit/util.rb +39 -0
  89. metadata +198 -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