rackjson 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -18,11 +18,11 @@ module Rack::JSON
18
18
  end
19
19
 
20
20
  def collection_path?
21
- self.path_info.match /^\/\w+$/
21
+ self.path_info.match /^\/[\w-]+$/
22
22
  end
23
23
 
24
24
  def member_path?
25
- self.path_info.match /^\/\w+\/\w+$/
25
+ self.path_info.match /^\/\w+\/[\w-]+$/
26
26
  end
27
27
 
28
28
  def json
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rackjson}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oliver Nightingale"]
12
- s.date = %q{2010-05-06}
12
+ s.date = %q{2010-05-12}
13
13
  s.description = %q{A rack end point for storing json documents.}
14
14
  s.email = %q{oliver.n@new-bamboo.co.uk}
15
15
  s.extra_rdoc_files = [
@@ -18,36 +18,36 @@ class ResourceTest < Test::Unit::TestCase
18
18
  }, :collections => [:testing], :db => @db
19
19
  end
20
20
 
21
- def test_get_non_existing_resource
21
+ test "test get non existing resource" do
22
22
  get '/blah'
23
23
  assert_equal 404, last_response.status
24
24
  end
25
25
 
26
- def test_post_non_existing_resource
26
+ test "test post non existing resource" do
27
27
  post '/blah', '{ "title": "hello!" }'
28
28
  assert_equal 404, last_response.status
29
29
  end
30
30
 
31
- def test_get_root
31
+ test "test get root" do
32
32
  get '/'
33
33
  assert_equal 404, last_response.status
34
34
  end
35
35
 
36
- def test_index_method
36
+ test "test index method" do
37
37
  @collection.save({:testing => true})
38
38
  get '/testing'
39
39
  assert last_response.ok?
40
40
  assert_match /"testing":true/, last_response.body
41
41
  end
42
42
 
43
- def test_creating_a_document
43
+ test "test creating a document" do
44
44
  put '/testing/1', '{"title": "testing"}'
45
45
  assert_equal 201, last_response.status
46
46
  assert_match /"_id":1/, last_response.body
47
47
  assert_match /"title":"testing"/, last_response.body
48
48
  end
49
49
 
50
- def test_show_a_single_document
50
+ test "test show a single document" do
51
51
  put '/testing/1', '{"title": "testing first"}'
52
52
  post '/testing', '{"title": "testing second"}'
53
53
  get '/testing/1'
@@ -56,13 +56,13 @@ class ResourceTest < Test::Unit::TestCase
56
56
  assert_no_match /"title":"testing second"/, last_response.body
57
57
  end
58
58
 
59
- def test_not_finding_a_specific_document
59
+ test "test not finding a specific document" do
60
60
  get '/testing/1'
61
61
  assert_equal 404, last_response.status
62
62
  assert_equal "document not found", last_response.body
63
63
  end
64
64
 
65
- def test_index_method_with_query_parameters
65
+ test "test index method with query parameters" do
66
66
  @collection.save({:testing => true, :rating => 5, :title => 'testing'})
67
67
  get '/testing?[?title=testing]'
68
68
  assert last_response.ok?
@@ -72,7 +72,7 @@ class ResourceTest < Test::Unit::TestCase
72
72
  assert_match /"title":"testing"/, last_response.body
73
73
  end
74
74
 
75
- def test_index_method_with_sort
75
+ test "test index method with sort" do
76
76
  @collection.save({:testing => true, :rating => 5, :title => 'testing'})
77
77
  get '/testing?[/title]'
78
78
  assert last_response.ok?
@@ -82,14 +82,14 @@ class ResourceTest < Test::Unit::TestCase
82
82
  assert_match /"title":"testing"/, last_response.body
83
83
  end
84
84
 
85
- def test_putting_a_new_document
85
+ test "test putting a new document" do
86
86
  put '/testing/1', '{"title": "testing update"}'
87
87
  assert_equal 201, last_response.status
88
88
  assert_match /"_id":1/, last_response.body
89
89
  assert_match /"title":"testing update"/, last_response.body
90
90
  end
91
91
 
92
- def test_updating_a_document
92
+ test "test updating a document" do
93
93
  @collection.save({:title => 'testing', :_id => 1})
94
94
  put '/testing/1', '{"title": "testing update"}'
95
95
  assert last_response.ok?
@@ -97,7 +97,7 @@ class ResourceTest < Test::Unit::TestCase
97
97
  assert_match /"title":"testing update"/, last_response.body
98
98
  end
99
99
 
100
- def test_updating_a_document_with_matching_query_params
100
+ test "test updating a document with matching query params" do
101
101
  @collection.save({:title => 'testing', :_id => 1, :user_id => 1})
102
102
  put '/testing/1?[?user_id=1]', '{"title": "testing update"}'
103
103
  assert last_response.ok?
@@ -105,7 +105,7 @@ class ResourceTest < Test::Unit::TestCase
105
105
  assert_match /"title":"testing update"/, last_response.body
106
106
  end
107
107
 
108
- def test_updating_a_document_with_non_matching_query_params
108
+ test "test updating a document with non matching query params" do
109
109
  @collection.save({:title => 'testing', :_id => 1, :user_id => 2})
110
110
  put '/testing/1?[?user_id=1]', '{"title": "testing update"}'
111
111
  assert_equal 404, last_response.status
@@ -113,7 +113,7 @@ class ResourceTest < Test::Unit::TestCase
113
113
  assert_nil @collection.find_one(:_id => 1, :user_id => 1)
114
114
  end
115
115
 
116
- def test_deleting_a_document
116
+ test "test deleting a document" do
117
117
  @collection.save({:title => 'testing', :_id => 1})
118
118
  assert @collection.find_one({:_id => 1})
119
119
  delete '/testing/1'
@@ -121,14 +121,24 @@ class ResourceTest < Test::Unit::TestCase
121
121
  assert_nil @collection.find_one({:_id => 1})
122
122
  end
123
123
 
124
- def test_deleting_only_with_member_path
124
+ test "test deleting only with member path" do
125
125
  delete '/testing'
126
126
  assert_equal 405, last_response.status
127
127
  end
128
128
 
129
- def test_posting_a_document
129
+ test "test posting a document" do
130
130
  post '/testing', '{"title": "testing"}'
131
131
  assert last_response.status == 201
132
132
  assert_match /"title":"testing"/, last_response.body
133
133
  end
134
+
135
+ test "using a string id for a document" do
136
+ put '/testing/string-id-1', '{"title": "testing"}'
137
+ put '/testing/another-string-id-2', '{"foo": "bar"}'
138
+ assert last_response.status == 201
139
+ get '/testing/string-id-1'
140
+ assert_equal 'testing', @collection.find_one({:_id => 'string-id-1'})['title']
141
+ assert_no_match /"foo":"bar"/, last_response.body
142
+ assert_match /"title":"testing"/, last_response.body
143
+ end
134
144
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackjson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Nightingale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-06 00:00:00 +01:00
12
+ date: 2010-05-12 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency