jrun-couchrest 0.2.1.1 → 0.12.6

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 (59) hide show
  1. data/README.md +6 -31
  2. data/Rakefile +1 -4
  3. data/examples/model/example.rb +13 -19
  4. data/lib/couchrest/core/database.rb +6 -8
  5. data/lib/couchrest/core/document.rb +45 -40
  6. data/lib/couchrest/core/model.rb +615 -0
  7. data/lib/couchrest/core/server.rb +1 -1
  8. data/lib/couchrest/monkeypatches.rb +48 -68
  9. data/lib/couchrest.rb +8 -54
  10. data/spec/couchrest/core/database_spec.rb +26 -31
  11. data/spec/couchrest/core/document_spec.rb +1 -1
  12. data/spec/couchrest/core/model_spec.rb +855 -0
  13. data/spec/spec_helper.rb +1 -6
  14. metadata +3 -56
  15. data/lib/couchrest/core/response.rb +0 -16
  16. data/lib/couchrest/mixins/attachments.rb +0 -31
  17. data/lib/couchrest/mixins/callbacks.rb +0 -483
  18. data/lib/couchrest/mixins/design_doc.rb +0 -64
  19. data/lib/couchrest/mixins/document_queries.rb +0 -48
  20. data/lib/couchrest/mixins/extended_attachments.rb +0 -68
  21. data/lib/couchrest/mixins/extended_document_mixins.rb +0 -6
  22. data/lib/couchrest/mixins/properties.rb +0 -125
  23. data/lib/couchrest/mixins/validation.rb +0 -234
  24. data/lib/couchrest/mixins/views.rb +0 -168
  25. data/lib/couchrest/mixins.rb +0 -4
  26. data/lib/couchrest/more/casted_model.rb +0 -28
  27. data/lib/couchrest/more/extended_document.rb +0 -217
  28. data/lib/couchrest/more/property.rb +0 -40
  29. data/lib/couchrest/support/blank.rb +0 -42
  30. data/lib/couchrest/support/class.rb +0 -191
  31. data/lib/couchrest/validation/auto_validate.rb +0 -163
  32. data/lib/couchrest/validation/contextual_validators.rb +0 -78
  33. data/lib/couchrest/validation/validation_errors.rb +0 -118
  34. data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
  35. data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
  36. data/lib/couchrest/validation/validators/format_validator.rb +0 -117
  37. data/lib/couchrest/validation/validators/formats/email.rb +0 -66
  38. data/lib/couchrest/validation/validators/formats/url.rb +0 -43
  39. data/lib/couchrest/validation/validators/generic_validator.rb +0 -120
  40. data/lib/couchrest/validation/validators/length_validator.rb +0 -134
  41. data/lib/couchrest/validation/validators/method_validator.rb +0 -89
  42. data/lib/couchrest/validation/validators/numeric_validator.rb +0 -104
  43. data/lib/couchrest/validation/validators/required_field_validator.rb +0 -109
  44. data/spec/couchrest/core/server_spec.rb +0 -35
  45. data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
  46. data/spec/couchrest/more/casted_model_spec.rb +0 -98
  47. data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -130
  48. data/spec/couchrest/more/extended_doc_spec.rb +0 -509
  49. data/spec/couchrest/more/extended_doc_view_spec.rb +0 -207
  50. data/spec/couchrest/more/property_spec.rb +0 -130
  51. data/spec/couchrest/support/class_spec.rb +0 -59
  52. data/spec/fixtures/more/article.rb +0 -34
  53. data/spec/fixtures/more/card.rb +0 -20
  54. data/spec/fixtures/more/course.rb +0 -14
  55. data/spec/fixtures/more/event.rb +0 -6
  56. data/spec/fixtures/more/invoice.rb +0 -17
  57. data/spec/fixtures/more/person.rb +0 -8
  58. data/spec/fixtures/more/question.rb +0 -6
  59. data/spec/fixtures/more/service.rb +0 -12
@@ -1,35 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe CouchRest::Server do
4
-
5
- describe "available databases" do
6
- before(:each) do
7
- @couch = CouchRest::Server.new
8
- end
9
-
10
- after(:each) do
11
- @couch.available_databases.each do |ref, db|
12
- db.delete!
13
- end
14
- end
15
-
16
- it "should let you add more databases" do
17
- @couch.available_databases.should be_empty
18
- @couch.define_available_database(:default, "cr-server-test-db")
19
- @couch.available_databases.keys.should include(:default)
20
- end
21
-
22
- it "should verify that a database is available" do
23
- @couch.define_available_database(:default, "cr-server-test-db")
24
- @couch.available_database?(:default).should be_true
25
- @couch.available_database?("cr-server-test-db").should be_true
26
- @couch.available_database?(:matt).should be_false
27
- end
28
-
29
- it "should let you set a default database" do
30
- @couch.default_database = 'cr-server-test-default-db'
31
- @couch.available_database?(:default).should be_true
32
- end
33
- end
34
-
35
- end
@@ -1,40 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
- require File.join(FIXTURE_PATH, 'more', 'card')
3
-
4
- class Car < CouchRest::ExtendedDocument
5
- use_database TEST_SERVER.default_database
6
-
7
- property :name
8
- property :driver, :cast_as => 'Driver'
9
- end
10
-
11
- class Driver < CouchRest::ExtendedDocument
12
- use_database TEST_SERVER.default_database
13
- # You have to add a casted_by accessor if you want to reach a casted extended doc parent
14
- attr_accessor :casted_by
15
-
16
- property :name
17
- end
18
-
19
- describe "casting an extended document" do
20
-
21
- before(:each) do
22
- @car = Car.new(:name => 'Renault 306')
23
- @driver = Driver.new(:name => 'Matt')
24
- end
25
-
26
- # it "should not create an empty casted object" do
27
- # @car.driver.should be_nil
28
- # end
29
-
30
- it "should let you assign the casted attribute after instantializing an object" do
31
- @car.driver = @driver
32
- @car.driver.name.should == 'Matt'
33
- end
34
-
35
- it "should let the casted document who casted it" do
36
- Car.new(:name => 'Renault 306', :driver => @driver)
37
- @car.driver.casted_by.should == @car
38
- end
39
-
40
- end
@@ -1,98 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
- require File.join(FIXTURE_PATH, 'more', 'card')
3
-
4
- class WithCastedModelMixin < Hash
5
- include CouchRest::CastedModel
6
- property :name
7
- end
8
-
9
- class DummyModel < CouchRest::ExtendedDocument
10
- use_database TEST_SERVER.default_database
11
- raise "Default DB not set" if TEST_SERVER.default_database.nil?
12
- property :casted_attribute, :cast_as => 'WithCastedModelMixin'
13
- property :keywords, :cast_as => ["String"]
14
- end
15
-
16
- describe CouchRest::CastedModel do
17
-
18
- describe "A non hash class including CastedModel" do
19
- it "should fail raising and include error" do
20
- lambda do
21
- class NotAHashButWithCastedModelMixin
22
- include CouchRest::CastedModel
23
- property :name
24
- end
25
-
26
- end.should raise_error
27
- end
28
- end
29
-
30
- describe "isolated" do
31
- before(:each) do
32
- @obj = WithCastedModelMixin.new
33
- end
34
- it "should automatically include the property mixin and define getters and setters" do
35
- @obj.name = 'Matt'
36
- @obj.name.should == 'Matt'
37
- end
38
- end
39
-
40
- describe "casted as attribute" do
41
- before(:each) do
42
- @obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
43
- @casted_obj = @obj.casted_attribute
44
- end
45
-
46
- it "should be available from its parent" do
47
- @casted_obj.should be_an_instance_of(WithCastedModelMixin)
48
- end
49
-
50
- it "should have the getters defined" do
51
- @casted_obj.name.should == 'whatever'
52
- end
53
-
54
- it "should know who casted it" do
55
- @casted_obj.casted_by.should == @obj
56
- end
57
- end
58
-
59
- describe "casted as an array of a different type" do
60
- before(:each) do
61
- @obj = DummyModel.new(:keywords => ['couch', 'sofa', 'relax', 'canapé'])
62
- end
63
-
64
- it "should cast the array propery" do
65
- @obj.keywords.should be_an_instance_of(Array)
66
- @obj.keywords.first.should == 'couch'
67
- end
68
-
69
- end
70
-
71
- describe "saved document with casted models" do
72
- before(:each) do
73
- reset_test_db!
74
- @obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
75
- @obj.save.should be_true
76
- @obj = DummyModel.get(@obj.id)
77
- end
78
-
79
- it "should be able to load with the casted models" do
80
- casted_obj = @obj.casted_attribute
81
- casted_obj.should_not be_nil
82
- casted_obj.should be_an_instance_of(WithCastedModelMixin)
83
- end
84
-
85
- it "should have defined getters for the casted model" do
86
- casted_obj = @obj.casted_attribute
87
- casted_obj.name.should == "whatever"
88
- end
89
-
90
- it "should have defined setters for the casted model" do
91
- casted_obj = @obj.casted_attribute
92
- casted_obj.name = "test"
93
- casted_obj.name.should == "test"
94
- end
95
-
96
- end
97
-
98
- end
@@ -1,130 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "ExtendedDocument attachments" do
4
-
5
- describe "#has_attachment?" do
6
- before(:each) do
7
- reset_test_db!
8
- @obj = Basic.new
9
- @obj.save.should == true
10
- @file = File.open(FIXTURE_PATH + '/attachments/test.html')
11
- @attachment_name = 'my_attachment'
12
- @obj.create_attachment(:file => @file, :name => @attachment_name)
13
- end
14
-
15
- it 'should return false if there is no attachment' do
16
- @obj.has_attachment?('bogus').should be_false
17
- end
18
-
19
- it 'should return true if there is an attachment' do
20
- @obj.has_attachment?(@attachment_name).should be_true
21
- end
22
-
23
- it 'should return true if an object with an attachment is reloaded' do
24
- @obj.save.should be_true
25
- reloaded_obj = Basic.get(@obj.id)
26
- reloaded_obj.has_attachment?(@attachment_name).should be_true
27
- end
28
-
29
- it 'should return false if an attachment has been removed' do
30
- @obj.delete_attachment(@attachment_name)
31
- @obj.has_attachment?(@attachment_name).should be_false
32
- end
33
- end
34
-
35
- describe "creating an attachment" do
36
- before(:each) do
37
- @obj = Basic.new
38
- @obj.save.should == true
39
- @file_ext = File.open(FIXTURE_PATH + '/attachments/test.html')
40
- @file_no_ext = File.open(FIXTURE_PATH + '/attachments/README')
41
- @attachment_name = 'my_attachment'
42
- @content_type = 'media/mp3'
43
- end
44
-
45
- it "should create an attachment from file with an extension" do
46
- @obj.create_attachment(:file => @file_ext, :name => @attachment_name)
47
- @obj.save.should == true
48
- reloaded_obj = Basic.get(@obj.id)
49
- reloaded_obj['_attachments'][@attachment_name].should_not be_nil
50
- end
51
-
52
- it "should create an attachment from file without an extension" do
53
- @obj.create_attachment(:file => @file_no_ext, :name => @attachment_name)
54
- @obj.save.should == true
55
- reloaded_obj = Basic.get(@obj.id)
56
- reloaded_obj['_attachments'][@attachment_name].should_not be_nil
57
- end
58
-
59
- it 'should raise ArgumentError if :file is missing' do
60
- lambda{ @obj.create_attachment(:name => @attachment_name) }.should raise_error
61
- end
62
-
63
- it 'should raise ArgumentError if :name is missing' do
64
- lambda{ @obj.create_attachment(:file => @file_ext) }.should raise_error
65
- end
66
-
67
- it 'should set the content-type if passed' do
68
- @obj.create_attachment(:file => @file_ext, :name => @attachment_name, :content_type => @content_type)
69
- @obj['_attachments'][@attachment_name]['content-type'].should == @content_type
70
- end
71
- end
72
-
73
- describe 'reading, updating, and deleting an attachment' do
74
- before(:each) do
75
- @obj = Basic.new
76
- @file = File.open(FIXTURE_PATH + '/attachments/test.html')
77
- @attachment_name = 'my_attachment'
78
- @obj.create_attachment(:file => @file, :name => @attachment_name)
79
- @obj.save.should == true
80
- @file.rewind
81
- @content_type = 'media/mp3'
82
- end
83
-
84
- it 'should read an attachment that exists' do
85
- @obj.read_attachment(@attachment_name).should == @file.read
86
- end
87
-
88
- it 'should update an attachment that exists' do
89
- file = File.open(FIXTURE_PATH + '/attachments/README')
90
- @file.should_not == file
91
- @obj.update_attachment(:file => file, :name => @attachment_name)
92
- @obj.save
93
- reloaded_obj = Basic.get(@obj.id)
94
- file.rewind
95
- reloaded_obj.read_attachment(@attachment_name).should_not == @file.read
96
- reloaded_obj.read_attachment(@attachment_name).should == file.read
97
- end
98
-
99
- it 'should se the content-type if passed' do
100
- file = File.open(FIXTURE_PATH + '/attachments/README')
101
- @file.should_not == file
102
- @obj.update_attachment(:file => file, :name => @attachment_name, :content_type => @content_type)
103
- @obj['_attachments'][@attachment_name]['content-type'].should == @content_type
104
- end
105
-
106
- it 'should delete an attachment that exists' do
107
- @obj.delete_attachment(@attachment_name)
108
- @obj.save
109
- lambda{Basic.get(@obj.id).read_attachment(@attachment_name)}.should raise_error
110
- end
111
- end
112
-
113
- describe "#attachment_url" do
114
- before(:each) do
115
- @obj = Basic.new
116
- @file = File.open(FIXTURE_PATH + '/attachments/test.html')
117
- @attachment_name = 'my_attachment'
118
- @obj.create_attachment(:file => @file, :name => @attachment_name)
119
- @obj.save.should == true
120
- end
121
-
122
- it 'should return nil if attachment does not exist' do
123
- @obj.attachment_url('bogus').should be_nil
124
- end
125
-
126
- it 'should return the attachment URL as specified by CouchDB HttpDocumentApi' do
127
- @obj.attachment_url(@attachment_name).should == "#{Basic.database}/#{@obj.id}/#{@attachment_name}"
128
- end
129
- end
130
- end