uuids 4.1.3 → 4.1.4

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
2
  SHA1:
3
- metadata.gz: 26ab118cb2345e2661d2db7cd4dfeda6729531b8
4
- data.tar.gz: e86f8c257d37ecd12e95d05301f1973ef92bf9d8
3
+ metadata.gz: b31b167f908d6ec2456b1925dc598826d6a071bc
4
+ data.tar.gz: a792ea83d4f4d187d64c71915f8068fad8e6a1ba
5
5
  SHA512:
6
- metadata.gz: 30236a707e43fd13e383659b3b50b3d304ccf26a078d288b07789253c2ae1421114bf6dd37a4adc566305795fd8f823b1431bb8ad8e8e2d0fe7b5ab4a1bd26d0
7
- data.tar.gz: 78b2169f231d9a70ec7786a1d7940d7ced442fca689884d42078b6f8dfb08945e4e7944f603cfa9c1e3b6584c79091563f43fe978690adb24b7cf57ac0b18bfe
6
+ metadata.gz: 4e6a91b697ebca4e978525666048c5c884b120345519dc889f72f307c09942bb9f949fc5314317b2964b2c9f8132d9164316b62bf49e7d318ff0b9b7d7d9e3fc
7
+ data.tar.gz: 5187b791e2878df7896f4a7d49e9fc742810e398649f95fa5cecab9ecd91cca3fc888d95f22be68f3fe50010eb014f1d5b84ec68208855ae597d9422c5028aa7
data/lib/uuids/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Uuids
2
2
 
3
3
  # Current release.
4
- VERSION = "4.1.3"
4
+ VERSION = "4.1.4"
5
5
  end
Binary file
@@ -0,0 +1,11 @@
1
+ # Checks if an object has method values as in given hash
2
+ #
3
+ # expect(object).to correspond_to hash
4
+ RSpec::Matchers.define :correspond_to do |hash|
5
+ match do |object|
6
+ hash.each do |key, value|
7
+ expect(object).not_to be_blank
8
+ expect(object.send key).to eq value
9
+ end
10
+ end
11
+ end
@@ -5,7 +5,7 @@ describe "$ uuids", :sandbox do
5
5
 
6
6
  describe "install" do
7
7
 
8
- let!(:root) { File.expand_path("../../..", __FILE__) }
8
+ let!(:root) { File.expand_path("../../../..", __FILE__) }
9
9
  let!(:migrations) { Dir["#{ root }/db/migrate/*.rb"] }
10
10
 
11
11
  describe "without options" do
@@ -3,38 +3,44 @@ require "spec_helper"
3
3
  module Uuids
4
4
  describe Base do
5
5
 
6
+ # Dependencies
7
+ let(:described_module) { Uuids::Base }
8
+ let(:uuids_class) { Uuids::Models::Uuid }
9
+
6
10
  describe ".included" do
7
11
 
8
12
  context "from non AR class" do
9
13
 
10
14
  before { class Test; end }
11
- after { begin; Uuids::Base.send :remove_constant, :Test; rescue; end }
15
+ after do
16
+ begin; described_module.send :remove_constant, :Test; rescue; end
17
+ end
12
18
 
13
19
  it "fails" do
14
- expect { Test.include Uuids::Base }.to raise_error
20
+ expect { Test.include described_module }.to raise_error
15
21
  end
16
22
  end
17
23
 
18
24
  context "from AR model" do
19
25
 
20
26
  it "doesn't fail" do
21
- expect { City.include Uuids::Base }.not_to raise_error
27
+ expect { City.include described_module }.not_to raise_error
22
28
  end
23
29
  end
24
30
  end
25
31
 
26
32
  describe ".has_uuids" do
27
33
 
28
- # For running this specification, the City AR model prepared in the
29
- # `spec dummy/app/models/item.rb`. The model included Uuids::Base.
34
+ # For this specification, the City AR model has been prepared in the
35
+ # `spec dummy/app/models/city.rb`. The model included Uuids::Base.
30
36
  before { City.send :has_uuids }
31
37
  subject { City.new }
32
38
 
33
39
  it "defines the #uuids attribute" do
34
40
  subject.uuids.new value: SecureRandom.uuid
35
41
  subject.save!
36
- expect(Uuids::Models::Uuid.first.try(:record)).to eq subject
37
- expect(subject.uuids.first).to eq Uuids::Models::Uuid.first
42
+ expect(uuids_class.first.try(:record)).to eq subject
43
+ expect(subject.uuids.first).to eq uuids_class.first
38
44
  end
39
45
 
40
46
  it "defines the #uuid method" do
@@ -46,13 +52,13 @@ module Uuids
46
52
  it "defines the #uuid= method" do
47
53
  value = "3ea8fd89-232f-4ed1-90b5-743da173cd7d"
48
54
  subject.uuid = value
49
- expect(subject.uuids.map(&:value)).to be_include(value)
55
+ expect(subject.uuids.map(&:value)).to include(value)
50
56
  end
51
57
 
52
58
  it "defines the #uuids= method" do
53
59
  value = "3ea8fd89-232f-4ed1-90b5-743da173cd7d"
54
60
  subject.uuids = [value]
55
- expect(subject.uuids.map(&:value)).to be_include(value)
61
+ expect(subject.uuids.map(&:value)).to include(value)
56
62
  end
57
63
 
58
64
  it "defines +by_uuid+ class scope" do
@@ -64,7 +70,7 @@ module Uuids
64
70
  end
65
71
 
66
72
  it "creates the first uuid by default" do
67
- expect(subject.uuid).not_to be_blank
73
+ expect(subject.uuid).to be_present
68
74
  end
69
75
 
70
76
  it "requires the #uuids attribute" do
@@ -119,8 +125,7 @@ module Uuids
119
125
  end
120
126
 
121
127
  it "sets the object" do
122
- expect { subject.state = state }
123
- .to change { subject.state }.to state
128
+ expect { subject.state = state }.to change { subject.state }.to state
124
129
  end
125
130
 
126
131
  it "sets the object uuid" do
@@ -130,14 +135,12 @@ module Uuids
130
135
 
131
136
  it "resets the object" do
132
137
  subject.state = state
133
- expect { subject.state = nil }
134
- .to change { subject.state }.to nil
138
+ expect { subject.state = nil }.to change { subject.state }.to nil
135
139
  end
136
140
 
137
141
  it "resets the object uuid" do
138
142
  subject.state = state
139
- expect { subject.state = nil }
140
- .to change { subject.state_uuid }.to nil
143
+ expect { subject.state = nil }.to change { subject.state_uuid }.to nil
141
144
  end
142
145
 
143
146
  it "sets the object by uuid" do
@@ -3,26 +3,26 @@ require "spec_helper"
3
3
  module Uuids::Models
4
4
  describe Uuid do
5
5
 
6
+ let!(:value) { SecureRandom.uuid }
7
+
6
8
  describe "#value" do
7
9
 
8
10
  before { subject.record = create(:record) }
9
11
 
10
12
  it "can be assigned manually" do
11
- value = SecureRandom.uuid
12
13
  subject.value = value
13
14
  subject.save!
14
15
  expect(subject.reload.value).to eq value
15
16
  end
16
17
 
17
18
  it "assigned by default" do
18
- expect(subject.value).not_to be_blank
19
+ expect(subject.value).to be_present
19
20
  end
20
21
  end
21
22
 
22
23
  describe "#value=" do
23
24
 
24
25
  let!(:subject) { build :uuid }
25
- let!(:value) { SecureRandom.uuid }
26
26
 
27
27
  it "sets #value before creation" do
28
28
  subject.value = value
@@ -57,7 +57,7 @@ module Uuids::Models
57
57
  end
58
58
 
59
59
  it "fails with wrong value" do
60
- subject.value = "not a valid uuid"
60
+ subject.value = "wrong"
61
61
  expect(subject).not_to be_valid
62
62
  end
63
63
  end
@@ -4,18 +4,28 @@ require "spec_helper"
4
4
  module Uuids::Services
5
5
  describe Add do
6
6
 
7
+ # Models dependency injection
8
+ let(:uuids_class) { Uuids::Models::Uuid }
9
+
10
+ # Parameters by default
7
11
  let!(:record) { create :record }
8
12
  let!(:params) do
9
13
  {
10
14
  "record" => record,
11
- "value" => "47027502-4574-3434-0547-032453443434",
15
+ "value" => SecureRandom.uuid,
12
16
  "wrong" => "wrong"
13
17
  }
14
18
  end
15
19
 
16
- describe ".new" do
20
+ # The service and its listener
21
+ let(:listener) { spy "listener" }
22
+ subject do
23
+ service = described_class.new params
24
+ service.subscribe listener
25
+ service
26
+ end
17
27
 
18
- subject { Add.new params }
28
+ describe ".new" do
19
29
 
20
30
  it "sets #record" do
21
31
  expect(subject.record).to eq params["record"]
@@ -32,41 +42,35 @@ module Uuids::Services
32
42
 
33
43
  describe "#run" do
34
44
 
35
- let(:listener) { double "listener" }
36
-
37
45
  context "with valid params" do
38
46
 
39
- subject { Add.new params }
40
-
41
47
  it "adds a uuid to the record" do
42
- expect { subject.run }.to change { Uuids::Models::Uuid.count }.by 1
43
- uuid = Uuids::Models::Uuid.last
44
- expect(uuid.record).to eq params["record"]
45
- expect(uuid.value).to eq params["value"]
48
+ expect { subject.run }.to change { uuids_class.count }.by 1
49
+ expect(uuids_class.last).to correspond_to subject.params
46
50
  end
47
51
 
48
52
  it "publishes :created" do
49
- subject.subscribe listener
50
- expect(listener).to receive(:created) do |uuid, messages|
51
- expect(uuid).to eq Uuids::Models::Uuid.last
52
- expect(messages).not_to be_blank
53
- end
54
53
  subject.run
54
+ expect(listener).to have_received(:created) do |uuid, messages|
55
+ expect(uuid).to eq uuids_class.last
56
+ expect(messages).to be_present
57
+ end
55
58
  end
56
59
  end
57
60
 
58
61
  context "with a wrong value" do
59
62
 
60
- subject { Add.new params.merge(value: "wrong") }
63
+ before { params.merge! "value" => "wrong" }
61
64
 
62
65
  it "doesn't create a uuid" do
63
- expect { subject.run }.not_to change { Uuids::Models::Uuid.all }
66
+ expect { subject.run }.not_to change { uuids_class.all }
64
67
  end
65
68
 
66
69
  it "publishes :error" do
67
- subject.subscribe listener
68
- expect(listener).to receive(:error)
69
70
  subject.run
71
+ expect(listener).to have_received(:error) do |messages|
72
+ expect(messages).to be_present
73
+ end
70
74
  end
71
75
  end
72
76
  end
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.3
4
+ version: 4.1.4
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-20 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hexx-active_record
@@ -244,6 +244,7 @@ files:
244
244
  - spec/support/all/config/garbage_collection.rb
245
245
  - spec/support/all/config/random_order.rb
246
246
  - spec/support/all/config/rspec.rb
247
+ - spec/support/all/matchers/correspond_to.rb
247
248
  - spec/support/development/config/sandbox.rb
248
249
  - spec/support/development/config/timecop.rb
249
250
  - spec/support/development/helpers/capture_stdout.rb
@@ -317,6 +318,7 @@ test_files:
317
318
  - spec/support/all/config/focus.rb
318
319
  - spec/support/all/config/random_order.rb
319
320
  - spec/support/all/config/rspec.rb
321
+ - spec/support/all/matchers/correspond_to.rb
320
322
  - spec/support/runtime/config/i18n.rb
321
323
  - spec/support/runtime/config/factory_girl.rb
322
324
  - spec/support/runtime/config/database_cleaner.rb