couchbase-model 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'rubygems/package_task'
19
+
20
+ def gemspec
21
+ @clean_gemspec ||= eval(File.read(File.expand_path('../../couchbase-model.gemspec', __FILE__)))
22
+ end
23
+
24
+ Gem::PackageTask.new(gemspec) do |pkg|
25
+ pkg.need_tar = true
26
+ end
27
+
@@ -20,6 +20,8 @@ require File.join(File.dirname(__FILE__), 'setup')
20
20
  class Post < Couchbase::Model
21
21
  attribute :title
22
22
  attribute :body
23
+ attribute :author, :default => 'Anonymous'
24
+ attribute :created_at, :default => lambda { Time.new("2010-01-01") }
23
25
  end
24
26
 
25
27
  class TestModel < MiniTest::Unit::TestCase
@@ -41,6 +43,20 @@ class TestModel < MiniTest::Unit::TestCase
41
43
  refute post.id
42
44
  end
43
45
 
46
+ def test_uses_default_value_or_nil
47
+ post = Post.new(:title => "Hello, world")
48
+ refute post.body
49
+ assert_equal 'Anonymous', post.author
50
+ assert_equal 'Anonymous', post.attributes[:author]
51
+ end
52
+
53
+ def test_allows_lambda_as_default_value
54
+ post = Post.new(:title => "Hello, world")
55
+ expected = Time.new("2010-01-01")
56
+ assert_equal expected, post.created_at
57
+ assert_equal expected, post.attributes[:created_at]
58
+ end
59
+
44
60
  def test_assings_id_and_saves_the_object
45
61
  post = Post.create(:title => "Hello, world")
46
62
  assert post.id
@@ -60,6 +76,16 @@ class TestModel < MiniTest::Unit::TestCase
60
76
  assert_equal "Good bye, world", orig.title
61
77
  end
62
78
 
79
+ def test_it_raises_not_found_exception
80
+ assert_raises Couchbase::Error::MissingId do
81
+ Post.find("missing_key")
82
+ end
83
+ end
84
+
85
+ def test_it_raises_not_found_exception
86
+ refute Post.find_by_id("missing_key")
87
+ end
88
+
63
89
  def test_doesnt_raise_if_the_attribute_redefined
64
90
  eval <<-EOC
65
91
  class RefinedPost < Couchbase::Model
@@ -69,6 +95,19 @@ class TestModel < MiniTest::Unit::TestCase
69
95
  EOC
70
96
  end
71
97
 
98
+ def test_allows_to_define_several_attributes_at_once
99
+ eval <<-EOC
100
+ class Comment < Couchbase::Model
101
+ attribute :name, :email, :body
102
+ end
103
+ EOC
104
+
105
+ comment = Comment.new
106
+ assert comment.respond_to?(:name)
107
+ assert comment.respond_to?(:email)
108
+ assert comment.respond_to?(:body)
109
+ end
110
+
72
111
  def test_allows_arbitrary_ids
73
112
  Post.create(:id => uniq_id, :title => "Foo")
74
113
  assert_equal "Foo", Post.find(uniq_id).title
@@ -100,7 +139,9 @@ class TestModel < MiniTest::Unit::TestCase
100
139
  def test_deletes_an_existent_model
101
140
  post = Post.create(:id => uniq_id)
102
141
  assert post.delete
103
- refute Post.bucket.get(uniq_id)
142
+ assert_raises Couchbase::Error::NotFound do
143
+ Post.bucket.get(uniq_id)
144
+ end
104
145
  end
105
146
 
106
147
  def test_fails_to_delete_model_without_id
metadata CHANGED
@@ -1,30 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Sergey Avseyev
8
+ - Couchbase
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000Z
12
+ date: 2012-04-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchbase
16
- requirement: &8647480 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.1.0
21
+ version: 1.2.0.dp
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8647480
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0.dp
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &8646760 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.8.7
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *8646760
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.7
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: minitest
38
- requirement: &8575100 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *8575100
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdiscount
49
- requirement: &8574240 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *8574240
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: yard
60
- requirement: &8573480 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *8573480
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: ruby-debug19
71
- requirement: &8572660 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,14 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *8572660
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: ORM-like interface allows you to persist your models to Couchbase
81
- email:
82
- - sergey.avseyev@gmail.com
111
+ email: support@couchbase.com
83
112
  executables: []
84
113
  extensions: []
85
114
  extra_rdoc_files: []
@@ -93,15 +122,24 @@ files:
93
122
  - couchbase-model.gemspec
94
123
  - lib/couchbase-model.rb
95
124
  - lib/couchbase/model.rb
125
+ - lib/couchbase/model/configuration.rb
96
126
  - lib/couchbase/model/uuid.rb
97
127
  - lib/couchbase/model/version.rb
128
+ - lib/couchbase/railtie.rb
129
+ - lib/rails/generators/couchbase/config/config_generator.rb
130
+ - lib/rails/generators/couchbase/config/templates/couchbase.yml
131
+ - lib/rails/generators/couchbase/view/templates/map.js
132
+ - lib/rails/generators/couchbase/view/templates/reduce.js
133
+ - lib/rails/generators/couchbase/view/view_generator.rb
134
+ - lib/rails/generators/couchbase_generator.rb
98
135
  - tasks/doc.rake
136
+ - tasks/package.rake
99
137
  - tasks/test.rake
100
138
  - tasks/util.rake
101
139
  - test/setup.rb
102
140
  - test/test_model.rb
103
141
  - test/test_uuid.rb
104
- homepage: ''
142
+ homepage: https://github.com/couchbaselabs/ruby-couchbase-model
105
143
  licenses: []
106
144
  post_install_message:
107
145
  rdoc_options: []
@@ -121,11 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
159
  version: '0'
122
160
  requirements: []
123
161
  rubyforge_project:
124
- rubygems_version: 1.8.10
162
+ rubygems_version: 1.8.18
125
163
  signing_key:
126
164
  specification_version: 3
127
165
  summary: Declarative interface to Couchbase
128
- test_files:
129
- - test/setup.rb
130
- - test/test_model.rb
131
- - test/test_uuid.rb
166
+ test_files: []