juozasg-couchrest 0.10.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/LICENSE +176 -0
- data/README.rdoc +67 -0
- data/Rakefile +86 -0
- data/THANKS +15 -0
- data/bin/couchapp +58 -0
- data/bin/couchdir +20 -0
- data/bin/couchview +48 -0
- data/examples/model/example.rb +138 -0
- data/examples/word_count/markov +38 -0
- data/examples/word_count/views/books/chunked-map.js +3 -0
- data/examples/word_count/views/books/united-map.js +1 -0
- data/examples/word_count/views/markov/chain-map.js +6 -0
- data/examples/word_count/views/markov/chain-reduce.js +7 -0
- data/examples/word_count/views/word_count/count-map.js +6 -0
- data/examples/word_count/views/word_count/count-reduce.js +3 -0
- data/examples/word_count/word_count.rb +67 -0
- data/examples/word_count/word_count_query.rb +39 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/core/database.rb +173 -0
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +60 -0
- data/lib/couchrest/core/model.rb +557 -0
- data/lib/couchrest/core/server.rb +51 -0
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/file_manager.rb +317 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +44 -0
- data/lib/couchrest/helper/templates/bar.txt +11 -0
- data/lib/couchrest/helper/templates/example-map.js +8 -0
- data/lib/couchrest/helper/templates/example-reduce.js +10 -0
- data/lib/couchrest/helper/templates/index.html +26 -0
- data/lib/couchrest/monkeypatches.rb +24 -0
- data/lib/couchrest.rb +125 -0
- data/spec/couchapp_spec.rb +87 -0
- data/spec/couchrest/core/couchrest_spec.rb +191 -0
- data/spec/couchrest/core/database_spec.rb +478 -0
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +96 -0
- data/spec/couchrest/core/model_spec.rb +660 -0
- data/spec/couchrest/helpers/file_manager_spec.rb +203 -0
- data/spec/couchrest/helpers/pager_spec.rb +122 -0
- data/spec/couchrest/helpers/streamer_spec.rb +23 -0
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +11 -0
- data/spec/fixtures/views/lib.js +3 -0
- data/spec/fixtures/views/test_view/lib.js +3 -0
- data/spec/fixtures/views/test_view/only-map.js +4 -0
- data/spec/fixtures/views/test_view/test-map.js +3 -0
- data/spec/fixtures/views/test_view/test-reduce.js +3 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +14 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +154 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CouchRest::Document, "[]=" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@doc = CouchRest::Document.new
|
|
6
|
+
end
|
|
7
|
+
it "should work" do
|
|
8
|
+
@doc["enamel"].should == nil
|
|
9
|
+
@doc["enamel"] = "Strong"
|
|
10
|
+
@doc["enamel"].should == "Strong"
|
|
11
|
+
end
|
|
12
|
+
it "[]= should convert to string" do
|
|
13
|
+
@doc["enamel"].should == nil
|
|
14
|
+
@doc[:enamel] = "Strong"
|
|
15
|
+
@doc["enamel"].should == "Strong"
|
|
16
|
+
end
|
|
17
|
+
it "should read as a string" do
|
|
18
|
+
@doc[:enamel] = "Strong"
|
|
19
|
+
@doc[:enamel].should == "Strong"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe CouchRest::Document, "new" do
|
|
24
|
+
before(:each) do
|
|
25
|
+
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
|
|
26
|
+
end
|
|
27
|
+
it "should create itself from a Hash" do
|
|
28
|
+
@doc["key"].should == [1,2,3]
|
|
29
|
+
@doc["more"].should == "values"
|
|
30
|
+
end
|
|
31
|
+
it "should not have rev and id" do
|
|
32
|
+
@doc.rev.should be_nil
|
|
33
|
+
@doc.id.should be_nil
|
|
34
|
+
end
|
|
35
|
+
it "should freak out when saving without a database" do
|
|
36
|
+
lambda{@doc.save}.should raise_error(ArgumentError)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# move to database spec
|
|
41
|
+
describe CouchRest::Document, "saving using a database" do
|
|
42
|
+
before(:all) do
|
|
43
|
+
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
|
|
44
|
+
@db = reset_test_db!
|
|
45
|
+
@resp = @db.save(@doc)
|
|
46
|
+
end
|
|
47
|
+
it "should apply the database" do
|
|
48
|
+
@doc.database.should == @db
|
|
49
|
+
end
|
|
50
|
+
it "should get id and rev" do
|
|
51
|
+
@doc.id.should == @resp["id"]
|
|
52
|
+
@doc.rev.should == @resp["rev"]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "getting from a database" do
|
|
57
|
+
before(:all) do
|
|
58
|
+
@db = reset_test_db!
|
|
59
|
+
@resp = @db.save({
|
|
60
|
+
"key" => "value"
|
|
61
|
+
})
|
|
62
|
+
@doc = @db.get @resp['id']
|
|
63
|
+
end
|
|
64
|
+
it "should return a document" do
|
|
65
|
+
@doc.should be_an_instance_of(CouchRest::Document)
|
|
66
|
+
end
|
|
67
|
+
it "should have a database" do
|
|
68
|
+
@doc.database.should == @db
|
|
69
|
+
end
|
|
70
|
+
it "should be saveable and resavable" do
|
|
71
|
+
@doc["more"] = "keys"
|
|
72
|
+
@doc.save
|
|
73
|
+
@db.get(@resp['id'])["more"].should == "keys"
|
|
74
|
+
@doc["more"] = "these keys"
|
|
75
|
+
@doc.save
|
|
76
|
+
@db.get(@resp['id'])["more"].should == "these keys"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "destroying a document from a db" do
|
|
81
|
+
before(:all) do
|
|
82
|
+
@db = reset_test_db!
|
|
83
|
+
@resp = @db.save({
|
|
84
|
+
"key" => "value"
|
|
85
|
+
})
|
|
86
|
+
@doc = @db.get @resp['id']
|
|
87
|
+
end
|
|
88
|
+
it "should make it disappear" do
|
|
89
|
+
@doc.destroy
|
|
90
|
+
lambda{@db.get @resp['id']}.should raise_error
|
|
91
|
+
end
|
|
92
|
+
it "should error when there's no db" do
|
|
93
|
+
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
|
|
94
|
+
lambda{@doc.destroy}.should raise_error(ArgumentError)
|
|
95
|
+
end
|
|
96
|
+
end
|