perpetuity 1.0.0 → 1.0.1

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.
@@ -12,73 +12,84 @@ module Perpetuity
12
12
  let(:wrapper) { object.to_model }
13
13
 
14
14
  it 'determines whether it is persisted based on @id ivar' do
15
- object.should_not be_persisted
15
+ expect(object).not_to be_persisted
16
16
  object.id = 'lol'
17
- object.should be_persisted
17
+ expect(object).to be_persisted
18
18
  end
19
19
 
20
20
  it 'returns the id as to_param' do
21
- object.to_param.should be == nil
21
+ expect(object.to_param).to be == nil
22
22
  object.id = 'foo'
23
- object.to_param.should be == 'foo'
23
+ expect(object.to_param).to be == 'foo'
24
24
  end
25
25
 
26
26
  it 'returns the keys on the object' do
27
- object.to_key.should be == nil
27
+ expect(object.to_key).to be == nil
28
28
  object.id = 'bar'
29
- object.to_key.should be == ['bar']
29
+ expect(object.to_key).to be == ['bar']
30
30
  end
31
31
 
32
32
  it 'returns the model name' do
33
- klass.model_name.should be == klass
33
+ expect(klass.model_name).to be == klass
34
+ expect(klass.new.model_name).to be == klass
35
+ end
36
+
37
+ it 'returns self as the model' do
38
+ model = klass.new
39
+ expect(model.to_model).to be model
40
+ end
41
+
42
+ it 'returns its name in lowercase as the i18n key' do
43
+ stub_const 'Foo::BarBaz', klass
44
+ expect(klass.i18n_key).to be == 'foo.bar_baz'
34
45
  end
35
46
 
36
47
  describe 'param_key' do
37
48
  it 'converts :: to _' do
38
49
  stub_const 'Foo::Bar', klass
39
- Foo::Bar.param_key.should be == 'foo_bar'
50
+ expect(Foo::Bar.param_key).to be == 'foo_bar'
40
51
  end
41
52
 
42
53
  it 'converts title-case to snake-case' do
43
54
  stub_const 'UserRegistration', klass
44
- UserRegistration.param_key.should be == 'user_registration'
55
+ expect(UserRegistration.param_key).to be == 'user_registration'
45
56
  end
46
57
  end
47
58
 
48
59
  it 'returns the route_key' do
49
60
  stub_const 'Foo::Bar', klass
50
- Foo::Bar.route_key.should be == 'foo_bars'
61
+ expect(Foo::Bar.route_key).to be == 'foo_bars'
51
62
  end
52
63
 
53
64
  it 'returns the singular_route_key' do
54
65
  stub_const 'Foo::Bar', klass
55
- Foo::Bar.singular_route_key.should be == 'foo_bar'
66
+ expect(Foo::Bar.singular_route_key).to be == 'foo_bar'
56
67
  end
57
68
 
58
69
  it 'returns the partial path' do
59
70
  stub_const 'Article', klass
60
- Article.to_partial_path.should be == 'articles/_article'
71
+ expect(Article.to_partial_path).to be == 'articles/_article'
61
72
  end
62
73
 
63
74
  describe 'human' do
64
75
  it 'returns the class name for a single-word class name' do
65
76
  stub_const 'Article', klass
66
- Article.human.should == 'Article'
77
+ expect(Article.human).to be == 'Article'
67
78
  end
68
79
 
69
80
  it 'converts namespaced to capitalized words' do
70
81
  stub_const 'Foo::Bar', klass
71
- Foo::Bar.human.should == 'Foo Bar'
82
+ expect(Foo::Bar.human).to be == 'Foo Bar'
72
83
  end
73
84
 
74
85
  it 'separates title-cased words' do
75
86
  stub_const 'FooBarBaz', klass
76
- FooBarBaz.human.should == 'Foo Bar Baz'
87
+ expect(FooBarBaz.human).to be == 'Foo Bar Baz'
77
88
  end
78
89
 
79
90
  it 'separates snake-cased, capitalized words' do
80
91
  stub_const 'FOO_BAR_BAZ', klass
81
- FOO_BAR_BAZ.human.should == 'Foo Bar Baz'
92
+ expect(FOO_BAR_BAZ.human).to be == 'Foo Bar Baz'
82
93
  end
83
94
  end
84
95
  end
@@ -8,8 +8,13 @@ module Perpetuity
8
8
 
9
9
  before { object.instance_variable_set :@id, 1 }
10
10
 
11
- its(:klass) { should be Object }
12
- its(:id) { should be == 1 }
11
+ it "stores the object's class in the `klass` attribute" do
12
+ expect(reference.klass).to be Object
13
+ end
14
+
15
+ it "stores the object's id" do
16
+ expect(reference.id).to be 1
17
+ end
13
18
 
14
19
  describe 'comparability' do
15
20
  describe 'equality' do
@@ -12,62 +12,62 @@ module Perpetuity
12
12
 
13
13
  it "sorts the results" do
14
14
  sorted = retrieval.sort(:name)
15
- sorted.sort_attribute.should == :name
15
+ expect(sorted.sort_attribute).to be == :name
16
16
  end
17
17
 
18
18
  it "reverses the sort order of the results" do
19
19
  sorted = retrieval.sort(:name).reverse
20
- sorted.sort_direction.should == :descending
20
+ expect(sorted.sort_direction).to be == :descending
21
21
  end
22
22
 
23
23
  it "limits the result set" do
24
- retrieval.limit(1).result_limit.should == 1
24
+ expect(retrieval.limit(1).result_limit).to be == 1
25
25
  end
26
26
 
27
27
  it 'indicates whether it includes a specific item' do
28
- subject.stub(to_a: [1])
29
- subject.should include 1
28
+ allow(subject).to receive(:to_a) { [1] }
29
+ expect(subject).to include 1
30
30
  end
31
31
 
32
32
  it 'can be empty' do
33
- retrieval.stub(to_a: [])
34
- retrieval.should be_empty
33
+ allow(retrieval).to receive(:to_a) { [] }
34
+ expect(retrieval).to be_empty
35
35
  end
36
36
 
37
37
  describe 'pagination' do
38
38
  let(:paginated) { retrieval.page(2) }
39
39
  it 'paginates data' do
40
- paginated.result_offset.should == 20
40
+ expect(paginated.result_offset).to be == 20
41
41
  end
42
42
 
43
43
  it 'defaults to 20 items per page' do
44
- paginated.result_limit.should == 20
44
+ expect(paginated.result_limit).to be == 20
45
45
  end
46
46
 
47
47
  it 'sets the number of items per page' do
48
- paginated.per_page(50).result_limit.should == 50
48
+ expect(paginated.per_page(50).result_limit).to be == 50
49
49
  end
50
50
  end
51
51
 
52
52
  it 'retrieves data from the data source' do
53
53
  return_data = { id: 0, a: 1, b: 2 }
54
54
  return_object = Object.new
55
- return_object.stub(id: return_data[:id])
55
+ allow(return_object).to receive(:id) { return_data[:id] }
56
56
  options = { attribute: nil, direction: nil, limit: nil, skip: nil }
57
57
 
58
- data_source.should_receive(:retrieve).with('Object', query, options).
58
+ expect(data_source).to receive(:retrieve).with('Object', query, options).
59
59
  and_return([return_data])
60
- data_source.should_receive(:unserialize).with([return_data], mapper) { [return_object] }
61
- mapper.stub(:id_for)
60
+ expect(data_source).to receive(:unserialize).with([return_data], mapper) { [return_object] }
61
+ allow(mapper).to receive(:id_for)
62
62
  results = retrieval.to_a
63
63
 
64
- results.map(&:id).should == [0]
64
+ expect(results.map(&:id)).to be == [0]
65
65
  end
66
66
 
67
67
  it 'clears results cache' do
68
68
  retrieval.result_cache = [1,2,3]
69
69
  retrieval.clear_cache
70
- retrieval.result_cache.should be_nil
70
+ expect(retrieval.result_cache).to be_nil
71
71
  end
72
72
 
73
73
  describe 'identity map' do
@@ -75,18 +75,18 @@ module Perpetuity
75
75
  let(:retrieval) { Retrieval.new(mapper, query, identity_map: id_map) }
76
76
 
77
77
  it 'maintains an identity_map' do
78
- retrieval.identity_map.should be id_map
78
+ expect(retrieval.identity_map).to be id_map
79
79
  end
80
80
 
81
81
  it 'returns objects from the identity map with queries' do
82
82
  result = Object.new
83
83
  result.instance_variable_set :@id, '1'
84
84
  id_map << result
85
- mapper.stub(id_for: '1')
86
- data_source.stub(:retrieve)
87
- data_source.stub(unserialize: [result.dup])
85
+ allow(mapper).to receive(:id_for) { '1' }
86
+ allow(data_source).to receive(:retrieve)
87
+ allow(data_source).to receive(:unserialize) { [result.dup] }
88
88
 
89
- retrieval.to_a.should include result
89
+ expect(retrieval.to_a).to include result
90
90
  end
91
91
  end
92
92
  end
@@ -5,7 +5,7 @@ describe Perpetuity do
5
5
  describe 'mapper generation' do
6
6
  it 'generates mappers' do
7
7
  Perpetuity.generate_mapper_for Object
8
- Perpetuity[Object].should be_a Perpetuity::Mapper
8
+ expect(Perpetuity[Object]).to be_a Perpetuity::Mapper
9
9
  end
10
10
 
11
11
  it 'provides a DSL within the generated mapper' do
@@ -17,8 +17,8 @@ describe Perpetuity do
17
17
  mapper = Perpetuity[Object]
18
18
  object = Object.new
19
19
  mapper.insert object
20
- mapper.id_for(object).should be == object.object_id + 1
21
- mapper.attributes.should include :object_id
20
+ expect(mapper.id_for(object)).to be == object.object_id + 1
21
+ expect(mapper.attributes).to include :object_id
22
22
  end
23
23
  end
24
24
 
@@ -41,12 +41,12 @@ describe Perpetuity do
41
41
 
42
42
  it 'allows methods to act as scopes' do
43
43
  published_ids = mapper.published.to_a.map { |article| mapper.id_for(article) }
44
- published_ids.should include published_id
45
- published_ids.should_not include draft_id, not_yet_published_id
44
+ expect(published_ids).to include published_id
45
+ expect(published_ids).not_to include draft_id, not_yet_published_id
46
46
 
47
47
  unpublished_ids = mapper.unpublished.to_a.map { |article| mapper.id_for(article) }
48
- unpublished_ids.should_not include published_id
49
- unpublished_ids.should include draft_id, not_yet_published_id
48
+ expect(unpublished_ids).not_to include published_id
49
+ expect(unpublished_ids).to include draft_id, not_yet_published_id
50
50
  end
51
51
  end
52
52
 
@@ -57,19 +57,19 @@ describe Perpetuity do
57
57
 
58
58
  it 'registers an adapter' do
59
59
  Perpetuity.register_adapter :example => ExampleAdapter
60
- Perpetuity::Configuration.adapters[:example].should == ExampleAdapter
60
+ expect(Perpetuity::Configuration.adapters[:example]).to be == ExampleAdapter
61
61
  end
62
62
 
63
63
  it 'can re-register an adapter' do
64
64
  Perpetuity.register_adapter :example => ExampleAdapter
65
65
  Perpetuity.register_adapter :example => ExampleAdapter
66
- Perpetuity::Configuration.adapters[:example].should == ExampleAdapter
66
+ expect(Perpetuity::Configuration.adapters[:example]).to be == ExampleAdapter
67
67
  end
68
68
 
69
69
  it 'cannot re-register an adapter with a different class than originally registered' do
70
70
  Perpetuity.register_adapter :example => ExampleAdapter
71
71
  expect { Perpetuity.register_adapter :example => TrueClass }.to raise_exception
72
- Perpetuity::Configuration.adapters[:example].should == ExampleAdapter
72
+ expect(Perpetuity::Configuration.adapters[:example]).to be == ExampleAdapter
73
73
  end
74
74
  end
75
75
 
metadata CHANGED
@@ -1,50 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: perpetuity
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Jamie Gaskins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-08-16 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id003
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
23
20
  type: :development
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: rspec
27
21
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: "2.13"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
33
34
  type: :development
34
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
35
41
  description: Persistence layer for Ruby objects
36
- email:
42
+ email:
37
43
  - jgaskins@gmail.com
38
44
  executables: []
39
-
40
45
  extensions: []
41
-
42
46
  extra_rdoc_files: []
43
-
44
- files:
45
- - .gitignore
46
- - .rvmrc
47
- - .travis.yml
47
+ files:
48
+ - ".gitignore"
49
+ - ".rvmrc"
50
+ - ".travis.yml"
48
51
  - CHANGELOG.md
49
52
  - Gemfile
50
53
  - LICENSE
@@ -104,29 +107,30 @@ files:
104
107
  - spec/support/test_classes/topic.rb
105
108
  - spec/support/test_classes/user.rb
106
109
  homepage: https://github.com/jgaskins/perpetuity
107
- licenses:
110
+ licenses:
108
111
  - MIT
109
112
  metadata: {}
110
-
111
113
  post_install_message:
112
114
  rdoc_options: []
113
-
114
- require_paths:
115
+ require_paths:
115
116
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
117
- requirements:
118
- - *id003
119
- required_rubygems_version: !ruby/object:Gem::Requirement
120
- requirements:
121
- - *id003
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
122
127
  requirements: []
123
-
124
128
  rubyforge_project:
125
- rubygems_version: 2.2.2
129
+ rubygems_version: 2.4.5
126
130
  signing_key:
127
131
  specification_version: 4
128
132
  summary: Persistence library allowing serialization of Ruby objects
129
- test_files:
133
+ test_files:
130
134
  - spec/integration/associations_spec.rb
131
135
  - spec/integration/deletion_spec.rb
132
136
  - spec/integration/enumerable_spec.rb