minimodel 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
- Minimodel: A little library for defining little models
2
- ======================================================
1
+ A little library for defining little models
2
+ ===========================================
3
+
4
+
5
+ Installation
6
+ ------------
7
+
8
+ $ gem install minimodel
3
9
 
4
10
 
5
11
  Motivation
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rake/testtask'
2
2
 
3
- task :default => :test
3
+ task :default => :spec
4
4
 
5
- Rake::TestTask.new do |t|
5
+ Rake::TestTask.new(:spec) do |t|
6
6
  t.test_files = FileList['spec/*_spec.rb']
7
+ t.warning = true
7
8
  end
@@ -1,6 +1,10 @@
1
1
  require 'yaml'
2
2
 
3
3
  class MiniModel
4
+ if defined?(id)
5
+ undef_method :id
6
+ end
7
+
4
8
  def initialize(attributes)
5
9
  @attributes = attributes.to_hash
6
10
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'minimodel'
3
- s.version = '0.4.0'
3
+ s.version = '1.0.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -8,7 +8,14 @@ Gem::Specification.new do |s|
8
8
  s.description = 'A little library for defining little models'
9
9
  s.summary = 'See description'
10
10
  s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md Rakefile minimodel.gemspec)
11
+ s.add_development_dependency('rake', '~> 10.0.3')
11
12
  s.add_development_dependency('activesupport', ['>= 3.0.3'])
12
13
  s.add_development_dependency('activerecord', ['>= 3.0.3'])
14
+ s.add_development_dependency('sqlite3', ['~> 1.3.6'])
13
15
  s.require_path = 'lib'
16
+
17
+ if RUBY_VERSION == '1.8.7'
18
+ s.add_development_dependency('minitest', '>= 4.2.0')
19
+ s.add_development_dependency('json', '>= 1.7.7')
20
+ end
14
21
  end
@@ -2,15 +2,15 @@ require 'minitest/autorun'
2
2
  require 'minimodel'
3
3
 
4
4
  class Colour < MiniModel
5
- indexed_by :id, auto_increment: true
5
+ indexed_by :id, :auto_increment => true
6
6
 
7
- insert name: 'Blue', hexdigits: '0000FF'
8
- insert name: 'Red', hexdigits: 'FF0000'
9
- insert name: 'Green', hexdigits: '00FF00'
7
+ insert :name => 'Blue', :hexdigits => '0000FF'
8
+ insert :name => 'Red', :hexdigits => 'FF0000'
9
+ insert :name => 'Green', :hexdigits => '00FF00'
10
10
  end
11
11
 
12
12
  describe 'Colour' do
13
- it 'should assign auto incrementing id values' do
13
+ it 'assigns auto incrementing id values' do
14
14
  Colour.all.map(&:id).must_equal([1, 2, 3])
15
15
  end
16
16
  end
@@ -7,50 +7,55 @@ class Currency < MiniModel
7
7
 
8
8
  load_from 'spec/currency_data.yml'
9
9
 
10
- insert code: 'INR', name: 'Indian rupee'
11
- insert code: 'JPY', name: 'Japanese yen'
10
+ insert :code => 'INR', :name => 'Indian rupee'
11
+ insert :code => 'JPY', :name => 'Japanese yen'
12
12
  end
13
13
 
14
14
  describe 'A currency object' do
15
15
  before do
16
- @euro = Currency.new(code: 'EUR', name: 'Euro')
16
+ @euro = Currency.new(:code => 'EUR', :name => 'Euro')
17
17
  end
18
18
 
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)
19
+ if Object.new.respond_to?(:respond_to_missing?)
20
+ it 'responds to code and name methods' do
21
+ @euro.respond_to?(:code).must_equal(true)
22
+ @euro.respond_to?(:name).must_equal(true)
23
+ end
22
24
  end
23
25
 
24
- it 'should have attribute reader methods' do
26
+ it 'provides attribute reader methods' do
25
27
  @euro.code.must_equal('EUR')
26
28
  @euro.name.must_equal('Euro')
27
29
  end
28
30
 
29
31
  describe 'eql query method' do
30
- it 'should return true when passed a currency object with the same attributes' do
32
+ it 'returns true when passed a currency object with the same attributes' do
31
33
  @euro.eql?(@euro).must_equal(true)
32
- @euro.eql?(Currency.new(code: 'EUR', name: 'Euro')).must_equal(true)
34
+ @euro.eql?(Currency.new(:code => 'EUR', :name => 'Euro')).must_equal(true)
33
35
  end
34
36
 
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)
37
+ it 'returns false when given a currency object with a different code' do
38
+ @euro.eql?(Currency.new(:code => 'GBP', :name => 'Pound sterling')).must_equal(false)
37
39
  end
38
40
  end
39
41
 
40
42
  describe 'to_hash method' do
41
- it 'should return a hash containing the object attributes' do
42
- @euro.to_hash.must_equal({code: 'EUR', name: 'Euro'})
43
+ it 'returns a hash containing the object attributes' do
44
+ @euro.to_hash.must_equal({:code => 'EUR', :name => 'Euro'})
43
45
  end
44
46
  end
45
47
 
46
48
  describe 'to_json method' do
47
- it 'should return a string containing a JSON object' do
48
- @euro.to_json.must_equal('{"code":"EUR","name":"Euro"}')
49
+ it 'returns a string containing the object attributes encoded as json' do
50
+ output = @euro.to_json
51
+ output.must_match(/\{.+?\}/)
52
+ output.must_match(/"code":"EUR"/)
53
+ output.must_match(/"name":"Euro"/)
49
54
  end
50
55
  end
51
56
 
52
57
  describe 'read_attribute method' do
53
- it 'should return the value corresponding to the given attribute name' do
58
+ it 'returns the value corresponding to the given attribute name' do
54
59
  @euro.read_attribute(:code).must_equal('EUR')
55
60
  @euro.read_attribute(:name).must_equal('Euro')
56
61
  end
@@ -59,32 +64,35 @@ end
59
64
 
60
65
  describe 'Currency' do
61
66
  describe 'all class method' do
62
- it 'should return an array containing currency objects' do
67
+ it 'returns an array containing currency objects' do
63
68
  Currency.all.must_be_kind_of(Array)
64
69
  Currency.all.each { |object| object.must_be_kind_of(Currency) }
65
70
  end
66
71
  end
67
72
 
68
73
  describe 'keys class method' do
69
- it 'should return an array containing all the primary keys' do
70
- Currency.keys.must_equal(%w(EUR GBP USD INR JPY))
74
+ it 'returns an array containing all the primary keys' do
75
+ keys = Currency.keys
76
+ keys.length.must_equal(5)
77
+
78
+ %w(EUR GBP USD INR JPY).each { |key| keys.must_include(key) }
71
79
  end
72
80
  end
73
81
 
74
82
  describe 'primary_key class method' do
75
- it 'should return the primary key specified using #indexed_by' do
83
+ it 'returns the name of the primary key attribute' do
76
84
  Currency.primary_key.must_equal(:code)
77
85
  end
78
86
  end
79
87
 
80
88
  describe 'count class method' do
81
- it 'should return the total number of currencies defined' do
89
+ it 'returns the total number of currencies' do
82
90
  Currency.count.must_equal(5)
83
91
  end
84
92
  end
85
93
 
86
94
  describe 'find class method' do
87
- it 'should return the correct currency object' do
95
+ it 'returns the correct currency object' do
88
96
  currency = Currency.find('EUR')
89
97
 
90
98
  currency.must_be_kind_of(Currency)
@@ -92,18 +100,22 @@ describe 'Currency' do
92
100
  currency.name.must_equal('Euro')
93
101
  end
94
102
 
95
- it 'should raise an error if the currency cannot be found' do
96
- proc { Currency.find('FOO') }.must_raise(KeyError)
103
+ it 'raises an error if the currency cannot be found' do
104
+ if defined?(KeyError)
105
+ proc { Currency.find('FOO') }.must_raise(KeyError) # 1.9
106
+ else
107
+ proc { Currency.find('FOO') }.must_raise(IndexError) # 1.8
108
+ end
97
109
  end
98
110
 
99
- it 'should yield if the currency cannot be found and the caller supplies a block' do
111
+ it 'yields if the currency cannot be found and the caller supplies a block' do
100
112
  Currency.find('FOO') { nil }.must_be_nil
101
113
  end
102
114
  end
103
115
 
104
116
  describe 'insert class method' do
105
- it 'should raise an error when passed a key that already exists' do
106
- proc { Currency.insert(code: 'EUR', name: 'Euro') }.must_raise(MiniModel::DuplicateKeyError)
117
+ it 'raises an error when passed a key that already exists' do
118
+ proc { Currency.insert(:code => 'EUR', :name => 'Euro') }.must_raise(MiniModel::DuplicateKeyError)
107
119
  end
108
120
  end
109
121
  end
@@ -3,7 +3,7 @@ require 'minimodel'
3
3
  require 'minimodel/associations'
4
4
  require 'active_record'
5
5
 
6
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
6
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
7
7
 
8
8
  ActiveRecord::Schema.define(:version => 1) do
9
9
  create_table :courses, :force => true do |t|
@@ -18,30 +18,30 @@ class Level < MiniModel
18
18
  has_many :courses
19
19
  has_many :profiles
20
20
 
21
- insert name: 'VMBO-T'
22
- insert name: 'HAVO'
23
- insert name: 'VWO'
21
+ insert :name => 'VMBO-T'
22
+ insert :name => 'HAVO'
23
+ insert :name => 'VWO'
24
24
  end
25
25
 
26
26
  class Profile < MiniModel
27
- indexed_by :id, auto_increment: true
27
+ indexed_by :id, :auto_increment => true
28
28
 
29
29
  belongs_to :level
30
30
 
31
- insert level_name: 'VMBO-T', name: 'Techniek'
32
- insert level_name: 'VMBO-T', name: 'Zorg en Welzijn'
33
- insert level_name: 'VMBO-T', name: 'Economie'
34
- insert level_name: 'VMBO-T', name: 'Landbouw'
31
+ insert :level_name => 'VMBO-T', :name => 'Techniek'
32
+ insert :level_name => 'VMBO-T', :name => 'Zorg en Welzijn'
33
+ insert :level_name => 'VMBO-T', :name => 'Economie'
34
+ insert :level_name => 'VMBO-T', :name => 'Landbouw'
35
35
 
36
- insert level_name: 'HAVO', name: 'Economie en Maatschappij'
37
- insert level_name: 'HAVO', name: 'Cultuur en Maatschappij'
38
- insert level_name: 'HAVO', name: 'Natuur en Gezondheid'
39
- insert level_name: 'HAVO', name: 'Natuur en Techniek'
36
+ insert :level_name => 'HAVO', :name => 'Economie en Maatschappij'
37
+ insert :level_name => 'HAVO', :name => 'Cultuur en Maatschappij'
38
+ insert :level_name => 'HAVO', :name => 'Natuur en Gezondheid'
39
+ insert :level_name => 'HAVO', :name => 'Natuur en Techniek'
40
40
 
41
- insert level_name: 'VWO', name: 'Economie en Maatschappij'
42
- insert level_name: 'VWO', name: 'Cultuur en Maatschappij'
43
- insert level_name: 'VWO', name: 'Natuur en Gezondheid'
44
- insert level_name: 'VWO', name: 'Natuur en Techniek'
41
+ insert :level_name => 'VWO', :name => 'Economie en Maatschappij'
42
+ insert :level_name => 'VWO', :name => 'Cultuur en Maatschappij'
43
+ insert :level_name => 'VWO', :name => 'Natuur en Gezondheid'
44
+ insert :level_name => 'VWO', :name => 'Natuur en Techniek'
45
45
  end
46
46
 
47
47
  class Course < ActiveRecord::Base
@@ -52,7 +52,7 @@ end
52
52
 
53
53
  Level.all.each do |level|
54
54
  for course_name in %w( Nederlands Engels Duits )
55
- Course.create!(level_name: level.name, name: "#{level.name}/#{course_name}")
55
+ Course.create!(:level_name => level.name, :name => "#{level.name}/#{course_name}")
56
56
  end
57
57
  end
58
58
 
@@ -66,7 +66,7 @@ describe 'A level object' do
66
66
  end
67
67
 
68
68
  describe 'profiles method' do
69
- it 'should return an enumerable object with the correct size' do
69
+ it 'returns an enumerable object with the correct size' do
70
70
  profiles = @level.profiles
71
71
  profiles.must_respond_to(:each)
72
72
  profiles.class.ancestors.must_include(Enumerable)
@@ -75,7 +75,7 @@ describe 'A level object' do
75
75
  end
76
76
 
77
77
  describe 'courses method' do
78
- it 'should return an enumerable object with the correct size' do
78
+ it 'returns an enumerable object with the correct size' do
79
79
  courses = @level.courses
80
80
  courses.must_respond_to(:each)
81
81
  courses.class.ancestors.must_include(Enumerable)
@@ -90,7 +90,7 @@ describe 'A profile object' do
90
90
  end
91
91
 
92
92
  describe 'level method' do
93
- it 'should return the correct level object' do
93
+ it 'returns the correct level object' do
94
94
  @profile.level.must_be_kind_of(Level)
95
95
  @profile.level.name.must_equal('HAVO')
96
96
  end
@@ -103,7 +103,7 @@ describe 'A course object' do
103
103
  end
104
104
 
105
105
  describe 'level method' do
106
- it 'should return the correct level object' do
106
+ it 'returns the correct level object' do
107
107
  @course.level.must_be_kind_of(Level)
108
108
  @course.level.name.must_equal('VWO')
109
109
  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.4.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-09 00:00:00.000000000Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 10.0.3
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 10.0.3
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: activesupport
16
- requirement: &508110 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
19
35
  - - ! '>='
@@ -21,10 +37,15 @@ dependencies:
21
37
  version: 3.0.3
22
38
  type: :development
23
39
  prerelease: false
24
- version_requirements: *508110
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.3
25
46
  - !ruby/object:Gem::Dependency
26
47
  name: activerecord
27
- requirement: &487740 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,7 +53,28 @@ dependencies:
32
53
  version: 3.0.3
33
54
  type: :development
34
55
  prerelease: false
35
- version_requirements: *487740
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.6
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.6
36
78
  description: A little library for defining little models
37
79
  email:
38
80
  - mail@timcraft.com
@@ -69,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
111
  version: '0'
70
112
  requirements: []
71
113
  rubyforge_project:
72
- rubygems_version: 1.8.10
114
+ rubygems_version: 1.8.24
73
115
  signing_key:
74
116
  specification_version: 3
75
117
  summary: See description