addywaddy-couch_surfer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ function justThisView() {
2
+ return "fixture";
3
+ };
@@ -0,0 +1,4 @@
1
+ function(doc) {
2
+ //include-lib
3
+ emit(null, null);
4
+ };
@@ -0,0 +1,3 @@
1
+ function(doc) {
2
+ emit(null, null);
3
+ };
@@ -0,0 +1,3 @@
1
+ function(ks,vs,co) {
2
+ return vs.length;
3
+ };
@@ -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