relaxo-model 0.10.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc3e60e23bca41d0d857ae65662634c291e23b37
4
- data.tar.gz: c69edbdbdf47dd0e233f79e5dac18aeeaecab191
3
+ metadata.gz: e2ad57e6711f00c73b9c202ead6b83a74487d3c6
4
+ data.tar.gz: 4415ddf243915e589262fabd95710bd87f4ca37f
5
5
  SHA512:
6
- metadata.gz: 6ddcedd238f098e276c693e75cb67f87bdee8eea27ad2a76ada6e402b004ea0e20c65712a5cc974d0e56db556809e25188f259738a08b146d6ae50a2374f0c3c
7
- data.tar.gz: d30f14e112a4ef9967568658c7d433046c2f65b9a3aef3815a0ae8946fcca6cb6d8615b6dd874c04379dccb7e71a17671b76cac60ab7af6ebfb7b992661cf257
6
+ metadata.gz: 2002c6a843e9faa0d161ec038746e14e7e62b1510913ce2a58a6d526a43d89cccca8df7ce0f452ce1d6783d2b841d07b0a94102e954a5ea8a49d5a457e41bb37
7
+ data.tar.gz: 70345816de27d90a95239d35254de896938fb36f2200bb98b4d6dadb1d7ef675b15488ef78286276047e1d4ccd2203655a615a7a8505f8dd3f3f8f88bf431d2b
@@ -226,6 +226,10 @@ module Relaxo
226
226
  self.id.eql?(other.id) if other
227
227
  end
228
228
 
229
+ def == other
230
+ self.attributes == other.attributes if other
231
+ end
232
+
229
233
  def hash
230
234
  self.id.hash
231
235
  end
@@ -37,6 +37,14 @@ module Relaxo
37
37
  !@dataset.each(@path).any?
38
38
  end
39
39
 
40
+ def first
41
+ to_a.first
42
+ end
43
+
44
+ def last
45
+ to_a.last
46
+ end
47
+
40
48
  def each(model = @model, &block)
41
49
  @dataset.each(@path) do |name, object|
42
50
  object = model.new(@dataset, object)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.10.3"
23
+ VERSION = "0.11.0"
24
24
  end
25
25
  end
@@ -1,57 +1,8 @@
1
1
 
2
- require 'relaxo/model'
3
-
4
- class Invoice
5
- class Transaction; end
6
-
7
- include Relaxo::Model
8
-
9
- property :id, UUID
10
- property :number
11
- property :name
12
-
13
- property :date, Attribute[Date]
14
-
15
- view :all, [:type], index: [:id]
16
-
17
- def transactions
18
- Invoice::Transaction.by_invoice(@dataset, invoice: self)
19
- end
20
- end
21
-
22
- class Invoice::Transaction
23
- include Relaxo::Model
24
-
25
- parent_type Invoice
26
-
27
- property :id, UUID
28
- property :invoice, BelongsTo[Invoice]
29
- property :date, Attribute[Date]
30
-
31
- view :all, [:type], index: [:id]
32
-
33
- view :by_invoice, [:type, 'by_invoice', :invoice], index: [[:date, :id]]
34
- end
35
-
36
- class User
37
- include Relaxo::Model
38
-
39
- property :email, Attribute[String]
40
- property :name
41
- property :intro
42
-
43
- view :all, [:type], index: [:email]
44
-
45
- view :by_name, [:type, 'by_name'], index: [:name]
46
- end
2
+ require_relative 'model_context'
47
3
 
48
4
  RSpec.describe Relaxo::Model::Document do
49
- let(:database_path) {File.join(__dir__, 'test')}
50
- let(:database) {Relaxo.connect(database_path)}
51
-
52
- let(:document_path) {'test/document.json'}
53
-
54
- before(:each) {FileUtils.rm_rf(database_path)}
5
+ include_context "model"
55
6
 
56
7
  it "should create and save document" do
57
8
  model = Invoice.create(database.current,
@@ -0,0 +1,55 @@
1
+
2
+ require 'relaxo/model'
3
+
4
+ class Invoice
5
+ class Transaction; end
6
+
7
+ include Relaxo::Model
8
+
9
+ property :id, UUID
10
+ property :number
11
+ property :name
12
+
13
+ property :date, Attribute[Date]
14
+
15
+ view :all, [:type], index: [:id]
16
+
17
+ def transactions
18
+ Invoice::Transaction.by_invoice(@dataset, invoice: self)
19
+ end
20
+ end
21
+
22
+ class Invoice::Transaction
23
+ include Relaxo::Model
24
+
25
+ parent_type Invoice
26
+
27
+ property :id, UUID
28
+ property :invoice, BelongsTo[Invoice]
29
+ property :date, Attribute[Date]
30
+
31
+ view :all, [:type], index: [:id]
32
+
33
+ view :by_invoice, [:type, 'by_invoice', :invoice], index: [[:date, :id]]
34
+ end
35
+
36
+ class User
37
+ include Relaxo::Model
38
+
39
+ property :email, Attribute[String]
40
+ property :name
41
+ property :intro
42
+
43
+ view :all, [:type], index: [:email]
44
+
45
+ view :by_name, [:type, 'by_name'], index: [:name]
46
+ end
47
+
48
+ RSpec.shared_context "model" do
49
+ let(:database_path) {File.join(__dir__, 'test')}
50
+ let(:database) {Relaxo.connect(database_path)}
51
+
52
+ let(:document_path) {'test/document.json'}
53
+
54
+ before(:each) {FileUtils.rm_rf(database_path)}
55
+ end
@@ -0,0 +1,26 @@
1
+
2
+ require_relative 'model_context'
3
+
4
+ RSpec.describe Relaxo::Model::Recordset do
5
+ include_context 'model'
6
+
7
+ context "with several invoices" do
8
+ before(:each) do
9
+ database.commit(message: "Adding test model") do |dataset|
10
+ @first = Invoice.insert(dataset, name: "Software Development")
11
+ @middle = Invoice.insert(dataset, name: "Website Hosting")
12
+ @last = Invoice.insert(dataset, name: "Backup Services")
13
+ end
14
+ end
15
+
16
+ it "should have a first and last invoice" do
17
+ recordset = Invoice.all(database.current)
18
+
19
+ expect(recordset.count).to be == 3
20
+ expect(recordset).to_not be_empty
21
+
22
+ expect(recordset.first).to be == @first
23
+ expect(recordset.last).to be == @last
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2018-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaxo
@@ -111,6 +111,8 @@ files:
111
111
  - relaxo-model.gemspec
112
112
  - spec/relaxo/model/attribute_spec.rb
113
113
  - spec/relaxo/model/document_spec.rb
114
+ - spec/relaxo/model/model_context.rb
115
+ - spec/relaxo/model/recordset_spec.rb
114
116
  homepage: http://www.codeotaku.com/projects/relaxo/model
115
117
  licenses:
116
118
  - MIT
@@ -138,3 +140,5 @@ summary: A model layer for CouchDB with minimal global state.
138
140
  test_files:
139
141
  - spec/relaxo/model/attribute_spec.rb
140
142
  - spec/relaxo/model/document_spec.rb
143
+ - spec/relaxo/model/model_context.rb
144
+ - spec/relaxo/model/recordset_spec.rb