addywaddy-couch_surfer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +0 -0
- data/README.md +73 -0
- data/Rakefile +67 -0
- data/lib/couch_surfer/associations.rb +57 -0
- data/lib/couch_surfer/model.rb +620 -0
- data/lib/couch_surfer/validations.rb +51 -0
- data/lib/couch_surfer.rb +9 -0
- data/spec/fixtures/attachments/README +3 -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/lib/associations_spec.rb +74 -0
- data/spec/lib/model_spec.rb +883 -0
- data/spec/lib/validations_spec.rb +93 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +27 -0
- metadata +105 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
class Account
|
4
|
+
include CouchSurfer::Model
|
5
|
+
include CouchSurfer::Associations
|
6
|
+
|
7
|
+
key_accessor :name
|
8
|
+
|
9
|
+
has_many :employees, :view => {:name => :by_account_id_and_email, :query => lambda{ {:startkey => [id, nil], :endkey => [id, {}]} }}
|
10
|
+
has_many :projects
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class Project
|
15
|
+
include CouchSurfer::Model
|
16
|
+
include CouchSurfer::Associations
|
17
|
+
|
18
|
+
key_accessor :name, :account_id
|
19
|
+
|
20
|
+
belongs_to :account
|
21
|
+
|
22
|
+
view_by :account_id
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class Employee
|
27
|
+
include CouchSurfer::Model
|
28
|
+
include CouchSurfer::Associations
|
29
|
+
|
30
|
+
key_accessor :email, :account_id
|
31
|
+
belongs_to :account
|
32
|
+
|
33
|
+
view_by :account_id, :email
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe CouchSurfer::Associations do
|
38
|
+
before(:all) do
|
39
|
+
db = CouchRest.database!('couch_surfer-test')
|
40
|
+
db.delete!
|
41
|
+
CouchSurfer::Model.default_database = CouchRest.database!('http://127.0.0.1:5984/couch_surfer-test')
|
42
|
+
@account = Account.create(:name => "My Account")
|
43
|
+
5.times do |i|
|
44
|
+
Employee.create(:email => "foo#{i}@bar.com", :account_id => @account.id)
|
45
|
+
Project.create(:name => "Project No. #{i}", :account_id => @account.id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "An employee" do
|
50
|
+
it "should return it's users" do
|
51
|
+
@other_employee = Employee.create(:email => "woo@war.com", :account_id => "ANOTHER_ACCOUNT_ID")
|
52
|
+
@account.employees.length.should == 5
|
53
|
+
@account.employees.should_not include(@other_employee)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return it's parent account" do
|
57
|
+
@employee = @account.employees.first
|
58
|
+
@employee.account.should == @account
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "A project" do
|
63
|
+
it "should return it's projects" do
|
64
|
+
@other_project = Project.create(:name => "Another Project", :account_id => "ANOTHER_ACCOUNT_ID")
|
65
|
+
@account.projects.length.should == 5
|
66
|
+
@account.projects.should_not include(@other_project)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return it's parent account" do
|
70
|
+
@project = @account.projects.first
|
71
|
+
@project.account.should == @account
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|