rufus-doric 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,14 @@
2
2
  = rufus-doric CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-doric - 0.1.9 released 2010/05/13
6
+
7
+ - model#detach(attachment_name)
8
+ - model#attach(attachment_name, data)
9
+ - raising ActiveRecord::RecordInvalid if _id is missing or ''
10
+ - view, as shortcut for view_by
11
+
12
+
5
13
  == rufus-doric - 0.1.8 released 2010/04/16
6
14
 
7
15
  - view_by 'funcname', 'func' creates a 'funcname' method, not a 'by_funcname'
data/Rakefile CHANGED
@@ -35,8 +35,8 @@ something at the intersection of Rails3, CouchDB and rufus-jig
35
35
 
36
36
  gem.test_file = 'test/test.rb'
37
37
 
38
- gem.add_dependency 'activerecord', '~> 3.0.0.beta2'
39
- gem.add_dependency 'rufus-jig', '>= 0.1.17'
38
+ gem.add_dependency 'activerecord', '~> 3.0.0.beta3'
39
+ gem.add_dependency 'rufus-jig', '>= 0.1.18'
40
40
  gem.add_dependency 'mime-types', '>= 1.16'
41
41
  gem.add_development_dependency 'rake'
42
42
  gem.add_development_dependency 'yard'
@@ -23,6 +23,7 @@
23
23
  #++
24
24
 
25
25
  require 'cgi'
26
+ require 'mime/types'
26
27
 
27
28
 
28
29
  module Rufus
@@ -170,6 +171,13 @@ module Doric
170
171
  end
171
172
  end
172
173
 
174
+ # Shorter than view_by.
175
+ #
176
+ def self.view (key, func=nil)
177
+
178
+ view_by(key, func)
179
+ end
180
+
173
181
  def self.text_index (*keys)
174
182
 
175
183
  @text_index = keys
@@ -237,13 +245,31 @@ module Doric
237
245
  @h['_id'] = Rufus::Doric.neutralize_id(@h['_id'])
238
246
  end
239
247
 
240
- raise ActiveRecord::RecordInvalid.new(self) if @h['_id'].nil?
248
+ if @h['_id'].nil? || @h['_id'].strip == ''
249
+ raise ActiveRecord::RecordInvalid.new(self)
250
+ end
241
251
 
242
252
  r = db.put(@h)
243
253
 
244
254
  raise(SaveFailed.new(self.class.doric_type, _id)) unless r.nil?
245
255
  end
246
256
 
257
+ def attach (attname, data)
258
+
259
+ doc = db.get(@h['_id'])
260
+
261
+ db.attach(
262
+ doc, attname, data,
263
+ :content_type => ::MIME::Types.type_for(attname).first.to_s)
264
+ end
265
+
266
+ def detach (attname)
267
+
268
+ raise ArgumentError.new("model not yet saved") unless @h['_rev']
269
+
270
+ db.delete("#{@h['_id']}/#{attname}?rev=#{@h['_rev']}")
271
+ end
272
+
247
273
  #--
248
274
  # methods required by ActiveModel (see test/unit/ut_3_model_lint.rb)
249
275
  #++
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rufus
3
3
  module Doric
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
6
6
  end
7
7
 
data/rufus-doric.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-doric}
8
- s.version = "0.1.8"
8
+ s.version = "0.1.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux"]
12
- s.date = %q{2010-04-16}
12
+ s.date = %q{2010-05-13}
13
13
  s.description = %q{
14
14
  something at the intersection of Rails3, CouchDB and rufus-jig
15
15
  }
@@ -78,23 +78,23 @@ something at the intersection of Rails3, CouchDB and rufus-jig
78
78
  s.specification_version = 3
79
79
 
80
80
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
81
- s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0.beta2"])
82
- s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.17"])
81
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0.beta3"])
82
+ s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.18"])
83
83
  s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
84
84
  s.add_development_dependency(%q<rake>, [">= 0"])
85
85
  s.add_development_dependency(%q<yard>, [">= 0"])
86
86
  s.add_development_dependency(%q<jeweler>, [">= 0"])
87
87
  else
88
- s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta2"])
89
- s.add_dependency(%q<rufus-jig>, [">= 0.1.17"])
88
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta3"])
89
+ s.add_dependency(%q<rufus-jig>, [">= 0.1.18"])
90
90
  s.add_dependency(%q<mime-types>, [">= 1.16"])
91
91
  s.add_dependency(%q<rake>, [">= 0"])
92
92
  s.add_dependency(%q<yard>, [">= 0"])
93
93
  s.add_dependency(%q<jeweler>, [">= 0"])
94
94
  end
95
95
  else
96
- s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta2"])
97
- s.add_dependency(%q<rufus-jig>, [">= 0.1.17"])
96
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta3"])
97
+ s.add_dependency(%q<rufus-jig>, [">= 0.1.18"])
98
98
  s.add_dependency(%q<mime-types>, [">= 1.16"])
99
99
  s.add_dependency(%q<rake>, [">= 0"])
100
100
  s.add_dependency(%q<yard>, [">= 0"])
@@ -22,7 +22,7 @@ class Team < Rufus::Doric::Model
22
22
  view_by 'tysec', %{
23
23
  emit(doc.type + '__' + doc.security_level, null);
24
24
  }
25
- view_by 'tysec2', %{
25
+ view 'tysec2', %{
26
26
  emit([ doc.type, doc.security_level ], null);
27
27
  }
28
28
  end
data/test/ut_1_model.rb CHANGED
@@ -90,6 +90,14 @@ class UtModelTest < Test::Unit::TestCase
90
90
  end
91
91
  end
92
92
 
93
+ def test_missing_id_when_saving
94
+
95
+ assert_raise ActiveRecord::RecordInvalid do
96
+ Thing.new(
97
+ ).save!
98
+ end
99
+ end
100
+
93
101
  def test_copy
94
102
 
95
103
  Thing.new(
@@ -179,5 +187,36 @@ class UtModelTest < Test::Unit::TestCase
179
187
 
180
188
  assert_equal 'art', c.name
181
189
  end
190
+
191
+ def test_attach
192
+
193
+ txt = File.read(__FILE__)
194
+
195
+ t = Thing.new('name' => 'piece_of_code')
196
+ t.save!
197
+
198
+ assert_equal [], t.attachments
199
+
200
+ t.attach('code.txt', txt)
201
+
202
+ t = Thing.find('piece_of_code')
203
+
204
+ assert_equal [ 'code.txt' ], t.attachments
205
+ assert_equal txt, t.db.get('piece_of_code/code.txt')
206
+ end
207
+
208
+ def test_detach
209
+
210
+ t = Thing.new('name' => 'ms_excel')
211
+ t.save!
212
+ t.attach('code.txt', File.read(__FILE__))
213
+ t = Thing.find('ms_excel')
214
+
215
+ assert_equal [ 'code.txt' ], t.attachments
216
+
217
+ t.detach('code.txt')
218
+
219
+ assert_equal [], Thing.find('ms_excel').attachments
220
+ end
182
221
  end
183
222
 
@@ -22,6 +22,12 @@ class User < Rufus::Doric::OneDocModel
22
22
  validates :password, :presence => true
23
23
  end
24
24
 
25
+ #class Site < Rufus::Doric::OneDocModel
26
+ # doc_id :sites
27
+ # property :name
28
+ # property :streets
29
+ #end
30
+
25
31
 
26
32
  class UtOneDocModelTest < Test::Unit::TestCase
27
33
 
@@ -87,5 +93,10 @@ class UtOneDocModelTest < Test::Unit::TestCase
87
93
 
88
94
  assert_equal [], User.all
89
95
  end
96
+
97
+ # def test_missing_db_declaration
98
+ #
99
+ # Site.new(:name => 'Eur', :streets => [:one, :two, :three]).save!
100
+ # end
90
101
  end
91
102
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 8
9
- version: 0.1.8
8
+ - 9
9
+ version: 0.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 +09:00
17
+ date: 2010-05-13 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  - 3
29
29
  - 0
30
30
  - 0
31
- - beta2
32
- version: 3.0.0.beta2
31
+ - beta3
32
+ version: 3.0.0.beta3
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -42,8 +42,8 @@ dependencies:
42
42
  segments:
43
43
  - 0
44
44
  - 1
45
- - 17
46
- version: 0.1.17
45
+ - 18
46
+ version: 0.1.18
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency