relaxo-model 0.12.0 → 0.16.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b0c3186186902c2608d53e8f866364aba7dbc958
4
- data.tar.gz: e35738b1d5643f40b8454bcb1d787f199faf0686
2
+ SHA256:
3
+ metadata.gz: 94885a0f81111f0e8ae7aa9c932ece3c903ebd81fb9f87756fc29317b8063536
4
+ data.tar.gz: edfd857bb82fd267570d33553fc11e4d03772653d0b0d2bc10631bae63b6ec1d
5
5
  SHA512:
6
- metadata.gz: 01f037f4d5c92d57442ba8232d3afe64410770ac7fc62aacb4e18a391295ef1f1ad6c1c6fab1881fc24457aaa7161a71e74470587434166fc2ecbc1de9802566
7
- data.tar.gz: 91287d51707af0a469dda51139ad8c8efb61228619b52ca7a3a84905f3f44472da1fcbe99e2ecc92a42a3f101d541ad74176750a51f1bd62c52998e33648c1bd
6
+ metadata.gz: 167db567e592094c75204d7d9041857665b88f0d18ac3da8e599d5140af19b5cdaf120c0e5d81d77867b8711912fc44097ab9c0bcad9e3bcd787edff3f046c7d
7
+ data.tar.gz: 7fb77cb8fbe0949e9495ec7ce76a6c9d0907303f42c14b6923776ea3791353525eaa3c906cabfa9632a41108ee83a6170a5a843e4d1c70a596b4f758379593ad
data/.gitignore CHANGED
@@ -1,18 +1,12 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
6
10
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- spec/relaxo/model/test
16
- test/tmp
17
- test/version_tmp
18
- tmp
11
+ .rspec_status
12
+ .covered.db
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --backtrace
3
+ --warnings
4
+ --require spec_helper
@@ -1,17 +1,20 @@
1
1
  language: ruby
2
- sudo: false
3
- before_install:
4
- # For testing purposes:
5
- - git config --global user.name "Samuel Williams"
6
- - git config --global user.email "samuel@oriontransfer.net"
7
- rvm:
8
- - 2.1.8
9
- - 2.2.4
10
- - 2.3.1
11
- - 2.4.0
12
- - rbx-2
13
- env: COVERAGE=true
2
+ dist: xenial
3
+ cache: bundler
4
+
14
5
  matrix:
6
+ include:
7
+ - rvm: 2.4
8
+ - rvm: 2.5
9
+ - rvm: 2.6
10
+ - rvm: 2.6
11
+ env: COVERAGE=PartialSummary,Coveralls
12
+ - rvm: truffleruby
13
+ - rvm: ruby-head
14
+ - rvm: 2.6
15
+ os: osx
15
16
  allow_failures:
17
+ - rvm: truffleruby
16
18
  - rvm: ruby-head
17
- - rvm: "rbx-2"
19
+ - rvm: jruby-head
20
+ - rvm: truffleruby
data/Gemfile CHANGED
@@ -3,13 +3,9 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in relaxo-model.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rugged', git: 'git://github.com/libgit2/rugged.git', submodules: true
6
+ gem 'rugged', git: 'https://github.com/libgit2/rugged.git', submodules: true
7
7
 
8
8
  group :development do
9
9
  gem "pry"
10
- end
11
-
12
- group :test do
13
- gem 'simplecov'
14
- gem 'coveralls', require: false
10
+ gem "bcrypt"
15
11
  end
data/README.md CHANGED
@@ -59,23 +59,23 @@ require 'relaxo/model'
59
59
  database = Relaxo.connect("test")
60
60
 
61
61
  trees = [
62
- {:name => 'Hinoki', :planted => Date.parse("2013/11/17")},
63
- {:name => 'Keyaki', :planted => Date.parse("2016/9/24")}
62
+ {:name => 'Hinoki', :planted => Date.parse("2013/11/17")},
63
+ {:name => 'Keyaki', :planted => Date.parse("2016/9/24")}
64
64
  ]
65
65
 
66
66
  class Tree
67
- include Relaxo::Model
67
+ include Relaxo::Model
68
68
 
69
- property :name
70
- property :planted, Attribute[Date]
69
+ property :name
70
+ property :planted, Attribute[Date]
71
71
 
72
- view :all, [:type], index: [:name]
72
+ view :all, [:type], index: [:name]
73
73
  end
74
74
 
75
75
  database.commit(message: "Create trees") do |changeset|
76
- trees.each do |tree|
77
- Tree.insert(changeset, tree)
78
- end
76
+ trees.each do |tree|
77
+ Tree.insert(changeset, tree)
78
+ end
79
79
  end
80
80
 
81
81
  database.current do |dataset|
data/Rakefile CHANGED
@@ -1,11 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
7
-
8
- task :default => :spec
4
+ # For RSpec
5
+ RSpec::Core::RakeTask.new(:spec)
9
6
 
10
7
  task :console do
11
8
  require 'pry'
@@ -16,3 +13,5 @@ task :console do
16
13
 
17
14
  Pry.start
18
15
  end
16
+
17
+ task :default => :spec
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -78,7 +78,7 @@ module Relaxo
78
78
 
79
79
  def view(name, *path, klass: self, index: nil)
80
80
  # Support array as 2nd argument, e.g.
81
- # view :by_owner, [:type, 'by_owner', ]
81
+ # view :by_owner, [:type, 'by_owner', ...]
82
82
  if path.empty?
83
83
  path = [:type, name.to_s, name.to_s.split('_', 2).last.to_sym]
84
84
  elsif path.count == 1 and path.first.is_a? Array
@@ -108,7 +108,7 @@ module Relaxo
108
108
 
109
109
  def unique(*keys)
110
110
  lambda do |arguments|
111
- Path.escape keys.map{|key| arguments[key] || self[key] || 'null'}
111
+ Path.escape keys.map{|key| arguments[key] || self.send(key) || 'null'}
112
112
  end
113
113
  end
114
114
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -22,6 +22,9 @@ require 'relaxo/model/base'
22
22
 
23
23
  module Relaxo
24
24
  module Model
25
+ class SerializationError < RuntimeError
26
+ end
27
+
25
28
  # Represents an underlying object with changes which can be persisted.
26
29
  module Component
27
30
  def self.included(child)
@@ -102,11 +105,11 @@ module Relaxo
102
105
  end
103
106
  end
104
107
 
105
- def validate
108
+ def validate(changeset)
106
109
  # Do nothing :)
107
110
  end
108
111
 
109
- def to_hash
112
+ def to_h
110
113
  @attributes
111
114
  end
112
115
 
@@ -131,14 +134,18 @@ module Relaxo
131
134
  # Moves values from `@changed` into `@attributes`.
132
135
  def flatten!
133
136
  self.class.properties.each do |key, klass|
134
- if @changed.include?(key)
135
- if klass
136
- @attributes[key] = klass.convert_to_primative(@changed.delete(key))
137
- else
138
- @attributes[key] = @changed.delete(key)
137
+ begin
138
+ if @changed.include?(key)
139
+ if klass
140
+ @attributes[key] = klass.convert_to_primative(@changed.delete(key))
141
+ else
142
+ @attributes[key] = @changed.delete(key)
143
+ end
144
+ elsif !@attributes.include?(key) and klass.respond_to?(:default)
145
+ @attributes[key] = klass.default
139
146
  end
140
- elsif !@attributes.include?(key) and klass.respond_to?(:default)
141
- @attributes[key] = klass.default
147
+ rescue
148
+ raise SerializationError, "Failed to flatten #{key.inspect} of type #{klass.inspect}!"
142
149
  end
143
150
  end
144
151
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,7 @@ require 'msgpack'
24
24
 
25
25
  module Relaxo
26
26
  module Model
27
- class ValidationError < StandardError
27
+ class ValidationFailure < StandardError
28
28
  def initialize(document, errors)
29
29
  @document = document
30
30
  @errors = errors
@@ -132,11 +132,12 @@ module Relaxo
132
132
  "\#<#{self.class}:#{self.id} #{self.attributes.inspect}>"
133
133
  end
134
134
 
135
- # Duplicate the model object, and possibly change the dataset it is connected to. You will potentially have two objects referring to the same record.
136
- def dup
137
- clone = self.class.new(@dataset, @object, @changed, **@attributes.dup)
135
+ # Make a copy of the record, as if calling create.
136
+ def dup(dataset = @dataset)
137
+ # Splat already calls dup internally I guess.
138
+ clone = self.class.new(dataset, nil, @changed.dup, **@attributes)
138
139
 
139
- clone.after_fetch
140
+ clone.after_create
140
141
 
141
142
  return clone
142
143
  end
@@ -156,7 +157,7 @@ module Relaxo
156
157
 
157
158
  before_save
158
159
 
159
- if errors = self.validate
160
+ if errors = self.validate(dataset)
160
161
  return errors
161
162
  end
162
163
 
@@ -190,7 +191,7 @@ module Relaxo
190
191
  result = self.save(dataset)
191
192
 
192
193
  if result != true
193
- raise ValidationErrors.new(result)
194
+ raise ValidationFailure.new(self, result)
194
195
  end
195
196
 
196
197
  return self
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -25,16 +25,22 @@ module Relaxo
25
25
  module Properties
26
26
  Attribute.for_class(BCrypt::Password) do
27
27
  def convert_to_primative(value)
28
+ unless value.is_a? BCrypt::Password
29
+ value = BCrypt::Password.create(value)
30
+ end
31
+
28
32
  [value.salt, value.checksum]
29
33
  end
30
34
 
31
35
  def convert_from_primative(dataset, value)
32
- if String === value
33
- # If the primative value is a string, we are saving the password:
34
- BCrypt::Password.create(value)
35
- else
36
- # Otherwise the password is given by an array containing the salt and checksum:
36
+ if value.is_a? Array
37
+ # The password is given by an array containing the salt and checksum:
37
38
  BCrypt::Password.new(value.join)
39
+ elsif BCrypt::Password.valid_hash?(value)
40
+ BCrypt::Password.new(value)
41
+ else
42
+ # Try to create a password from the supplied value:
43
+ BCrypt::Password.create(value)
38
44
  end
39
45
  end
40
46
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@ module Relaxo
29
29
  end
30
30
 
31
31
  def convert_from_primative(dataset, value)
32
- if Array === value
32
+ if value.is_a? Array
33
33
  @klass.new(value[0], value[1])
34
34
  else
35
35
  @klass.parse(value)
@@ -1,4 +1,4 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.12.0"
23
+ VERSION = "0.16.0"
24
24
  end
25
25
  end
@@ -1,7 +1,5 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'relaxo/model/version'
1
+
2
+ require_relative 'lib/relaxo/model/version'
5
3
 
6
4
  Gem::Specification.new do |spec|
7
5
  spec.name = "relaxo-model"
@@ -22,10 +20,11 @@ Gem::Specification.new do |spec|
22
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
21
  spec.require_paths = ["lib"]
24
22
 
25
- spec.add_dependency("relaxo", "~> 1.0")
23
+ spec.add_dependency("relaxo", "~> 1.5")
26
24
  spec.add_dependency("msgpack", "~> 1.0")
27
25
 
28
- spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "covered"
27
+ spec.add_development_dependency "bundler"
29
28
  spec.add_development_dependency "rspec", "~> 3.4.0"
30
29
  spec.add_development_dependency "rake"
31
30
  end
@@ -1,3 +1,22 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
1
20
 
2
21
  require 'relaxo/model'
3
22
 
@@ -1,3 +1,22 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
1
20
 
2
21
  require_relative 'model_context'
3
22
 
@@ -1,5 +1,25 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
1
20
 
2
21
  require 'relaxo/model'
22
+ require 'relaxo/model/properties/bcrypt'
3
23
 
4
24
  class Invoice
5
25
  class Transaction; end
@@ -28,9 +48,14 @@ class Invoice::Transaction
28
48
  property :invoice, BelongsTo[Invoice]
29
49
  property :date, Attribute[Date]
30
50
 
51
+ def year
52
+ date.year
53
+ end
54
+
31
55
  view :all, :type, index: :id
32
56
 
33
57
  view :by_invoice, index: unique(:date, :id)
58
+ view :by_year, :type, 'by_year', index: unique(:year)
34
59
  end
35
60
 
36
61
  class User
@@ -38,6 +63,7 @@ class User
38
63
 
39
64
  property :email, Attribute[String]
40
65
  property :name
66
+ property :password, Attribute[BCrypt::Password]
41
67
  property :intro
42
68
 
43
69
  view :all, :type, index: unique(:email)
@@ -0,0 +1,81 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative '../model_context'
22
+
23
+ RSpec.describe Relaxo::Model::Properties do
24
+ context BCrypt::Password do
25
+ include_context "model"
26
+
27
+ it "can set password string" do
28
+ database.commit(message: "Add new user") do |changeset|
29
+ User.insert(changeset, email: "its@complicated.com", name: "Bob", password: "foobar")
30
+ end
31
+
32
+ bob = User.fetch_by_name(database.current, name: "Bob")
33
+ expect(bob).to_not be nil
34
+
35
+ expect(bob.password == "foobar").to be_truthy
36
+ end
37
+
38
+ it "can set password instance" do
39
+ database.commit(message: "Add new user") do |changeset|
40
+ User.insert(changeset, email: "its@complicated.com", name: "Bob", password: BCrypt::Password.create("foobar"))
41
+ end
42
+
43
+ bob = User.fetch_by_name(database.current, name: "Bob")
44
+ expect(bob).to_not be nil
45
+
46
+ expect(bob.password == "foobar").to be_truthy
47
+ end
48
+
49
+ it "can assign password string" do
50
+ database.commit(message: "Add new user") do |changeset|
51
+ user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
52
+
53
+ user.assign(password: "foobar")
54
+
55
+ user.save(changeset)
56
+ end
57
+
58
+ bob = User.fetch_by_name(database.current, name: "Bob")
59
+ expect(bob).to_not be nil
60
+
61
+ expect(bob.password == "foobar").to be_truthy
62
+ end
63
+
64
+ it "can assign password hash" do
65
+ password = BCrypt::Password.create("foobar")
66
+
67
+ database.commit(message: "Add new user") do |changeset|
68
+ user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
69
+
70
+ user.assign(password: password.to_s)
71
+
72
+ user.save(changeset)
73
+ end
74
+
75
+ bob = User.fetch_by_name(database.current, name: "Bob")
76
+ expect(bob).to_not be nil
77
+
78
+ expect(bob.password == "foobar").to be_truthy
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,22 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
1
20
 
2
21
  require_relative 'model_context'
3
22
 
@@ -0,0 +1,31 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require "bundler/setup"
22
+ require "covered/rspec"
23
+
24
+ RSpec.configure do |config|
25
+ # Enable flags like --only-failures and --next-failure
26
+ config.example_status_persistence_file_path = ".rspec_status"
27
+
28
+ config.expect_with :rspec do |c|
29
+ c.syntax = :expect
30
+ end
31
+ 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.12.0
4
+ version: 0.16.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-11 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaxo
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: msgpack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: covered
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '1.3'
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '1.3'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +104,7 @@ extensions: []
90
104
  extra_rdoc_files: []
91
105
  files:
92
106
  - ".gitignore"
93
- - ".simplecov"
107
+ - ".rspec"
94
108
  - ".travis.yml"
95
109
  - Gemfile
96
110
  - README.md
@@ -113,7 +127,9 @@ files:
113
127
  - spec/relaxo/model/attribute_spec.rb
114
128
  - spec/relaxo/model/document_spec.rb
115
129
  - spec/relaxo/model/model_context.rb
130
+ - spec/relaxo/model/properties/bcrypt_spec.rb
116
131
  - spec/relaxo/model/recordset_spec.rb
132
+ - spec/spec_helper.rb
117
133
  homepage: http://www.codeotaku.com/projects/relaxo/model
118
134
  licenses:
119
135
  - MIT
@@ -133,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
149
  - !ruby/object:Gem::Version
134
150
  version: '0'
135
151
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.6.12
152
+ rubygems_version: 3.1.2
138
153
  signing_key:
139
154
  specification_version: 4
140
155
  summary: A model layer for CouchDB with minimal global state.
@@ -142,4 +157,6 @@ test_files:
142
157
  - spec/relaxo/model/attribute_spec.rb
143
158
  - spec/relaxo/model/document_spec.rb
144
159
  - spec/relaxo/model/model_context.rb
160
+ - spec/relaxo/model/properties/bcrypt_spec.rb
145
161
  - spec/relaxo/model/recordset_spec.rb
162
+ - spec/spec_helper.rb
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end