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.
Files changed (55) hide show
  1. data/LICENSE +176 -0
  2. data/README.rdoc +67 -0
  3. data/Rakefile +86 -0
  4. data/THANKS +15 -0
  5. data/bin/couchapp +58 -0
  6. data/bin/couchdir +20 -0
  7. data/bin/couchview +48 -0
  8. data/examples/model/example.rb +138 -0
  9. data/examples/word_count/markov +38 -0
  10. data/examples/word_count/views/books/chunked-map.js +3 -0
  11. data/examples/word_count/views/books/united-map.js +1 -0
  12. data/examples/word_count/views/markov/chain-map.js +6 -0
  13. data/examples/word_count/views/markov/chain-reduce.js +7 -0
  14. data/examples/word_count/views/word_count/count-map.js +6 -0
  15. data/examples/word_count/views/word_count/count-reduce.js +3 -0
  16. data/examples/word_count/word_count.rb +67 -0
  17. data/examples/word_count/word_count_query.rb +39 -0
  18. data/lib/couchrest/commands/generate.rb +71 -0
  19. data/lib/couchrest/commands/push.rb +103 -0
  20. data/lib/couchrest/core/database.rb +173 -0
  21. data/lib/couchrest/core/design.rb +89 -0
  22. data/lib/couchrest/core/document.rb +60 -0
  23. data/lib/couchrest/core/model.rb +557 -0
  24. data/lib/couchrest/core/server.rb +51 -0
  25. data/lib/couchrest/core/view.rb +4 -0
  26. data/lib/couchrest/helper/file_manager.rb +317 -0
  27. data/lib/couchrest/helper/pager.rb +103 -0
  28. data/lib/couchrest/helper/streamer.rb +44 -0
  29. data/lib/couchrest/helper/templates/bar.txt +11 -0
  30. data/lib/couchrest/helper/templates/example-map.js +8 -0
  31. data/lib/couchrest/helper/templates/example-reduce.js +10 -0
  32. data/lib/couchrest/helper/templates/index.html +26 -0
  33. data/lib/couchrest/monkeypatches.rb +24 -0
  34. data/lib/couchrest.rb +125 -0
  35. data/spec/couchapp_spec.rb +87 -0
  36. data/spec/couchrest/core/couchrest_spec.rb +191 -0
  37. data/spec/couchrest/core/database_spec.rb +478 -0
  38. data/spec/couchrest/core/design_spec.rb +131 -0
  39. data/spec/couchrest/core/document_spec.rb +96 -0
  40. data/spec/couchrest/core/model_spec.rb +660 -0
  41. data/spec/couchrest/helpers/file_manager_spec.rb +203 -0
  42. data/spec/couchrest/helpers/pager_spec.rb +122 -0
  43. data/spec/couchrest/helpers/streamer_spec.rb +23 -0
  44. data/spec/fixtures/attachments/couchdb.png +0 -0
  45. data/spec/fixtures/attachments/test.html +11 -0
  46. data/spec/fixtures/views/lib.js +3 -0
  47. data/spec/fixtures/views/test_view/lib.js +3 -0
  48. data/spec/fixtures/views/test_view/only-map.js +4 -0
  49. data/spec/fixtures/views/test_view/test-map.js +3 -0
  50. data/spec/fixtures/views/test_view/test-reduce.js +3 -0
  51. data/spec/spec.opts +6 -0
  52. data/spec/spec_helper.rb +14 -0
  53. data/utils/remap.rb +27 -0
  54. data/utils/subset.rb +30 -0
  55. 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