csv_record 1.9.0 → 2.0.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.
@@ -1,116 +1,102 @@
1
1
  require_relative '../test_helper'
2
2
 
3
- require_relative '../models/car'
4
-
5
3
  describe CsvRecord::Writer do
6
4
  describe 'initializing class methods' do
7
5
  it 'responds to create' do
8
- Car.must_respond_to :create
6
+ Jedi.must_respond_to :create
9
7
  end
10
8
  end
11
9
 
12
10
  describe 'initializing instance methods' do
13
- it ('responds to save') { car.must_respond_to :save }
14
- it ('responds to new_record?') { car.must_respond_to :new_record? }
15
- it ('responds to calculate_id') { car.must_respond_to :calculate_id }
16
- it ('responds to write_object') { car.must_respond_to :write_object }
17
- it ('responds to id') { car.must_respond_to :id }
18
- it ('responds to update_attribute') { car.must_respond_to :update_attribute }
19
- it ('responds to update_attributes') { car.must_respond_to :update_attributes }
20
- it ('responds to destroy') { car.must_respond_to :destroy }
11
+ it ('responds to save') { luke.must_respond_to :save }
12
+ it ('responds to new_record?') { luke.must_respond_to :new_record? }
13
+ it ('responds to calculate_id') { luke.must_respond_to :calculate_id }
14
+ it ('responds to write_object') { luke.must_respond_to :write_object }
15
+ it ('responds to id') { luke.must_respond_to :id }
16
+ it ('responds to update_attribute') { luke.must_respond_to :update_attribute }
17
+ it ('responds to update_attributes') { luke.must_respond_to :update_attributes }
18
+ it ('responds to destroy') { luke.must_respond_to :destroy }
21
19
  end
22
20
 
23
21
  describe 'validating the methods behavior' do
24
- let(:second_car) do
25
- Car.build(
26
- year: 2007,
27
- make: 'Chevrolet',
28
- model: 'F450',
29
- description: 'ac, abs, moon',
30
- price: 5000.00
31
- )
32
- end
33
-
34
22
  describe 'create' do
35
23
  it "Creates more than one registry" do
36
- car.save
37
- second_car.save
38
- Car.all.size.must_equal 2
24
+ luke.save
25
+ yoda.save
26
+ Jedi.all.size.must_equal 2
39
27
  end
40
28
 
41
29
  it "Creates the object through create method" do
42
- created_car = Car.create(
43
- year: 2007,
44
- make: 'Chevrolet',
45
- model: 'F450',
46
- description: 'ac, abs, moon',
47
- price: 5000.00
30
+ created_jedi = Jedi.create(
31
+ name: 'Luke Skywalker',
32
+ age: 18,
33
+ midi_chlorians: '12k'
48
34
  )
49
- created_car.wont_be_nil
50
- created_car.must_be_instance_of Car
51
- created_car.new_record?.must_equal false
35
+ created_jedi.wont_be_nil
36
+ created_jedi.must_be_instance_of Jedi
37
+ created_jedi.new_record?.must_equal false
52
38
  end
53
39
 
54
40
  it "Sets the ID of the created object" do
55
- car.id.must_be_nil
56
- car.save
57
- car.id.must_equal 1
58
- second_car.save
59
- second_car.id.must_equal 2
41
+ luke.id.must_be_nil
42
+ luke.save
43
+ luke.id.must_equal 1
44
+ yoda.save
45
+ yoda.id.must_equal 2
60
46
  end
61
47
  end
62
48
 
63
49
  describe 'new_record' do
64
50
  it "Checks whether is a new record" do
65
- car.new_record?.must_equal true
66
- car.save
67
- car.new_record?.must_equal false
51
+ luke.new_record?.must_equal true
52
+ luke.save
53
+ luke.new_record?.must_equal false
68
54
  end
69
55
 
70
56
  it "Checks whether a previously saved record is a new record" do
71
- car.save
72
- Car.find(car).new_record?.must_equal false
57
+ luke.save
58
+ Jedi.find(luke).new_record?.must_equal false
73
59
  end
74
60
  end
75
61
 
76
62
  describe 'updates' do
77
63
  it "Updates a single field" do
78
- car.save
79
- car.update_attribute :year, 2008
80
- Car.find(car).year.must_equal '2008'
64
+ luke.save
65
+ luke.update_attribute :age, 24
66
+ Jedi.find(luke).age.must_equal '24'
81
67
  end
82
68
 
83
69
  it "Updates multiple fields at the same time" do
84
- car.save
85
- car.update_attributes year: 2008, model: 'E846'
86
- Car.find(car).year.must_equal '2008'
87
- Car.find(car).model.must_equal 'E846'
70
+ luke.save
71
+ luke.update_attributes name: 'lukas', midi_chlorians: '99999k'
72
+ Jedi.find(luke).name.must_equal 'lukas'
73
+ Jedi.find(luke).midi_chlorians.must_equal '99999k'
88
74
  end
89
75
 
90
76
  it "Updates multiple fields using save" do
91
- car.save
92
- car.year = 2008
93
- car.model = 'E846'
94
- car.save
95
- retrieved_car = Car.find(car)
96
- retrieved_car.year.must_equal '2008'
97
- retrieved_car.model.must_equal 'E846'
77
+ luke.save
78
+ luke.name = 'lukas'
79
+ luke.age = 24
80
+ luke.save
81
+ retrieved_jedi = Jedi.find(luke)
82
+ retrieved_jedi.name.must_equal 'lukas'
83
+ retrieved_jedi.age.must_equal '24'
98
84
  end
99
85
  end
100
86
 
101
87
  describe 'destroy' do
102
88
  it 'remove the object from the database' do
103
- car.save
104
- car.destroy
105
- Car.count.must_equal 0
89
+ luke.save
90
+ luke.destroy
91
+ Jedi.count.must_equal 0
106
92
  end
107
93
 
108
94
  it 'by destroying the object its timestamps and id should be empty' do
109
- car.save
110
- car.destroy
111
- car.id.must_be_nil
112
- car.created_at.must_be_nil
113
- car.updated_at.must_be_nil
95
+ luke.save
96
+ luke.destroy
97
+ luke.id.must_be_nil
98
+ luke.created_at.must_be_nil
99
+ luke.updated_at.must_be_nil
114
100
  end
115
101
  end
116
102
  end
data/test/models/jedi.rb CHANGED
@@ -18,7 +18,7 @@ class Jedi
18
18
  end
19
19
  end
20
20
 
21
- private
21
+ private
22
22
  def my_custom_validator_method
23
23
  @custom_validator_checker = true
24
24
  end
@@ -28,5 +28,4 @@ class Jedi
28
28
  def my_after_save_method
29
29
  @after_save_value = true
30
30
  end
31
-
32
31
  end
data/test/test_helper.rb CHANGED
@@ -16,16 +16,6 @@ class MiniTest::Spec
16
16
  FileUtils.rm_rf 'db'
17
17
  end
18
18
 
19
- let(:car) do
20
- Car.build(
21
- year: 1997,
22
- make: 'Ford',
23
- model: 'E350',
24
- description: 'ac, abs, moon',
25
- price: 3000.00
26
- )
27
- end
28
-
29
19
  let(:jedi_council) { JediOrder.build rank: 'council' }
30
20
  let(:luke) do
31
21
  Jedi.build(
@@ -50,7 +40,7 @@ class MiniTest::Spec
50
40
  end
51
41
  let(:obi_wan_kenobi_padawan) do
52
42
  Padawan.build(
53
- name: 'Qui-Gon Jinn',
43
+ name: 'Obi Wan Kenobi',
54
44
  age: 22,
55
45
  midi_chlorians: '4k'
56
46
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: minitest
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  description: CSV Object-relational mapping for Ruby
95
111
  email:
96
112
  - lukasalexandre@gmail.com
@@ -107,27 +123,32 @@ files:
107
123
  - csv_record.gemspec
108
124
  - lib/csv_record.rb
109
125
  - lib/csv_record/associations.rb
126
+ - lib/csv_record/callback.rb
110
127
  - lib/csv_record/callbacks.rb
111
128
  - lib/csv_record/connector.rb
129
+ - lib/csv_record/csv_queries/condition.rb
130
+ - lib/csv_record/csv_queries/query.rb
131
+ - lib/csv_record/csv_validations/custom_validation.rb
132
+ - lib/csv_record/csv_validations/presence_validation.rb
133
+ - lib/csv_record/csv_validations/uniqueness_validation.rb
134
+ - lib/csv_record/csv_validations/validations.rb
112
135
  - lib/csv_record/document.rb
113
136
  - lib/csv_record/helpers.rb
114
137
  - lib/csv_record/reader.rb
115
138
  - lib/csv_record/timestamps.rb
116
- - lib/csv_record/validations.rb
117
139
  - lib/csv_record/version.rb
118
140
  - lib/csv_record/writer.rb
119
141
  - test/csv_record/associations_test.rb
120
142
  - test/csv_record/callbacks_test.rb
143
+ - test/csv_record/condition_test.rb
121
144
  - test/csv_record/connector_test.rb
122
- - test/csv_record/csv_record_test.rb
123
- - test/csv_record/document_test.rb
124
145
  - test/csv_record/helpers_test.rb
146
+ - test/csv_record/query_test.rb
125
147
  - test/csv_record/reader_test.rb
126
148
  - test/csv_record/timestamps_test.rb
127
149
  - test/csv_record/validation_test.rb
128
150
  - test/csv_record/writer_test.rb
129
151
  - test/models/callback_test_class.rb
130
- - test/models/car.rb
131
152
  - test/models/custom_errors_class.rb
132
153
  - test/models/jedi.rb
133
154
  - test/models/jedi_order.rb
@@ -155,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
176
  version: '0'
156
177
  requirements: []
157
178
  rubyforge_project:
158
- rubygems_version: 1.8.24
179
+ rubygems_version: 1.8.25
159
180
  signing_key:
160
181
  specification_version: 3
161
182
  summary: CSV Record connects Ruby classes to CSV documents database to establish an
@@ -163,16 +184,15 @@ summary: CSV Record connects Ruby classes to CSV documents database to establish
163
184
  test_files:
164
185
  - test/csv_record/associations_test.rb
165
186
  - test/csv_record/callbacks_test.rb
187
+ - test/csv_record/condition_test.rb
166
188
  - test/csv_record/connector_test.rb
167
- - test/csv_record/csv_record_test.rb
168
- - test/csv_record/document_test.rb
169
189
  - test/csv_record/helpers_test.rb
190
+ - test/csv_record/query_test.rb
170
191
  - test/csv_record/reader_test.rb
171
192
  - test/csv_record/timestamps_test.rb
172
193
  - test/csv_record/validation_test.rb
173
194
  - test/csv_record/writer_test.rb
174
195
  - test/models/callback_test_class.rb
175
- - test/models/car.rb
176
196
  - test/models/custom_errors_class.rb
177
197
  - test/models/jedi.rb
178
198
  - test/models/jedi_order.rb
@@ -1,83 +0,0 @@
1
- module CsvRecord
2
- module Validations
3
- module ClassMethods
4
- [:presence, :uniqueness].each do |kind|
5
- define_method "fields_to_validate_#{kind}" do
6
- eval "@fields_to_validate_#{kind} || []"
7
- end
8
-
9
- define_method "__validates_#{kind}_of__" do |*attr_names|
10
- eval "@fields_to_validate_#{kind} = attr_names"
11
- end
12
-
13
- eval "alias :validates_#{kind}_of :__validates_#{kind}_of__"
14
- end
15
-
16
- def custom_validators
17
- @custom_validators ||= []
18
- end
19
-
20
- def validate(*args, &block)
21
- @custom_validators ||= []
22
- @custom_validators += args
23
- @custom_validators << block if block_given?
24
- end
25
- end
26
-
27
- module InstanceMethods
28
- def __valid__?
29
- trigger_presence_validations
30
- trigger_uniqueness_validations
31
- trigger_custom_validations
32
- errors.empty?
33
- end
34
-
35
- def invalid?
36
- not self.__valid__?
37
- end
38
-
39
- def errors
40
- unless @errors
41
- @errors = []
42
- def @errors.add(attribute)
43
- self << attribute
44
- end
45
- end
46
-
47
- @errors
48
- end
49
-
50
- alias :valid? :__valid__?
51
-
52
- private
53
- def trigger_presence_validations
54
- self.class.fields_to_validate_presence.each do |attribute|
55
- if self.public_send(attribute).nil?
56
- self.errors.add attribute
57
- end
58
- end
59
- end
60
-
61
- def trigger_uniqueness_validations
62
- self.class.fields_to_validate_uniqueness.each do |attribute|
63
- condition = {}
64
- condition[attribute] = self.public_send attribute
65
- records = self.class.__where__ condition
66
- if records.any? { |record| record != self }
67
- self.errors.add attribute
68
- end
69
- end
70
- end
71
-
72
- def trigger_custom_validations
73
- self.class.custom_validators.each do |validator|
74
- if not validator.is_a? Proc
75
- self.send validator
76
- else
77
- self.instance_eval &validator
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,8 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- require 'csv_record'
4
-
5
- require_relative '../models/car'
6
-
7
- describe CsvRecord do
8
- end
@@ -1,6 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- require_relative '../models/car'
4
-
5
- describe CsvRecord::Document do
6
- end
data/test/models/car.rb DELETED
@@ -1,11 +0,0 @@
1
- class Car
2
- include CsvRecord::Document
3
-
4
- def initialize(params={})
5
- params.each do |key, value|
6
- self.public_send("#{key}=", value)
7
- end
8
- end
9
-
10
- attr_accessor :year, :make, :model, :description, :price
11
- end