uuids 4.1.5 → 4.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -4
- data/app/services/add.rb +12 -7
- data/lib/uuids/base/belongs_to.rb +5 -5
- data/lib/uuids/version.rb +1 -1
- data/spec/dummy/db/schema.rb +4 -4
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/support/development/helpers/sandbox.rb +1 -1
- data/spec/uuids/services/add_spec.rb +2 -18
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e60466e84069bbbe17ea18d0cab274efc374b119
|
4
|
+
data.tar.gz: 313ba714a9c86ce92e0a6d24a4ba39d91dbee873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b858909ab9bd547df281aebca36d15331de2194902ac2ef43dd21d0500a1bbb065ce34d1ae67756e9051506839adf5b1ba5b41226ef947a66c21f22ceef8db78
|
7
|
+
data.tar.gz: b74a87db3c878373a5ee13849ff38b7c147593ebf23681bdbabcf21ec783555d69418fb4275ccbaacb3bae9915989c2118823971bc5caf57c28c76c7bd91812a
|
data/README.rdoc
CHANGED
@@ -149,10 +149,8 @@ The module also contains the service object +Add+:
|
|
149
149
|
Depending on the result of creation, the listener will receive either the
|
150
150
|
<tt>:created, uuid, messages</tt> or <tt>:error, messages</tt> notification.
|
151
151
|
|
152
|
-
The service doesn't know what the record is.
|
153
|
-
|
154
|
-
To provide more concise messaging, the service should be reloaded with a
|
155
|
-
new <tt>name</tt> method.
|
152
|
+
The service doesn't know what the record is. To provide more concise messaging,
|
153
|
+
the service should be reloaded with a new <tt>name</tt> method.
|
156
154
|
|
157
155
|
module Users
|
158
156
|
module Services
|
data/app/services/add.rb
CHANGED
@@ -21,6 +21,10 @@ module Uuids
|
|
21
21
|
# )
|
22
22
|
# service.subscribe some_listener
|
23
23
|
# service.run
|
24
|
+
#
|
25
|
+
# @change Creates the uuid assigned to the record.
|
26
|
+
# @publish created(uuid,messages) when the uuid has been created.
|
27
|
+
# @publish error(messages) when the uuid cannot be created.
|
24
28
|
class Add < Hexx::Service
|
25
29
|
|
26
30
|
# @!scope class
|
@@ -44,11 +48,10 @@ module Uuids
|
|
44
48
|
|
45
49
|
# Runs the service and publishes its results.
|
46
50
|
# @example (see Uuids::Services::Add)
|
47
|
-
# @change
|
48
|
-
# @publish
|
49
|
-
# @publish error(messages) when the uuid cannot be created.
|
51
|
+
# @change (see Uuids::Services::Add)
|
52
|
+
# @publish (see Uuids::Services::Add)
|
50
53
|
def run
|
51
|
-
|
54
|
+
run!
|
52
55
|
rescue => err
|
53
56
|
publish :error, err.messages
|
54
57
|
else
|
@@ -59,9 +62,11 @@ module Uuids
|
|
59
62
|
|
60
63
|
attr_reader :uuid
|
61
64
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
+
def run!
|
66
|
+
escape do
|
67
|
+
@uuid = Models::Uuid.create! record: record, value: value
|
68
|
+
add_message "success", :created, uuid: uuid, record: name
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
def name
|
@@ -54,14 +54,14 @@ module Uuids
|
|
54
54
|
# @api hide
|
55
55
|
# Constructs the object and adds the attribute.
|
56
56
|
# @example (see Uuids::Base::BelongsTo)
|
57
|
-
# @
|
57
|
+
# @param [ActiveRecord::Base] klass The model to add attribute to.
|
58
58
|
# Should have a corresponding column for reference by uuid.
|
59
|
-
# @
|
60
|
-
# @
|
59
|
+
# @param [String, Symbol] name The name of the attribute to be added.
|
60
|
+
# @param [ActiveRecord::Base] model The model to be referred by uuid.
|
61
61
|
# Should include the <tt>Uuids::Base</tt> module.
|
62
62
|
# @raise (see Uuids::Base::BelongsTo#add)
|
63
|
-
def self.add(
|
64
|
-
new(
|
63
|
+
def self.add(klass, name, model)
|
64
|
+
new(klass, name, model).add
|
65
65
|
end
|
66
66
|
|
67
67
|
# @api hide
|
data/lib/uuids/version.rb
CHANGED
data/spec/dummy/db/schema.rb
CHANGED
@@ -30,12 +30,12 @@ ActiveRecord::Schema.define(version: 20151215182355) do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
create_table "uuids_uuids", force: :cascade do |t|
|
33
|
-
t.string "value", limit: 36,
|
34
|
-
t.integer "record_id",
|
35
|
-
t.string "record_type",
|
33
|
+
t.string "value", limit: 36, null: false
|
34
|
+
t.integer "record_id", null: false
|
35
|
+
t.string "record_type", null: false
|
36
36
|
end
|
37
37
|
|
38
|
-
add_index "uuids_uuids", ["
|
38
|
+
add_index "uuids_uuids", ["record_type", "record_id"], name: "index_uuids_uuids_on_record_type_and_record_id"
|
39
39
|
add_index "uuids_uuids", ["value"], name: "index_uuids_uuids_on_value", unique: true
|
40
40
|
|
41
41
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -12,8 +12,7 @@ module Uuids::Services
|
|
12
12
|
let!(:params) do
|
13
13
|
{
|
14
14
|
"record" => record,
|
15
|
-
"value" => SecureRandom.uuid
|
16
|
-
"wrong" => "wrong"
|
15
|
+
"value" => SecureRandom.uuid
|
17
16
|
}
|
18
17
|
end
|
19
18
|
|
@@ -25,28 +24,13 @@ module Uuids::Services
|
|
25
24
|
service
|
26
25
|
end
|
27
26
|
|
28
|
-
describe ".new" do
|
29
|
-
|
30
|
-
it "sets #record" do
|
31
|
-
expect(subject.record).to eq params["record"]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "sets #value" do
|
35
|
-
expect(subject.value).to eq params["value"]
|
36
|
-
end
|
37
|
-
|
38
|
-
it "whitelists params" do
|
39
|
-
expect(subject.params).to eq params.slice("record", "value")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
27
|
describe "#run" do
|
44
28
|
|
45
29
|
context "with valid params" do
|
46
30
|
|
47
31
|
it "adds a uuid to the record" do
|
48
32
|
expect { subject.run }.to change { uuids_class.count }.by 1
|
49
|
-
expect(uuids_class.last).to correspond_to
|
33
|
+
expect(uuids_class.last).to correspond_to params
|
50
34
|
end
|
51
35
|
|
52
36
|
it "publishes :created" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hexx-active_record
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
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: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: coveralls
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|