minimodel 0.2.0 → 0.3.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.
@@ -77,8 +77,8 @@ class MiniModel
77
77
  index[pkey] = object
78
78
  end
79
79
 
80
- def find(key)
81
- index[key]
80
+ def find(primary_key, &block)
81
+ index.fetch(primary_key, &block)
82
82
  end
83
83
 
84
84
  def load_from(path)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'minimodel'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -9,8 +9,8 @@ class Colour < MiniModel
9
9
  insert name: 'Green', hexdigits: '00FF00'
10
10
  end
11
11
 
12
- describe Colour do
12
+ describe 'Colour' do
13
13
  it 'should assign auto incrementing id values' do
14
- Colour.all.map(&:id).must_equal [1, 2, 3]
14
+ Colour.all.map(&:id).must_equal([1, 2, 3])
15
15
  end
16
16
  end
@@ -17,92 +17,87 @@ describe 'A currency object' do
17
17
  end
18
18
 
19
19
  it 'should respond_to?(:code) and respond_to?(:name)' do
20
- @euro.respond_to?(:code).must_equal true
21
- @euro.respond_to?(:name).must_equal true
20
+ @euro.respond_to?(:code).must_equal(true)
21
+ @euro.respond_to?(:name).must_equal(true)
22
22
  end
23
23
 
24
24
  it 'should have attribute reader methods' do
25
- @euro.code.must_equal 'EUR'
26
- @euro.name.must_equal 'Euro'
25
+ @euro.code.must_equal('EUR')
26
+ @euro.name.must_equal('Euro')
27
27
  end
28
28
 
29
- describe '#eql?' do
30
- describe 'when passed the same currency object' do
31
- it 'should return true' do
32
- @euro.eql?(@euro).must_equal true
33
- @euro.eql?(Currency.new(code: 'EUR', name: 'Euro')).must_equal true
34
- end
29
+ describe 'eql query method' do
30
+ it 'should return true when passed a currency object with the same attributes' do
31
+ @euro.eql?(@euro).must_equal(true)
32
+ @euro.eql?(Currency.new(code: 'EUR', name: 'Euro')).must_equal(true)
35
33
  end
36
34
 
37
- describe 'when passed a different currency object' do
38
- it 'should return false' do
39
- @euro.eql?(Currency.new(code: 'GBP', name: 'Pound sterling')).must_equal false
40
- end
35
+ it 'should return false when given a currency object with a different code' do
36
+ @euro.eql?(Currency.new(code: 'GBP', name: 'Pound sterling')).must_equal(false)
41
37
  end
42
38
  end
43
39
 
44
- describe '#to_hash' do
40
+ describe 'to_hash method' do
45
41
  it 'should return a hash containing the object attributes' do
46
- @euro.to_hash.must_be_kind_of Hash
47
- @euro.to_hash.must_equal code: 'EUR', name: 'Euro'
42
+ @euro.to_hash.must_equal({code: 'EUR', name: 'Euro'})
48
43
  end
49
44
  end
50
45
 
51
- describe '#to_json' do
46
+ describe 'to_json method' do
52
47
  it 'should return a string containing a JSON object' do
53
- @euro.to_json.must_equal '{"code":"EUR","name":"Euro"}'
48
+ @euro.to_json.must_equal('{"code":"EUR","name":"Euro"}')
54
49
  end
55
50
  end
56
51
 
57
- describe '#read_attribute' do
52
+ describe 'read_attribute method' do
58
53
  it 'should return the value corresponding to the given attribute name' do
59
- @euro.read_attribute(:code).must_equal 'EUR'
60
- @euro.read_attribute(:name).must_equal 'Euro'
54
+ @euro.read_attribute(:code).must_equal('EUR')
55
+ @euro.read_attribute(:name).must_equal('Euro')
61
56
  end
62
57
  end
63
58
  end
64
59
 
65
- describe Currency do
66
- describe '#all' do
60
+ describe 'Currency' do
61
+ describe 'all class method' do
67
62
  it 'should return an array containing currency objects' do
68
- Currency.all.must_be_kind_of Array
69
- Currency.all.all? { |object| object.must_be_kind_of Currency }
63
+ Currency.all.must_be_kind_of(Array)
64
+ Currency.all.each { |object| object.must_be_kind_of(Currency) }
70
65
  end
71
66
  end
72
67
 
73
- describe '#primary_key' do
68
+ describe 'primary_key class method' do
74
69
  it 'should return the primary key specified using #indexed_by' do
75
- Currency.primary_key.must_equal :code
70
+ Currency.primary_key.must_equal(:code)
76
71
  end
77
72
  end
78
73
 
79
- describe '#count' do
74
+ describe 'count class method' do
80
75
  it 'should return the total number of currencies defined' do
81
- Currency.count.must_equal 5
76
+ Currency.count.must_equal(5)
82
77
  end
83
78
  end
84
79
 
85
- describe '#find' do
86
- describe 'when passed a valid currency code' do
87
- it 'should return the correct currency' do
88
- currency = Currency.find('EUR')
80
+ describe 'find class method' do
81
+ it 'should return the correct currency object' do
82
+ currency = Currency.find('EUR')
89
83
 
90
- currency.must_be_kind_of Currency
91
- currency.code.must_equal 'EUR'
92
- currency.name.must_equal 'Euro'
93
- end
84
+ currency.must_be_kind_of(Currency)
85
+ currency.code.must_equal('EUR')
86
+ currency.name.must_equal('Euro')
94
87
  end
95
88
 
96
- describe 'when passed an invalid currency code' do
97
- it 'should return nil' do
98
- Currency.find('FOO').must_be_nil
99
- end
89
+ it 'should raise an error if the currency cannot be found' do
90
+ proc { Currency.find('FOO') }.must_raise(KeyError)
91
+ end
92
+
93
+ it 'should yield if the currency cannot be found and the caller supplies a block' do
94
+ Currency.find('FOO') { nil }.must_be_nil
100
95
  end
101
96
  end
102
97
 
103
- describe '#insert' do
98
+ describe 'insert class method' do
104
99
  it 'should raise an error when passed a key that already exists' do
105
- proc { Currency.insert(code: 'EUR', name: 'Euro') }.must_raise MiniModel::DuplicateKeyError
100
+ proc { Currency.insert(code: 'EUR', name: 'Euro') }.must_raise(MiniModel::DuplicateKeyError)
106
101
  end
107
102
  end
108
103
  end
@@ -65,47 +65,21 @@ describe 'A level object' do
65
65
  @course_names = %w( VMBO-T/Duits VMBO-T/Engels VMBO-T/Nederlands )
66
66
  end
67
67
 
68
- describe '#profiles' do
69
- it 'should be enumerable' do
70
- @level.profiles.must_respond_to :each
71
- @level.profiles.class.ancestors.must_include Enumerable
72
- end
73
-
74
- describe '#size' do
75
- it 'should return the number of profiles linked to this level' do
76
- @level.profiles.size.must_equal 4
77
- end
78
- end
79
-
80
- describe '#to_a' do
81
- it 'should return an array containing the correct profile objects' do
82
- profiles = @level.profiles.to_a
83
-
84
- profiles.must_be_kind_of Array
85
- profiles.map(&:name).sort.must_equal @profile_names
86
- end
68
+ describe 'profiles method' do
69
+ it 'should return an enumerable object with the correct size' do
70
+ profiles = @level.profiles
71
+ profiles.must_respond_to(:each)
72
+ profiles.class.ancestors.must_include(Enumerable)
73
+ profiles.size.must_equal(4)
87
74
  end
88
75
  end
89
76
 
90
- describe '#courses' do
91
- it 'should be enumerable' do
92
- @level.courses.must_respond_to :each
93
- @level.courses.class.ancestors.must_include Enumerable
94
- end
95
-
96
- describe '#size' do
97
- it 'should return the number of courses linked to this level' do
98
- @level.courses.size.must_equal 3
99
- end
100
- end
101
-
102
- describe '#to_a' do
103
- it 'should return an array containing the correct course objects' do
104
- courses = @level.courses.to_a
105
-
106
- courses.must_be_kind_of Array
107
- courses.map(&:name).sort.must_equal @course_names
108
- end
77
+ describe 'courses method' do
78
+ it 'should return an enumerable object with the correct size' do
79
+ courses = @level.courses
80
+ courses.must_respond_to(:each)
81
+ courses.class.ancestors.must_include(Enumerable)
82
+ courses.size.must_equal(3)
109
83
  end
110
84
  end
111
85
  end
@@ -115,10 +89,10 @@ describe 'A profile object' do
115
89
  @profile = Profile.find(8)
116
90
  end
117
91
 
118
- describe '#level' do
92
+ describe 'level method' do
119
93
  it 'should return the correct level object' do
120
- @profile.level.must_be_kind_of Level
121
- @profile.level.name.must_equal 'HAVO'
94
+ @profile.level.must_be_kind_of(Level)
95
+ @profile.level.name.must_equal('HAVO')
122
96
  end
123
97
  end
124
98
  end
@@ -128,10 +102,10 @@ describe 'A course object' do
128
102
  @course = Course.find_by_name('VWO/Engels')
129
103
  end
130
104
 
131
- describe '#level' do
105
+ describe 'level method' do
132
106
  it 'should return the correct level object' do
133
- @course.level.must_be_kind_of Level
134
- @course.level.name.must_equal 'VWO'
107
+ @course.level.must_be_kind_of(Level)
108
+ @course.level.name.must_equal('VWO')
135
109
  end
136
110
  end
137
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-11 00:00:00.000000000Z
12
+ date: 2012-01-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &9966180 !ruby/object:Gem::Requirement
16
+ requirement: &10440420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *9966180
24
+ version_requirements: *10440420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &9965800 !ruby/object:Gem::Requirement
27
+ requirement: &10440150 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 3.0.3
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *9965800
35
+ version_requirements: *10440150
36
36
  description: A little library for defining little models
37
37
  email:
38
38
  - mail@timcraft.com