sinatra_resource 0.4.21 → 0.4.22

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 (88) hide show
  1. data/Gemfile +18 -0
  2. data/Gemfile.lock +51 -0
  3. data/README.mdown +1 -1
  4. data/VERSION +1 -1
  5. data/examples/datacatalog/.bundle/config +2 -0
  6. data/examples/datacatalog/Gemfile +14 -0
  7. data/examples/datacatalog/Gemfile.lock +33 -0
  8. data/examples/datacatalog/Rakefile +2 -2
  9. data/examples/datacatalog/app.rb +0 -2
  10. data/examples/datacatalog/config/config.rb +5 -7
  11. data/examples/datacatalog/lib/base.rb +2 -2
  12. data/examples/datacatalog/lib/resource.rb +5 -5
  13. data/examples/datacatalog/lib/roles.rb +2 -2
  14. data/examples/datacatalog/model_helpers/search.rb +6 -6
  15. data/examples/datacatalog/models/categorization.rb +1 -1
  16. data/examples/datacatalog/models/note.rb +1 -1
  17. data/examples/datacatalog/models/source.rb +3 -3
  18. data/examples/datacatalog/models/usage.rb +2 -2
  19. data/examples/datacatalog/models/user.rb +7 -7
  20. data/examples/datacatalog/resources/categories.rb +7 -7
  21. data/examples/datacatalog/resources/categories_sources.rb +4 -4
  22. data/examples/datacatalog/resources/notes.rb +1 -1
  23. data/examples/datacatalog/resources/sources.rb +3 -3
  24. data/examples/datacatalog/resources/sources_usages.rb +3 -3
  25. data/examples/datacatalog/resources/users.rb +3 -3
  26. data/examples/datacatalog/tasks/db.rake +2 -2
  27. data/examples/datacatalog/tasks/test.rake +1 -1
  28. data/examples/datacatalog/test/helpers/assertions/assert_include.rb +1 -1
  29. data/examples/datacatalog/test/helpers/assertions/assert_not_include.rb +1 -1
  30. data/examples/datacatalog/test/helpers/lib/model_factories.rb +7 -7
  31. data/examples/datacatalog/test/helpers/lib/model_helpers.rb +1 -1
  32. data/examples/datacatalog/test/helpers/lib/request_helpers.rb +7 -7
  33. data/examples/datacatalog/test/helpers/resource_test_helper.rb +1 -1
  34. data/examples/datacatalog/test/helpers/shared/api_keys.rb +11 -11
  35. data/examples/datacatalog/test/helpers/shared/common_body_responses.rb +1 -1
  36. data/examples/datacatalog/test/helpers/shared/model_counts.rb +2 -2
  37. data/examples/datacatalog/test/helpers/shared/status_codes.rb +4 -4
  38. data/examples/datacatalog/test/helpers/test_cases/resource_test_case.rb +4 -4
  39. data/examples/datacatalog/test/helpers/test_helper.rb +4 -10
  40. data/examples/datacatalog/test/models/categorization_test.rb +6 -6
  41. data/examples/datacatalog/test/models/category_test.rb +8 -8
  42. data/examples/datacatalog/test/models/note_test.rb +6 -6
  43. data/examples/datacatalog/test/models/search_test.rb +4 -4
  44. data/examples/datacatalog/test/models/source_test.rb +5 -5
  45. data/examples/datacatalog/test/models/user_test.rb +11 -11
  46. data/examples/datacatalog/test/resources/categories/categories_delete_test.rb +12 -12
  47. data/examples/datacatalog/test/resources/categories/categories_get_many_test.rb +9 -9
  48. data/examples/datacatalog/test/resources/categories/categories_get_one_test.rb +7 -7
  49. data/examples/datacatalog/test/resources/categories/categories_post_test.rb +16 -16
  50. data/examples/datacatalog/test/resources/categories/categories_put_test.rb +17 -17
  51. data/examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb +25 -25
  52. data/examples/datacatalog/test/resources/categories_sources/categories_sources_get_many_test.rb +5 -5
  53. data/examples/datacatalog/test/resources/categories_sources/categories_sources_get_one_test.rb +15 -15
  54. data/examples/datacatalog/test/resources/categories_sources/categories_sources_post_test.rb +31 -31
  55. data/examples/datacatalog/test/resources/categories_sources/categories_sources_put_test.rb +41 -41
  56. data/examples/datacatalog/test/resources/notes/notes_get_many_test.rb +15 -15
  57. data/examples/datacatalog/test/resources/notes/notes_get_one_test.rb +7 -7
  58. data/examples/datacatalog/test/resources/notes/notes_post_test.rb +12 -12
  59. data/examples/datacatalog/test/resources/sources/sources_delete_test.rb +12 -12
  60. data/examples/datacatalog/test/resources/sources/sources_get_many_search_test.rb +20 -20
  61. data/examples/datacatalog/test/resources/sources/sources_get_many_test.rb +8 -8
  62. data/examples/datacatalog/test/resources/sources/sources_get_one_test.rb +17 -9
  63. data/examples/datacatalog/test/resources/sources/sources_post_test.rb +13 -13
  64. data/examples/datacatalog/test/resources/sources/sources_put_test.rb +30 -30
  65. data/examples/datacatalog/test/resources/sources_usages/sources_usages_delete_test.rb +24 -24
  66. data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_filter_test.rb +9 -9
  67. data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_test.rb +9 -9
  68. data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_one_test.rb +15 -15
  69. data/examples/datacatalog/test/resources/sources_usages/sources_usages_post_test.rb +16 -16
  70. data/examples/datacatalog/test/resources/sources_usages/sources_usages_put_test.rb +33 -33
  71. data/examples/datacatalog/test/resources/users/users_delete_test.rb +21 -21
  72. data/examples/datacatalog/test/resources/users/users_get_many_test.rb +16 -16
  73. data/examples/datacatalog/test/resources/users/users_get_one_test.rb +8 -8
  74. data/examples/datacatalog/test/resources/users/users_post_test.rb +13 -13
  75. data/examples/datacatalog/test/resources/users/users_put_test.rb +18 -18
  76. data/lib/builder/action_definitions.rb +8 -8
  77. data/lib/builder/helpers.rb +10 -12
  78. data/lib/builder/mongo_helpers.rb +13 -14
  79. data/lib/builder.rb +10 -10
  80. data/lib/exceptions.rb +1 -1
  81. data/lib/resource.rb +20 -20
  82. data/lib/roles.rb +2 -2
  83. data/lib/utility.rb +2 -2
  84. data/notes/permissions.mdown +6 -6
  85. data/sinatra_resource.gemspec +9 -4
  86. data/spec/spec_helper.rb +1 -1
  87. data/spec/utility_spec.rb +2 -2
  88. metadata +30 -4
@@ -8,7 +8,7 @@ module RequestHelpers
8
8
  Crack::JSON.parse(s)
9
9
  end
10
10
  end
11
-
11
+
12
12
  def assert_properties(correct, parsed_document)
13
13
  correct.each do |property|
14
14
  assert_include property, parsed_document
@@ -19,7 +19,7 @@ module RequestHelpers
19
19
  def self.included(includee)
20
20
  includee.extend(ClassMethods)
21
21
  end
22
-
22
+
23
23
  module ClassMethods
24
24
  def doc_properties(correct)
25
25
  test "document should only have correct attributes" do
@@ -34,13 +34,13 @@ module RequestHelpers
34
34
  end
35
35
  end
36
36
  end
37
-
37
+
38
38
  def invalid_param(s)
39
39
  test "should report #{s} as invalid" do
40
40
  assert_include s.to_s, parsed_response_body["errors"]["invalid_params"]
41
41
  end
42
42
  end
43
-
43
+
44
44
  def missing_param(s)
45
45
  test "should report missing #{s}" do
46
46
  assert_include "can't be empty", parsed_response_body["errors"][s.to_s]
@@ -55,7 +55,7 @@ module RequestHelpers
55
55
  assert_equal expected, last_response.headers['Location']
56
56
  end
57
57
  end
58
-
58
+
59
59
  def nested_location_header(parent_path, parent_ivar, child_path)
60
60
  test "should set Location header correctly" do
61
61
  base_uri = Config.environment_config["base_uri"]
@@ -67,8 +67,8 @@ module RequestHelpers
67
67
  assert_equal expected, last_response.headers['Location']
68
68
  end
69
69
  end
70
-
70
+
71
71
 
72
72
  end
73
-
73
+
74
74
  end
@@ -2,4 +2,4 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../../app')
3
3
 
4
4
  BAD_API_KEY = "123400005678"
5
- FAKE_ID = BSON::ObjectID.new.to_s
5
+ FAKE_ID = BSON::ObjectId.new.to_s
@@ -2,43 +2,43 @@ class ResourceTestCase
2
2
 
3
3
  shared "return 400 because no params were given" do
4
4
  use "return 400 Bad Request"
5
-
5
+
6
6
  test "body should say no params were given" do
7
7
  assert_include "errors", parsed_response_body
8
8
  assert_include "no_params", parsed_response_body["errors"]
9
9
  end
10
10
  end
11
11
 
12
- shared "return 400 because params were not empty" do
12
+ shared "return 400 because invalid params were present" do
13
13
  use "return 400 Bad Request"
14
-
15
- test "body should say params were non-empty" do
14
+
15
+ test "body should say invalid params were present" do
16
16
  assert_include "errors", parsed_response_body
17
- assert_include "non_empty_params", parsed_response_body["errors"]
17
+ assert_include "invalid_params", parsed_response_body["errors"]
18
18
  end
19
19
  end
20
-
20
+
21
21
  shared "return 401 because the API key is invalid" do
22
22
  use "return 401 Unauthorized"
23
-
23
+
24
24
  test "body should say the API key is invalid" do
25
25
  assert_include "errors", parsed_response_body
26
26
  assert_include "invalid_api_key", parsed_response_body["errors"]
27
27
  end
28
28
  end
29
-
29
+
30
30
  shared "return 401 because the API key is missing" do
31
31
  use "return 401 Unauthorized"
32
-
32
+
33
33
  test "body should say the API key is missing" do
34
34
  assert_include "errors", parsed_response_body
35
35
  assert_include "missing_api_key", parsed_response_body["errors"]
36
36
  end
37
37
  end
38
-
38
+
39
39
  shared "return 401 because the API key is unauthorized" do
40
40
  use "return 401 Unauthorized"
41
-
41
+
42
42
  test "body should say the API key is unauthorized" do
43
43
  assert_include "errors", parsed_response_body
44
44
  assert_include "unauthorized_api_key", parsed_response_body["errors"]
@@ -11,7 +11,7 @@ class ResourceTestCase
11
11
  assert_equal [], parsed_response_body
12
12
  end
13
13
  end
14
-
14
+
15
15
  shared "content type header indicates JSON" do
16
16
  test "should have JSON content type" do
17
17
  assert_equal "application/json", last_response.headers["Content-Type"]
@@ -1,5 +1,5 @@
1
1
  class ResourceTestCase
2
-
2
+
3
3
  # == categories
4
4
 
5
5
  shared "no change in category count" do
@@ -13,7 +13,7 @@ class ResourceTestCase
13
13
  assert_equal @category_count - 1, DataCatalog::Category.all.length
14
14
  end
15
15
  end
16
-
16
+
17
17
  shared "one new category" do
18
18
  test "should add one category document to database" do
19
19
  assert_equal @category_count + 1, DataCatalog::Category.all.length
@@ -1,5 +1,5 @@
1
1
  class ResourceTestCase
2
-
2
+
3
3
  shared "return 200 Ok" do
4
4
  test "status should be 200 Ok" do
5
5
  assert_equal 200, last_response.status
@@ -12,7 +12,7 @@ class ResourceTestCase
12
12
  test "status should be 201 Created" do
13
13
  assert_equal 201, last_response.status
14
14
  end
15
-
15
+
16
16
  test "location header should start with http://localhost" do
17
17
  assert_include "Location", last_response.headers
18
18
  generic_uri = %r{^http://localhost}
@@ -26,7 +26,7 @@ class ResourceTestCase
26
26
  test "status should be 204 No Content" do
27
27
  assert_equal 204, last_response.status
28
28
  end
29
-
29
+
30
30
  use "return an empty response body"
31
31
  use "content type header not set"
32
32
  end
@@ -65,7 +65,7 @@ class ResourceTestCase
65
65
 
66
66
  shared "return 404 Not Found with empty response body" do
67
67
  use "return 404 Not Found"
68
-
68
+
69
69
  use "return an empty response body"
70
70
  end
71
71
 
@@ -14,15 +14,15 @@ class ResourceTestCase < Test::Unit::TestCase
14
14
  )
15
15
  end
16
16
  end
17
-
17
+
18
18
  after :all do
19
19
  @users_by_role.each_pair { |role, user| user.destroy }
20
20
  end
21
-
21
+
22
22
  def user_for(role)
23
23
  @users_by_role[role]
24
24
  end
25
-
25
+
26
26
  def api_key_for(role)
27
27
  key = @users_by_role[role]._api_key
28
28
  raise "API key not found" unless key
@@ -32,5 +32,5 @@ class ResourceTestCase < Test::Unit::TestCase
32
32
  def valid_params_for(role)
33
33
  @valid_params.merge(:api_key => api_key_for(role))
34
34
  end
35
-
35
+
36
36
  end
@@ -1,19 +1,13 @@
1
1
  require 'rubygems'
2
2
 
3
- require 'test/unit'
4
-
3
+ require 'crack/json'
4
+ require 'pending'
5
5
  require 'rack/test'
6
6
  require 'rr'
7
-
8
- gem 'crack', '>= 0.1.4'
9
- require 'crack/json'
10
-
11
- gem 'tu-context', '>= 0.5.8'
7
+ require 'test/unit'
8
+ require 'timecop'
12
9
  require 'tu-context'
13
10
 
14
- gem 'pending', '>= 0.1.1'
15
- require 'pending'
16
-
17
11
  base = File.dirname(__FILE__)
18
12
  Dir.glob(base + '/lib/*.rb' ).each { |f| require f }
19
13
  Dir.glob(base + '/test_cases/*.rb').each { |f| require f }
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
2
2
 
3
3
  class CategorizationTest < ModelTestCase
4
-
4
+
5
5
  include DataCatalog
6
-
6
+
7
7
  context "Categorization" do
8
8
  before do
9
9
  @source = create_source
@@ -13,13 +13,13 @@ class CategorizationTest < ModelTestCase
13
13
  :category_id => @category.id
14
14
  )
15
15
  end
16
-
16
+
17
17
  after do
18
18
  @source.destroy
19
19
  @category.destroy
20
20
  @categorization.destroy
21
21
  end
22
-
22
+
23
23
  test "Categorization#source is correct" do
24
24
  assert_equal @source, @categorization.source
25
25
  end
@@ -27,11 +27,11 @@ class CategorizationTest < ModelTestCase
27
27
  test "Categorization#category is correct" do
28
28
  assert_equal @category, @categorization.category
29
29
  end
30
-
30
+
31
31
  test "Source#categorization is correct" do
32
32
  assert_equal [@categorization], @source.categorizations
33
33
  end
34
-
34
+
35
35
  test "Category#categorization is correct" do
36
36
  assert_equal [@categorization], @category.categorizations
37
37
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
2
2
 
3
3
  class CategoryTest < ModelTestCase
4
-
4
+
5
5
  include DataCatalog
6
6
 
7
7
  before do
@@ -15,33 +15,33 @@ class CategoryTest < ModelTestCase
15
15
  before do
16
16
  @category = Category.new(@required)
17
17
  end
18
-
18
+
19
19
  test "should be valid" do
20
20
  assert_equal true, @category.valid?
21
21
  end
22
22
  end
23
-
23
+
24
24
  [:name].each do |missing|
25
25
  context "missing #{missing}" do
26
26
  before do
27
27
  @category = Category.new(@required.delete_if { |k, v| k == missing })
28
28
  end
29
-
29
+
30
30
  missing_key(:category, missing)
31
31
  end
32
32
  end
33
33
  end
34
-
34
+
35
35
  context "Category with 0 categorizations" do
36
36
  before do
37
37
  @category = Category.create(@required)
38
38
  end
39
-
39
+
40
40
  test "#sources should be empty" do
41
41
  assert_equal [], @category.sources
42
42
  end
43
43
  end
44
-
44
+
45
45
  context "Category with 3 categorizations" do
46
46
  before do
47
47
  @category = Category.create(@required)
@@ -57,7 +57,7 @@ class CategoryTest < ModelTestCase
57
57
  )
58
58
  end
59
59
  end
60
-
60
+
61
61
  test "#sources should have 3 categorizations" do
62
62
  categorizations = @category.categorizations
63
63
  assert_equal 3, categorizations.length
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
2
2
 
3
3
  class NoteTest < ModelTestCase
4
-
4
+
5
5
  include DataCatalog
6
6
 
7
7
  context "Note" do
@@ -12,16 +12,16 @@ class NoteTest < ModelTestCase
12
12
  :user_id => @user.id
13
13
  }
14
14
  end
15
-
15
+
16
16
  after do
17
17
  @user.destroy
18
18
  end
19
-
19
+
20
20
  context "correct params" do
21
21
  before do
22
22
  @note = Note.new(@required)
23
23
  end
24
-
24
+
25
25
  test "should be valid" do
26
26
  assert_equal true, @note.valid?
27
27
  end
@@ -32,11 +32,11 @@ class NoteTest < ModelTestCase
32
32
  before do
33
33
  @note = Note.new(@required.delete_if { |k, v| k == missing })
34
34
  end
35
-
35
+
36
36
  missing_key(:note, missing)
37
37
  end
38
38
  end
39
39
 
40
40
  end
41
-
41
+
42
42
  end
@@ -25,20 +25,20 @@ class SearchUnitTest < ModelTestCase
25
25
  Search.tokens("The earth has an axial tilt of 23.439 degrees.")
26
26
  end
27
27
  end
28
-
28
+
29
29
  context "tokenize" do
30
30
  test "simple" do
31
31
  assert_equal %w(aerospace defense systems),
32
32
  Search.tokenize(["aerospace defense", "defense systems"])
33
33
  end
34
34
  end
35
-
35
+
36
36
  context "unstop" do
37
37
  test "simple" do
38
38
  assert_equal %w(big brown fox), Search.unstop(%w(the big brown fox))
39
39
  end
40
40
  end
41
-
41
+
42
42
  context "process" do
43
43
  test "simple" do
44
44
  assert_equal %w(aerospace defense systems),
@@ -50,5 +50,5 @@ class SearchUnitTest < ModelTestCase
50
50
  Search.process(["The earth has an axial tilt of 23.439 degrees."])
51
51
  end
52
52
  end
53
-
53
+
54
54
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
2
2
 
3
3
  class SourceTest < ModelTestCase
4
-
4
+
5
5
  include DataCatalog
6
6
 
7
7
  context "Source" do
@@ -11,12 +11,12 @@ class SourceTest < ModelTestCase
11
11
  :url => "http://moneybags.gov/data/2009"
12
12
  }
13
13
  end
14
-
14
+
15
15
  context "correct params" do
16
16
  before do
17
17
  @source = Source.new(@required)
18
18
  end
19
-
19
+
20
20
  test "should be valid" do
21
21
  assert_equal true, @source.valid?
22
22
  end
@@ -27,11 +27,11 @@ class SourceTest < ModelTestCase
27
27
  before do
28
28
  @source = Source.new(@required.delete_if { |k, v| k == missing })
29
29
  end
30
-
30
+
31
31
  missing_key(:source, missing)
32
32
  end
33
33
  end
34
34
 
35
35
  end
36
-
36
+
37
37
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
2
2
 
3
3
  class UserTest < ModelTestCase
4
-
4
+
5
5
  include DataCatalog
6
6
 
7
7
  context "User#new" do
@@ -11,27 +11,27 @@ class UserTest < ModelTestCase
11
11
  :role => "basic"
12
12
  }
13
13
  end
14
-
14
+
15
15
  context "correct params" do
16
16
  before do
17
17
  @user = User.new(@required)
18
18
  end
19
-
19
+
20
20
  test "should be valid" do
21
21
  assert_equal true, @user.valid?
22
22
  end
23
-
23
+
24
24
  test "should not set api_key" do
25
25
  assert_equal nil, @user._api_key
26
26
  end
27
27
  end
28
-
28
+
29
29
  [:name, :role].each do |missing|
30
30
  context "missing #{missing}" do
31
31
  before do
32
32
  @user = User.new(@required.delete_if { |k, v| k == missing })
33
33
  end
34
-
34
+
35
35
  missing_key(:user, missing)
36
36
  end
37
37
  end
@@ -41,7 +41,7 @@ class UserTest < ModelTestCase
41
41
  @user = User.new(@required.merge(:role => "owner"))
42
42
  # owner is not a 'fixed' role, it is a 'relative' role
43
43
  end
44
-
44
+
45
45
  test "should be invalid" do
46
46
  assert_equal false, @user.valid?
47
47
  end
@@ -58,20 +58,20 @@ class UserTest < ModelTestCase
58
58
  before do
59
59
  @user = User.create(@required)
60
60
  end
61
-
61
+
62
62
  after do
63
63
  @user.destroy
64
64
  end
65
-
65
+
66
66
  test "should be valid" do
67
67
  assert_equal true, @user.valid?
68
68
  end
69
-
69
+
70
70
  test "should set api_key" do
71
71
  assert_not_equal nil, @user._api_key
72
72
  end
73
73
  end
74
74
  end
75
75
  end
76
-
76
+
77
77
  end
@@ -20,7 +20,7 @@ class CategoriesDeleteResourceTest < ResourceTestCase
20
20
  before do
21
21
  delete "/#{@category.id}"
22
22
  end
23
-
23
+
24
24
  use "return 401 because the API key is missing"
25
25
  use "no change in category count"
26
26
  end
@@ -29,18 +29,18 @@ class CategoriesDeleteResourceTest < ResourceTestCase
29
29
  before do
30
30
  delete "/#{@category.id}", :api_key => BAD_API_KEY
31
31
  end
32
-
32
+
33
33
  use "return 401 because the API key is invalid"
34
34
  use "no change in category count"
35
35
  end
36
36
  end
37
-
37
+
38
38
  %w(basic).each do |role|
39
39
  context "#{role} : delete /:fake_id" do
40
40
  before do
41
41
  delete "/#{FAKE_ID}", :api_key => api_key_for(role)
42
42
  end
43
-
43
+
44
44
  use "return 401 because the API key is unauthorized"
45
45
  use "no change in category count"
46
46
  end
@@ -51,7 +51,7 @@ class CategoriesDeleteResourceTest < ResourceTestCase
51
51
  :api_key => api_key_for(role),
52
52
  :key => "value"
53
53
  end
54
-
54
+
55
55
  use "return 401 because the API key is unauthorized"
56
56
  use "no change in category count"
57
57
  end
@@ -60,7 +60,7 @@ class CategoriesDeleteResourceTest < ResourceTestCase
60
60
  before do
61
61
  delete "/#{@category.id}", :api_key => api_key_for(role)
62
62
  end
63
-
63
+
64
64
  use "return 401 because the API key is unauthorized"
65
65
  use "no change in category count"
66
66
  end
@@ -71,7 +71,7 @@ class CategoriesDeleteResourceTest < ResourceTestCase
71
71
  before do
72
72
  delete "/#{FAKE_ID}", :api_key => api_key_for(role)
73
73
  end
74
-
74
+
75
75
  use "return 404 Not Found with empty response body"
76
76
  use "no change in category count"
77
77
  end
@@ -82,8 +82,8 @@ class CategoriesDeleteResourceTest < ResourceTestCase
82
82
  :api_key => api_key_for(role),
83
83
  :key => "value"
84
84
  end
85
-
86
- use "return 400 because params were not empty"
85
+
86
+ use "return 400 because invalid params were present"
87
87
  use "no change in category count"
88
88
  end
89
89
 
@@ -91,15 +91,15 @@ class CategoriesDeleteResourceTest < ResourceTestCase
91
91
  before do
92
92
  delete "/#{@category.id}", :api_key => api_key_for(role)
93
93
  end
94
-
94
+
95
95
  use "return 204 No Content"
96
96
  use "one less category"
97
-
97
+
98
98
  test "callbacks should work" do
99
99
  actual = last_response.headers['X-Test-Callbacks']
100
100
  assert_equal "before_destroy after_destroy", actual
101
101
  end
102
102
  end
103
103
  end
104
-
104
+
105
105
  end
@@ -14,11 +14,11 @@ class CategoriesGetManyResourceTest < ResourceTestCase
14
14
  create_category(:name => "Category #{i}")
15
15
  end
16
16
  end
17
-
17
+
18
18
  after do
19
19
  @categories.each { |x| x.destroy } if @categories
20
20
  end
21
-
21
+
22
22
  CATEGORIES = ["Category 0", "Category 1", "Category 2"].sort
23
23
 
24
24
  context "get /" do
@@ -26,15 +26,15 @@ class CategoriesGetManyResourceTest < ResourceTestCase
26
26
  before do
27
27
  get "/"
28
28
  end
29
-
29
+
30
30
  use "return 401 because the API key is missing"
31
31
  end
32
-
32
+
33
33
  context "incorrect API key" do
34
34
  before do
35
35
  get "/", :api_key => BAD_API_KEY
36
36
  end
37
-
37
+
38
38
  use "return 401 because the API key is invalid"
39
39
  end
40
40
  end
@@ -45,18 +45,18 @@ class CategoriesGetManyResourceTest < ResourceTestCase
45
45
  get "/", :api_key => api_key_for(role)
46
46
  @members = parsed_response_body['members']
47
47
  end
48
-
48
+
49
49
  use "return 200 Ok"
50
-
50
+
51
51
  test "body should have 3 categories" do
52
52
  assert_equal 3, @members.length
53
53
  end
54
-
54
+
55
55
  test "body should have correct category names" do
56
56
  actual = @members.map { |e| e["name"] }
57
57
  assert_equal CATEGORIES, actual.sort
58
58
  end
59
-
59
+
60
60
  test "members should only have correct attributes" do
61
61
  correct = %w(name log sources id created_at updated_at)
62
62
  @members.each do |member|