samflores-couch_surfer 0.0.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.
@@ -0,0 +1,93 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+
4
+ class User
5
+ include CouchSurfer::Model
6
+ include CouchSurfer::Validations
7
+
8
+
9
+ key_accessor :name, :email, :postcode, :account_id
10
+
11
+ view_by :account_id, :email
12
+ view_by :name
13
+
14
+ validates_presence_of :name
15
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
16
+ validates_length_of :postcode, :is => 7, :message => "not the correct length"
17
+ validates_uniqueness_of :name, :message => "No two Beatles have the same name"
18
+ validates_uniqueness_of :email, :view => :by_account_id_and_email, :query => lambda{ {:key => [account_id, email]} }, :message => "Already taken!"
19
+ end
20
+
21
+
22
+ describe CouchSurfer::Validations do
23
+ before(:all) do
24
+ db = CouchRest.database!('couch_surfer-test')
25
+ db.delete!
26
+ CouchSurfer::Model.default_database = CouchRest.database!('http://127.0.0.1:5984/couch_surfer-test')
27
+ end
28
+ before(:each) do
29
+ @user = User.new(:name => nil, :email => "foo.bar.com", :postcode => "WD2", :account_id => 1)
30
+ end
31
+ describe "Validations" do
32
+ before(:each) do
33
+ @user.save.should be_false
34
+ end
35
+ describe "presence_of" do
36
+ it "should display relevant error messages" do
37
+ @user.errors.on(:name).should == "can't be empty"
38
+ end
39
+ end
40
+ describe "format_of" do
41
+ it "should display relevant errors messages" do
42
+ @user.errors.on(:email).should == "is invalid"
43
+ end
44
+ end
45
+ describe "length_of" do
46
+ it "should check the length of the field" do
47
+ @user.errors.on(:postcode).should == "not the correct length"
48
+ end
49
+ end
50
+ describe "uniqueness_of" do
51
+ before(:all) do
52
+ paul = User.new(:name => "Paul", :email => "paul@beatles.com", :postcode => "WD2 4WF", :account_id => 1)
53
+ paul.save.should be_true
54
+ @user_with_invalid_email = User.new(:name => "John", :email => "paul@beatles.com", :postcode => "WD2 4WF", :account_id => 1)
55
+ @user_with_invalid_name = User.new(:name => "Paul", :email => "george@beatles.com", :postcode => "WD2 4WF", :account_id => 1)
56
+ end
57
+
58
+ describe "basic" do
59
+ it "should display relevant errors messages" do
60
+ @user_with_invalid_name.save.should be_false
61
+ @user_with_invalid_name.errors.on(:name).should == "No two Beatles have the same name"
62
+ end
63
+
64
+ it "should save if the user is unique within the scope" do
65
+ @user_with_invalid_name.name = "George"
66
+ @user_with_invalid_name.save.should be_true
67
+ end
68
+ end
69
+
70
+ describe "with scope" do
71
+ it "should display relevant error messages" do
72
+ @user_with_invalid_email.save.should be_false
73
+ @user_with_invalid_email.errors.on(:email).should == "Already taken!"
74
+ end
75
+
76
+ it "should save if the user is unique within the scope" do
77
+ @user_with_invalid_email.email = "george@beatles.com"
78
+ @user_with_invalid_email.save.should be_true
79
+ end
80
+ end
81
+
82
+ end
83
+ describe "when valid" do
84
+ it "should save the document" do
85
+ @user.name = "Foo"
86
+ @user.postcode = "WD2 3AX"
87
+ @user.email = "foo2@bar.com"
88
+ @user.save.should be_true
89
+ end
90
+ end
91
+ end
92
+
93
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'couch_surfer'
11
+
12
+ unless defined?(FIXTURE_PATH)
13
+ FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures'
14
+ SCRATCH_PATH = File.dirname(__FILE__) + '/tmp'
15
+
16
+ COUCHHOST = "http://127.0.0.1:5984"
17
+ TESTDB = 'couch_surfer-test'
18
+ end
19
+
20
+ def reset_test_db!
21
+ cr = CouchRest.new(COUCHHOST)
22
+ db = cr.database(TESTDB)
23
+ db.delete! rescue nil
24
+ db = cr.create_db(TESTDB) rescue nin
25
+ db
26
+ end
27
+ #CouchSurfer::Model.default_database = CouchRest.database!('http://127.0.0.1:5984/couch_surfer-test')
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: samflores-couch_surfer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Adam Groves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-22 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: jchris-couchrest
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.12.2
44
+ version:
45
+ description: CouchSurfer provides an ORM for CouchDB, as well as supporting association and validation declarations.
46
+ email: adam.groves@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.md
53
+ - LICENSE
54
+ - CHANGELOG.md
55
+ files:
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/couch_surfer
60
+ - lib/couch_surfer/associations.rb
61
+ - lib/couch_surfer/model.rb
62
+ - lib/couch_surfer/validations.rb
63
+ - lib/couch_surfer.rb
64
+ - spec/fixtures
65
+ - spec/fixtures/attachments
66
+ - spec/fixtures/attachments/couchdb.png
67
+ - spec/fixtures/attachments/README
68
+ - spec/fixtures/attachments/test.html
69
+ - spec/fixtures/views
70
+ - spec/fixtures/views/lib.js
71
+ - spec/fixtures/views/test_view
72
+ - spec/fixtures/views/test_view/lib.js
73
+ - spec/fixtures/views/test_view/only-map.js
74
+ - spec/fixtures/views/test_view/test-map.js
75
+ - spec/fixtures/views/test_view/test-reduce.js
76
+ - spec/lib
77
+ - spec/lib/associations_spec.rb
78
+ - spec/lib/model_spec.rb
79
+ - spec/lib/validations_spec.rb
80
+ - spec/spec.opts
81
+ - spec/spec_helper.rb
82
+ - CHANGELOG.md
83
+ has_rdoc: true
84
+ homepage: http://github.com/addywaddy/couchsurfer
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.2.0
106
+ signing_key:
107
+ specification_version: 2
108
+ summary: ORM based on CouchRest::Model
109
+ test_files: []
110
+