couch_potato 0.2.31 → 0.2.32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Changes
2
2
 
3
+ ### 0.2.32
4
+ * added persisted? and to_key for proper ActiveModel compliance (thilo)
5
+ * id setter (jhohertz-work)
6
+ * load document ids if include\_documents is false (jweiss)
7
+ * persist given created\_at/updated\_at instead of Time.now (langalex)
8
+
3
9
  ### 0.2.31
4
10
  * Removed requirement for validatable gem. Allows for using more uptodate versions of the library, or doesn't install it when you're using ActiveModel. (mattmatt)
5
11
  * fixed callbacks of super classes were not run (langalex)
data/README.md CHANGED
@@ -36,6 +36,10 @@ After that you configure the name of the database:
36
36
  The server URL will default to http://localhost:5984/ unless specified:
37
37
 
38
38
  CouchPotato::Config.database_name = "http://example.com:5984/name_of_the_db"
39
+
40
+ Or with authentication
41
+
42
+ CouchPotato::Config.database_name = "http://username:password@example.com:5984/name_of_the_db"
39
43
 
40
44
  Optionally you can configure which framework you want to use for validations (either validatable or ActiveModel)
41
45
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 31
4
+ :patch: 32
5
5
  :build:
@@ -15,6 +15,14 @@ module CouchPotato
15
15
  def errors
16
16
  super || []
17
17
  end
18
+
19
+ def persisted?
20
+ !self.new?
21
+ end
22
+
23
+ def to_key
24
+ persisted? ? [to_param] : nil
25
+ end
18
26
 
19
27
  def destroyed?
20
28
  !!_deleted
@@ -5,8 +5,15 @@ module CouchPotato
5
5
  property :created_at, :type => Time
6
6
  property :updated_at, :type => Time
7
7
 
8
- before_create lambda {|model| model.created_at = Time.now; model.created_at_not_changed}
9
- before_save lambda {|model| model.updated_at = Time.now; model.updated_at_not_changed}
8
+ before_create lambda {|model|
9
+ model.created_at ||= Time.now
10
+ model.created_at_not_changed
11
+ model.updated_at ||= Time.now
12
+ model.updated_at_not_changed
13
+ }
14
+ before_update lambda {|model|
15
+ model.updated_at = Time.now
16
+ model.updated_at_not_changed}
10
17
  end
11
18
  end
12
19
  end
@@ -23,6 +23,7 @@ module CouchPotato
23
23
  base.class_eval do
24
24
  attr_accessor :_id, :_rev, :_deleted, :database
25
25
  alias_method :id, :_id
26
+ alias_method :id=, :_id=
26
27
  end
27
28
  end
28
29
 
@@ -100,4 +101,4 @@ module CouchPotato
100
101
  %Q{#<#{self.class} _id: "#{_id}", _rev: "#{_rev}", #{attributes_as_string}>}
101
102
  end
102
103
  end
103
- end
104
+ end
data/spec/create_spec.rb CHANGED
@@ -10,6 +10,18 @@ describe "create" do
10
10
  CouchPotato.database.save_document! @comment
11
11
  CouchPotato.couchrest_database.get(@comment.id).send(JSON.create_id).should == 'Comment'
12
12
  end
13
+
14
+ it "should persist a given created_at" do
15
+ @comment = Comment.new :created_at => Time.parse('2010-01-02 12:34:48 +0000'), :title => '-'
16
+ CouchPotato.database.save_document! @comment
17
+ CouchPotato.couchrest_database.get(@comment.id).created_at.should == Time.parse('2010-01-02 12:34:48 +0000')
18
+ end
19
+
20
+ it "should persist a given updated_at" do
21
+ @comment = Comment.new :updated_at => Time.parse('2010-01-02 12:34:48 +0000'), :title => '-'
22
+ CouchPotato.database.save_document! @comment
23
+ CouchPotato.couchrest_database.get(@comment.id).updated_at.should == Time.parse('2010-01-02 12:34:48 +0000')
24
+ end
13
25
  end
14
26
  describe "fails" do
15
27
  it "should not store anything" do
@@ -24,6 +24,31 @@ begin
24
24
  @model = ActiveComment.new
25
25
  end
26
26
 
27
+ describe "#persisted?" do
28
+ it "should return false if it is a new document " do
29
+ @model.should_not be_persisted
30
+ end
31
+
32
+ it "should be true if it was saved" do
33
+ @comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
34
+ CouchPotato.database.save_document! @comment
35
+ @comment.should be_persisted
36
+ end
37
+ end
38
+
39
+ describe "#to_key" do
40
+ it "should return nil if the document was not persisted" do
41
+ @model.to_key.should be_nil
42
+ end
43
+
44
+ it "should return the id of the document if it was persisted" do
45
+ @comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
46
+ CouchPotato.database.save_document! @comment
47
+ @comment.to_key.should == [@comment.id]
48
+ end
49
+ end
50
+
51
+
27
52
  describe "#errors" do
28
53
  it "should return a single error as array" do
29
54
  @model.valid?
@@ -55,7 +80,7 @@ begin
55
80
  end
56
81
  end
57
82
 
58
- def assert(boolean, message)
83
+ def assert(boolean, message = '')
59
84
  boolean || raise(message)
60
85
  end
61
86
 
data/spec/update_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe "create" do
6
6
  end
7
7
 
8
8
  before(:each) do
9
- @comment = Comment.new :title => 'my_title'
9
+ @comment = Comment.new :title => 'my_title', :updated_at => Time.now - 100
10
10
  CouchPotato.database.save_document! @comment
11
11
  end
12
12
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 31
9
- version: 0.2.31
8
+ - 32
9
+ version: 0.2.32
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Lang
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-04 00:00:00 +02:00
17
+ date: 2010-07-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency