rackjson 0.3.0 → 0.3.1
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.
- data/VERSION +1 -1
- data/lib/rackjson/request.rb +2 -2
- data/rackjson.gemspec +2 -2
- data/test/test_resource.rb +26 -16
- metadata +2 -2
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.3. | 
| 1 | 
            +
            0.3.1
         | 
    
        data/lib/rackjson/request.rb
    CHANGED
    
    | @@ -18,11 +18,11 @@ module Rack::JSON | |
| 18 18 | 
             
                end
         | 
| 19 19 |  | 
| 20 20 | 
             
                def collection_path?
         | 
| 21 | 
            -
                  self.path_info.match  | 
| 21 | 
            +
                  self.path_info.match /^\/[\w-]+$/
         | 
| 22 22 | 
             
                end
         | 
| 23 23 |  | 
| 24 24 | 
             
                def member_path?
         | 
| 25 | 
            -
                  self.path_info.match /^\/\w | 
| 25 | 
            +
                  self.path_info.match /^\/\w+\/[\w-]+$/
         | 
| 26 26 | 
             
                end
         | 
| 27 27 |  | 
| 28 28 | 
             
                def json
         | 
    
        data/rackjson.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{rackjson}
         | 
| 8 | 
            -
              s.version = "0.3. | 
| 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- | 
| 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 = [
         | 
    
        data/test/test_resource.rb
    CHANGED
    
    | @@ -18,36 +18,36 @@ class ResourceTest < Test::Unit::TestCase | |
| 18 18 | 
             
                },  :collections => [:testing], :db => @db 
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 31 | 
            +
              test "test get root" do
         | 
| 32 32 | 
             
                get '/'
         | 
| 33 33 | 
             
                assert_equal 404, last_response.status
         | 
| 34 34 | 
             
              end
         | 
| 35 35 |  | 
| 36 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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 | 
            -
               | 
| 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. | 
| 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- | 
| 12 | 
            +
            date: 2010-05-12 00:00:00 +01:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         |