gnip-gnip 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/README +144 -0
  2. data/Rakefile +221 -0
  3. data/TODO +72 -0
  4. data/bin/gnip +651 -0
  5. data/doc/api.html +1201 -0
  6. data/gemspec.rb +25 -0
  7. data/gnip-ruby.gemspec +26 -0
  8. data/lib/gnip.rb +71 -0
  9. data/lib/gnip/activity.rb +665 -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 +311 -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 +316 -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/integration/auth.rb +12 -0
  34. data/test/integration/publisher.rb +86 -0
  35. data/test/lib/shoulda.rb +9 -0
  36. data/test/lib/shoulda/action_controller.rb +28 -0
  37. data/test/lib/shoulda/action_controller/helpers.rb +47 -0
  38. data/test/lib/shoulda/action_controller/macros.rb +277 -0
  39. data/test/lib/shoulda/action_controller/matchers.rb +37 -0
  40. data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  41. data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  42. data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  43. data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  44. data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
  45. data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  46. data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  47. data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  48. data/test/lib/shoulda/action_mailer.rb +10 -0
  49. data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
  50. data/test/lib/shoulda/action_view.rb +10 -0
  51. data/test/lib/shoulda/action_view/macros.rb +56 -0
  52. data/test/lib/shoulda/active_record.rb +16 -0
  53. data/test/lib/shoulda/active_record/assertions.rb +69 -0
  54. data/test/lib/shoulda/active_record/helpers.rb +40 -0
  55. data/test/lib/shoulda/active_record/macros.rb +586 -0
  56. data/test/lib/shoulda/active_record/matchers.rb +42 -0
  57. data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  58. data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  59. data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  60. data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  61. data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  62. data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  63. data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  64. data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  65. data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  66. data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  67. data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  68. data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  69. data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  70. data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  71. data/test/lib/shoulda/assertions.rb +59 -0
  72. data/test/lib/shoulda/autoload_macros.rb +46 -0
  73. data/test/lib/shoulda/context.rb +304 -0
  74. data/test/lib/shoulda/helpers.rb +8 -0
  75. data/test/lib/shoulda/macros.rb +73 -0
  76. data/test/lib/shoulda/private_helpers.rb +20 -0
  77. data/test/lib/shoulda/proc_extensions.rb +14 -0
  78. data/test/lib/shoulda/rails.rb +13 -0
  79. data/test/lib/shoulda/rspec.rb +9 -0
  80. data/test/lib/shoulda/tasks.rb +3 -0
  81. data/test/lib/shoulda/tasks/list_tests.rake +29 -0
  82. data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  83. data/test/lib/shoulda/test_unit.rb +19 -0
  84. data/test/lib/xmlsimple.rb +1021 -0
  85. data/test/loader.rb +25 -0
  86. data/test/unit/activity.rb +26 -0
  87. data/test/unit/util.rb +39 -0
  88. metadata +158 -0
@@ -0,0 +1,9 @@
1
+ module Shoulda
2
+ VERSION = "2.9.1"
3
+ end
4
+
5
+ if defined? Spec
6
+ require 'shoulda/rspec'
7
+ else
8
+ require 'shoulda/test_unit'
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'shoulda'
2
+ require 'shoulda/action_controller/helpers'
3
+ require 'shoulda/action_controller/matchers'
4
+ require 'shoulda/action_controller/macros'
5
+
6
+ module Test # :nodoc: all
7
+ module Unit
8
+ class TestCase
9
+ include Shoulda::ActionController::Matchers
10
+ include Shoulda::ActionController::Helpers
11
+ extend Shoulda::ActionController::Macros
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'shoulda/active_record/assertions'
17
+ require 'shoulda/action_mailer/assertions'
18
+
19
+ module ActionController #:nodoc: all
20
+ module Integration
21
+ class Session
22
+ include Shoulda::Assertions
23
+ include Shoulda::Helpers
24
+ include Shoulda::ActiveRecord::Assertions
25
+ include Shoulda::ActionMailer::Assertions
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ module Shoulda # :nodoc:
2
+ module ActionController # :nodoc:
3
+ module Helpers # :nodoc:
4
+ private # :enddoc:
5
+
6
+ SPECIAL_INSTANCE_VARIABLES = %w{
7
+ _cookies
8
+ _flash
9
+ _headers
10
+ _params
11
+ _request
12
+ _response
13
+ _session
14
+ action_name
15
+ before_filter_chain_aborted
16
+ cookies
17
+ flash
18
+ headers
19
+ ignore_missing_templates
20
+ logger
21
+ params
22
+ request
23
+ request_origin
24
+ response
25
+ session
26
+ template
27
+ template_class
28
+ template_root
29
+ url
30
+ variables_added
31
+ }.map(&:to_s)
32
+
33
+ def instantiate_variables_from_assigns(*names, &blk)
34
+ old = {}
35
+ names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty?
36
+ names.each do |name|
37
+ old[name] = instance_variable_get("@#{name}")
38
+ instance_variable_set("@#{name}", assigns(name.to_sym))
39
+ end
40
+ blk.call
41
+ names.each do |name|
42
+ instance_variable_set("@#{name}", old[name])
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,277 @@
1
+ module Shoulda # :nodoc:
2
+ module ActionController # :nodoc:
3
+ # = Macro test helpers for your controllers
4
+ #
5
+ # By using the macro helpers you can quickly and easily create concise and easy to read test suites.
6
+ #
7
+ # This code segment:
8
+ # context "on GET to :show for first record" do
9
+ # setup do
10
+ # get :show, :id => 1
11
+ # end
12
+ #
13
+ # should_assign_to :user
14
+ # should_respond_with :success
15
+ # should_render_template :show
16
+ # should_not_set_the_flash
17
+ #
18
+ # should "do something else really cool" do
19
+ # assert_equal 1, assigns(:user).id
20
+ # end
21
+ # end
22
+ #
23
+ # Would produce 5 tests for the +show+ action
24
+ module Macros
25
+ include Matchers
26
+
27
+ # Macro that creates a test asserting that the flash contains the given value.
28
+ # val can be a String, a Regex, or nil (indicating that the flash should not be set)
29
+ #
30
+ # Example:
31
+ #
32
+ # should_set_the_flash_to "Thank you for placing this order."
33
+ # should_set_the_flash_to /created/i
34
+ # should_set_the_flash_to nil
35
+ def should_set_the_flash_to(val)
36
+ matcher = set_the_flash.to(val)
37
+ if val
38
+ should matcher.description do
39
+ assert_accepts matcher, @controller
40
+ end
41
+ else
42
+ should "not #{matcher.description}" do
43
+ assert_rejects matcher, @controller
44
+ end
45
+ end
46
+ end
47
+
48
+ # Macro that creates a test asserting that the flash is empty. Same as
49
+ # @should_set_the_flash_to nil@
50
+ def should_not_set_the_flash
51
+ should_set_the_flash_to nil
52
+ end
53
+
54
+ # Macro that creates a test asserting that filter_parameter_logging
55
+ # is set for the specified keys
56
+ #
57
+ # Example:
58
+ #
59
+ # should_filter_params :password, :ssn
60
+ def should_filter_params(*keys)
61
+ keys.each do |key|
62
+ matcher = filter_param(key)
63
+ should matcher.description do
64
+ assert_accepts matcher, @controller
65
+ end
66
+ end
67
+ end
68
+
69
+ # Macro that creates a test asserting that the controller assigned to
70
+ # each of the named instance variable(s).
71
+ #
72
+ # Options:
73
+ # * <tt>:class</tt> - The expected class of the instance variable being checked.
74
+ # * <tt>:equals</tt> - A string which is evaluated and compared for equality with
75
+ # the instance variable being checked.
76
+ #
77
+ # Example:
78
+ #
79
+ # should_assign_to :user, :posts
80
+ # should_assign_to :user, :class => User
81
+ # should_assign_to(:user) { @user }
82
+ def should_assign_to(*names, &block)
83
+ opts = names.extract_options!
84
+ if opts[:equals]
85
+ warn "[DEPRECATION] should_assign_to :var, :equals => 'val' " <<
86
+ "is deprecated. Use should_assign_to(:var) { 'val' } instead."
87
+ end
88
+ names.each do |name|
89
+ matcher = assign_to(name).with_kind_of(opts[:class])
90
+ test_name = matcher.description
91
+ test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
92
+ should test_name do
93
+ if opts[:equals]
94
+ instantiate_variables_from_assigns do
95
+ expected_value = eval(opts[:equals],
96
+ self.send(:binding),
97
+ __FILE__,
98
+ __LINE__)
99
+ matcher = matcher.with(expected_value)
100
+ end
101
+ elsif block
102
+ expected_value = instance_eval(&block)
103
+ matcher = matcher.with(expected_value)
104
+ end
105
+
106
+ assert_accepts matcher, @controller
107
+ end
108
+ end
109
+ end
110
+
111
+ # Macro that creates a test asserting that the controller did not assign to
112
+ # any of the named instance variable(s).
113
+ #
114
+ # Example:
115
+ #
116
+ # should_not_assign_to :user, :posts
117
+ def should_not_assign_to(*names)
118
+ names.each do |name|
119
+ matcher = assign_to(name)
120
+ should "not #{matcher.description}" do
121
+ assert_rejects matcher, @controller
122
+ end
123
+ end
124
+ end
125
+
126
+ # Macro that creates a test asserting that the controller responded with a 'response' status code.
127
+ # Example:
128
+ #
129
+ # should_respond_with :success
130
+ def should_respond_with(response)
131
+ should "respond with #{response}" do
132
+ matcher = respond_with(response)
133
+ assert_accepts matcher, @controller
134
+ end
135
+ end
136
+
137
+ # Macro that creates a test asserting that the response content type was 'content_type'.
138
+ # Example:
139
+ #
140
+ # should_respond_with_content_type 'application/rss+xml'
141
+ # should_respond_with_content_type :rss
142
+ # should_respond_with_content_type /rss/
143
+ def should_respond_with_content_type(content_type)
144
+ should "respond with content type of #{content_type}" do
145
+ matcher = respond_with_content_type(content_type)
146
+ assert_accepts matcher, @controller
147
+ end
148
+ end
149
+
150
+ # Macro that creates a test asserting that a value returned from the session is correct.
151
+ # The given string is evaled to produce the resulting redirect path. All of the instance variables
152
+ # set by the controller are available to the evaled string.
153
+ # Example:
154
+ #
155
+ # should_set_session(:user_id) { '@user.id' }
156
+ # should_set_session(:message) { "Free stuff" }
157
+ def should_set_session(key, expected = nil, &block)
158
+ matcher = set_session(key)
159
+ if expected
160
+ warn "[DEPRECATION] should_set_session :key, 'val' is deprecated. " <<
161
+ "Use should_set_session(:key) { 'val' } instead."
162
+ end
163
+ should matcher.description do
164
+ if expected
165
+ instantiate_variables_from_assigns do
166
+ expected_value = eval(expected,
167
+ self.send(:binding),
168
+ __FILE__,
169
+ __LINE__)
170
+ matcher = matcher.to(expected_value)
171
+ end
172
+ else
173
+ expected_value = instance_eval(&block)
174
+ matcher = matcher.to(expected_value)
175
+ end
176
+ assert_accepts matcher, @controller
177
+ end
178
+ end
179
+
180
+ # Deprecated. See should_set_session
181
+ def should_return_from_session(key, expected)
182
+ warn "[DEPRECATION] should_require_attributes is deprecated. " <<
183
+ "Use should_set_session instead."
184
+ should_set_session(key, expected)
185
+ end
186
+
187
+ # Macro that creates a test asserting that the controller rendered the given template.
188
+ # Example:
189
+ #
190
+ # should_render_template :new
191
+ def should_render_template(template)
192
+ should "render template #{template.inspect}" do
193
+ assert_template template.to_s
194
+ end
195
+ end
196
+
197
+ # Macro that creates a test asserting that the controller rendered with the given layout.
198
+ # Example:
199
+ #
200
+ # should_render_with_layout 'special'
201
+ def should_render_with_layout(expected_layout = 'application')
202
+ matcher = render_with_layout(expected_layout)
203
+ if expected_layout
204
+ should matcher.description do
205
+ assert_accepts matcher, @controller
206
+ end
207
+ else
208
+ should "render without layout" do
209
+ assert_rejects matcher, @controller
210
+ end
211
+ end
212
+ end
213
+
214
+ # Macro that creates a test asserting that the controller rendered without a layout.
215
+ # Same as @should_render_with_layout false@
216
+ def should_render_without_layout
217
+ should_render_with_layout nil
218
+ end
219
+
220
+ # Macro that creates a test asserting that the controller returned a redirect to the given path.
221
+ # The given string is evaled to produce the resulting redirect path. All of the instance variables
222
+ # set by the controller are available to the evaled string.
223
+ # Example:
224
+ #
225
+ # should_redirect_to("the user's profile") { user_url(@user) }
226
+ def should_redirect_to(description, &block)
227
+ unless block
228
+ warn "[DEPRECATION] should_redirect_to without a block is " <<
229
+ "deprecated. Use should_redirect_to('somewhere') { } instead."
230
+ end
231
+ should "redirect to #{description}" do
232
+ if block
233
+ url = instance_eval(&block)
234
+ else
235
+ instantiate_variables_from_assigns do
236
+ url = eval(description, self.send(:binding), __FILE__, __LINE__)
237
+ end
238
+ end
239
+ assert_redirected_to url
240
+ end
241
+ end
242
+
243
+ # Macro that creates a routing test. It tries to use the given HTTP
244
+ # +method+ on the given +path+, and asserts that it routes to the
245
+ # given +options+.
246
+ #
247
+ # If you don't specify a :controller, it will try to guess the controller
248
+ # based on the current test.
249
+ #
250
+ # +to_param+ is called on the +options+ given.
251
+ #
252
+ # Examples:
253
+ #
254
+ # should_route :get, "/posts", :controller => :posts, :action => :index
255
+ # should_route :get, "/posts/new", :action => :new
256
+ # should_route :post, "/posts", :action => :create
257
+ # should_route :get, "/posts/1", :action => :show, :id => 1
258
+ # should_route :edit, "/posts/1", :action => :show, :id => 1
259
+ # should_route :put, "/posts/1", :action => :update, :id => 1
260
+ # should_route :delete, "/posts/1", :action => :destroy, :id => 1
261
+ # should_route :get, "/users/1/posts/1",
262
+ # :action => :show, :id => 1, :user_id => 1
263
+ #
264
+ def should_route(method, path, options)
265
+ unless options[:controller]
266
+ options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize
267
+ end
268
+
269
+ matcher = route(method, path).to(options)
270
+
271
+ should matcher.description do
272
+ assert_accepts matcher.in_context(self), self
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,37 @@
1
+ require 'shoulda/action_controller/matchers/assign_to_matcher'
2
+ require 'shoulda/action_controller/matchers/filter_param_matcher'
3
+ require 'shoulda/action_controller/matchers/set_the_flash_matcher'
4
+ require 'shoulda/action_controller/matchers/render_with_layout_matcher'
5
+ require 'shoulda/action_controller/matchers/respond_with_matcher'
6
+ require 'shoulda/action_controller/matchers/respond_with_content_type_matcher'
7
+ require 'shoulda/action_controller/matchers/set_session_matcher'
8
+ require 'shoulda/action_controller/matchers/route_matcher'
9
+
10
+ module Shoulda # :nodoc:
11
+ module ActionController # :nodoc:
12
+
13
+ # By using the macro helpers you can quickly and easily create concise and
14
+ # easy to read test suites.
15
+ #
16
+ # This code segment:
17
+ #
18
+ # describe UsersController, "on GET to show with a valid id" do
19
+ # before(:each) do
20
+ # get :show, :id => User.first.to_param
21
+ # end
22
+ #
23
+ # it { should assign_to(:user) }
24
+ # it { should respond_with(:success) }
25
+ # it { should render_template(:show) }
26
+ # it { should not_set_the_flash) }
27
+ #
28
+ # it "should do something else really cool" do
29
+ # assigns[:user].id.should == 1
30
+ # end
31
+ # end
32
+ #
33
+ # Would produce 5 tests for the show action
34
+ module Matchers
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,109 @@
1
+ module Shoulda # :nodoc:
2
+ module ActionController # :nodoc:
3
+ module Matchers
4
+
5
+ # Ensures that the controller assigned to the named instance variable.
6
+ #
7
+ # Options:
8
+ # * <tt>with_kind_of</tt> - The expected class of the instance variable
9
+ # being checked.
10
+ # * <tt>with</tt> - The value that should be assigned.
11
+ #
12
+ # Example:
13
+ #
14
+ # it { should assign_to(:user) }
15
+ # it { should_not assign_to(:user) }
16
+ # it { should assign_to(:user).with_kind_of(User) }
17
+ # it { should assign_to(:user).with(@user) }
18
+ def assign_to(variable)
19
+ AssignToMatcher.new(variable)
20
+ end
21
+
22
+ class AssignToMatcher # :nodoc:
23
+
24
+ def initialize(variable)
25
+ @variable = variable.to_s
26
+ end
27
+
28
+ def with_kind_of(expected_class)
29
+ @expected_class = expected_class
30
+ self
31
+ end
32
+
33
+ def with(expected_value)
34
+ @expected_value = expected_value
35
+ self
36
+ end
37
+
38
+ def matches?(controller)
39
+ @controller = controller
40
+ assigned_value? && kind_of_expected_class? && equal_to_expected_value?
41
+ end
42
+
43
+ attr_reader :failure_message, :negative_failure_message
44
+
45
+ def description
46
+ description = "assign @#{@variable}"
47
+ description << " with a kind of #{@expected_class}" if @expected_class
48
+ description
49
+ end
50
+
51
+ private
52
+
53
+ def assigned_value?
54
+ if assigned_value.nil?
55
+ @failure_message =
56
+ "Expected action to assign a value for @#{@variable}"
57
+ false
58
+ else
59
+ @negative_failure_message =
60
+ "Didn't expect action to assign a value for @#{@variable}, " <<
61
+ "but it was assigned to #{assigned_value.inspect}"
62
+ true
63
+ end
64
+ end
65
+
66
+ def kind_of_expected_class?
67
+ return true unless @expected_class
68
+ if assigned_value.kind_of?(@expected_class)
69
+ @negative_failure_message =
70
+ "Didn't expect action to assign a kind of #{@expected_class} " <<
71
+ "for #{@variable}, but got one anyway"
72
+ true
73
+ else
74
+ @failure_message =
75
+ "Expected action to assign a kind of #{@expected_class} " <<
76
+ "for #{@variable}, but got #{@variable.inspect} " <<
77
+ "(#{@variable.class.name})"
78
+ false
79
+ end
80
+ end
81
+
82
+ def equal_to_expected_value?
83
+ return true unless @expected_value
84
+ if @expected_value == assigned_value
85
+ @negative_failure_message =
86
+ "Didn't expect action to assign #{@expected_value.inspect} " <<
87
+ "for #{@variable}, but got it anyway"
88
+ true
89
+ else
90
+ @failure_message =
91
+ "Expected action to assign #{@expected_value.inspect} " <<
92
+ "for #{@variable}, but got #{assigned_value.inspect}"
93
+ false
94
+ end
95
+ end
96
+
97
+ def assigned_value
98
+ assigns[@variable]
99
+ end
100
+
101
+ def assigns
102
+ @controller.response.template.assigns
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+ end
109
+ end