relaxo-model 0.12.1 → 0.17.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
- SHA1:
3
- metadata.gz: 47752f1b7559c0d9655e5e672a02be42349906ff
4
- data.tar.gz: 35fadf3fe42a32cd640272232224f3f92fef8c90
2
+ SHA256:
3
+ metadata.gz: d5a7bf567015446448d276991edbaf5ae5639c46fb718d3f3da95725fde8e983
4
+ data.tar.gz: bb061e063c19f537cf73704bdd3ddc2f2e4f84c3f9a9b84fc7b6a2cdd41ec41b
5
5
  SHA512:
6
- metadata.gz: e02d21e29e82f65f25a08c3580db7028c770d35f84810a38821065bf49b695c4b190f18e63226de8e722c8148f7145c61a2d5f3dbda715996053a49e3309e6b9
7
- data.tar.gz: dbe2d8acaf7fc724a6fb63c4b7ca1d0d9ea4067dfbcfb410f6af98d0e0a3fcb19b057601743cea5bf85f4e7a3136ce12fa59e88c45b2067a23624a4ce915ad3c
6
+ metadata.gz: f077e32a41107719d760835467b7ef8b8cfbd20b6dfa168e967d49a824f0be1822068f4b6742681f5f13fff974614a3deb74a3be1051d20359f5343668a8a74b
7
+ data.tar.gz: 1c2714ba31834609ce49f11dc6cd603959f79685986901709c73685b88165f3a18ee0eb74e6be9c2af0144ac0c534aee32197b688d630012a58611c19a387b7e
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
@@ -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)
@@ -51,7 +54,8 @@ module Relaxo
51
54
  # Attributes that have been changed or de-serialized from the dataset:
52
55
  attr :changed
53
56
 
54
- def reload
57
+ def reload(dataset = @dataset)
58
+ @dataset = dataset
55
59
  @changed.clear
56
60
  self.load_object
57
61
  end
@@ -102,11 +106,11 @@ module Relaxo
102
106
  end
103
107
  end
104
108
 
105
- def validate
109
+ def validate(changeset)
106
110
  # Do nothing :)
107
111
  end
108
112
 
109
- def to_hash
113
+ def to_h
110
114
  @attributes
111
115
  end
112
116
 
@@ -131,14 +135,18 @@ module Relaxo
131
135
  # Moves values from `@changed` into `@attributes`.
132
136
  def flatten!
133
137
  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)
138
+ begin
139
+ if @changed.include?(key)
140
+ if klass
141
+ @attributes[key] = klass.convert_to_primative(@changed.delete(key))
142
+ else
143
+ @attributes[key] = @changed.delete(key)
144
+ end
145
+ elsif !@attributes.include?(key) and klass.respond_to?(:default)
146
+ @attributes[key] = klass.default
139
147
  end
140
- elsif !@attributes.include?(key) and klass.respond_to?(:default)
141
- @attributes[key] = klass.default
148
+ rescue
149
+ raise SerializationError, "Failed to flatten #{key.inspect} of type #{klass.inspect}!"
142
150
  end
143
151
  end
144
152
 
@@ -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.1"
23
+ VERSION = "0.17.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
@@ -43,6 +63,7 @@ class User
43
63
 
44
64
  property :email, Attribute[String]
45
65
  property :name
66
+ property :password, Attribute[BCrypt::Password]
46
67
  property :intro
47
68
 
48
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.1
4
+ version: 0.17.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-27 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