active_mocker 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/active_mocker.gemspec +4 -2
- data/lib/active_hash/find_by.rb +1 -1
- data/lib/active_mocker/version.rb +1 -1
- data/lib/active_record/app/models/person.rb +3 -0
- data/lib/active_record/app/models/zip_code.rb +2 -0
- data/lib/active_record/ar.rb +10 -0
- data/lib/active_record/db/schema.rb +38 -0
- data/spec/lib/compare_mocker_and_record_spec.rb +167 -0
- metadata +64 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d68198a21ac2738734c94c5565127480b8772d8
|
4
|
+
data.tar.gz: 55577fbc878b514b20b2c6a4ed8169e273fd610d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d812eeae5501c118b19293b99f405bcdf6683c692b4a6aadebda619d5a9d0eaf13351db8787058f1a84ff5b0da46aa78077ca18e0d9238f9a8aaa8d71f14d2
|
7
|
+
data.tar.gz: cebef904a1a20c104b27bf005ea1bd263354bd4215536da28930fb6c3fee6a202ced8354350b511242d93159ddcce0cfe737526d961e28c242c2f6dab7350f97
|
data/active_mocker.gemspec
CHANGED
@@ -27,10 +27,12 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", "~>10.1"
|
28
28
|
spec.add_development_dependency "rspec", "~>2.14"
|
29
29
|
spec.add_development_dependency "i18n", "~>0.6"
|
30
|
+
spec.add_development_dependency "activerecord", "~>4.0"
|
31
|
+
spec.add_development_dependency "sqlite3", "~>1.3"
|
30
32
|
|
31
|
-
if ENV['DEBUG'] == '1'
|
33
|
+
# if ENV['DEBUG'] == '1'
|
32
34
|
spec.add_development_dependency "debase", "~>0.0"
|
33
35
|
spec.add_development_dependency "ruby-debug-ide", "~>0.4"
|
34
|
-
end
|
36
|
+
# end
|
35
37
|
|
36
38
|
end
|
data/lib/active_hash/find_by.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection({
|
5
|
+
:adapter => "sqlite3",
|
6
|
+
database: ":memory:"
|
7
|
+
})
|
8
|
+
require_relative 'db/schema'
|
9
|
+
project_root = File.dirname(File.absolute_path(__FILE__))
|
10
|
+
Dir.glob(project_root + "/app/models/*.rb").each{|f| require f }
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ActiveRecord::Schema.define(version: 20140327205359) do
|
2
|
+
|
3
|
+
create_table "people", force: true do |t|
|
4
|
+
t.integer "company_id"
|
5
|
+
t.string "first_name", limit: 128
|
6
|
+
t.string "middle_name", limit: 128
|
7
|
+
t.string "last_name", limit: 128
|
8
|
+
t.string "address_1", limit: 200
|
9
|
+
t.string "address_2", limit: 100
|
10
|
+
t.string "city", limit: 100
|
11
|
+
t.integer "state_id"
|
12
|
+
t.integer "zip_code_id"
|
13
|
+
t.string "title", limit: 150
|
14
|
+
t.string "department", limit: 150
|
15
|
+
t.string "person_email", limit: 150
|
16
|
+
t.string "work_phone", limit: 20
|
17
|
+
t.string "cell_phone", limit: 20
|
18
|
+
t.string "home_phone", limit: 20
|
19
|
+
t.string "fax", limit: 20
|
20
|
+
t.integer "user_id_assistant"
|
21
|
+
t.date "birth_date"
|
22
|
+
t.boolean "needs_review"
|
23
|
+
t.datetime "created_at"
|
24
|
+
t.datetime "updated_at"
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table "zip_codes", force: true do |t|
|
29
|
+
t.string "zip_code", limit: 9
|
30
|
+
t.integer "state_id"
|
31
|
+
t.integer "cola_by_fip_id"
|
32
|
+
t.string "city_name", limit: 100
|
33
|
+
t.string "County_name", limit: 100
|
34
|
+
t.decimal "City_Latitude", precision: 8, scale: 4
|
35
|
+
t.decimal "City_Longitude", precision: 8, scale: 4
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
project_root = File.expand_path('../../../', __FILE__)
|
3
|
+
require "#{project_root}/lib/active_record/ar"
|
4
|
+
require "#{project_root}/lib/active_mocker"
|
5
|
+
|
6
|
+
describe 'Comparing ActiveMocker Api to ActiveRecord Api' do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
ActiveMocker::Base.configure do |config|
|
10
|
+
# Required Options
|
11
|
+
config.schema_file = project_root + '/lib/active_record/db/schema.rb'
|
12
|
+
config.model_dir = project_root + '/lib/active_record/app/models'
|
13
|
+
# Additional Options
|
14
|
+
# Dependency injection
|
15
|
+
config.schema_file_reader = nil
|
16
|
+
config.model_file_reader = nil
|
17
|
+
config.active_hash_as_base = true #default
|
18
|
+
#config.schema_attributes = true #default
|
19
|
+
#config.model_relationships = true #default
|
20
|
+
#config.model_methods = true #default
|
21
|
+
#config.mass_assignment = true #default
|
22
|
+
# Logging
|
23
|
+
config.log_level = Logger::WARN #default
|
24
|
+
end
|
25
|
+
ActiveMocker::Base.mock('Person')
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
PersonMock.destroy_all
|
30
|
+
Person.destroy_all
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:attributes){{first_name: 'Dustin', last_name: 'Zeisler'}}
|
34
|
+
|
35
|
+
describe '::superclass' do
|
36
|
+
|
37
|
+
it 'mock has super of active hash' do
|
38
|
+
expect(PersonMock.superclass.name).to eq "ActiveHash::Base"
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'ar has super of ar' do
|
42
|
+
expect(Person.superclass.name).to eq "ActiveRecord::Base"
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '::create' do
|
49
|
+
|
50
|
+
let(:create_attributes){attributes}
|
51
|
+
|
52
|
+
it 'mock will take all attributes that AR takes' do
|
53
|
+
|
54
|
+
person = Person.create(create_attributes)
|
55
|
+
person_mock = PersonMock.create(create_attributes)
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#attributes' do
|
62
|
+
|
63
|
+
let(:person_ar){Person.new(attributes)}
|
64
|
+
let(:person_mock){PersonMock.new(attributes)}
|
65
|
+
|
66
|
+
# DO NOT depend on the fact that attributes to be the same as AR
|
67
|
+
# Work Around: seed all unused values with nil
|
68
|
+
# Implementation Fix: On init give all values nil
|
69
|
+
|
70
|
+
it 'the mock will exclude any attributes with nil and have a symbol and string version' do
|
71
|
+
expect(person_mock.attributes).to eq({:first_name=>"Dustin", :last_name=>"Zeisler", "first_name"=>"Dustin", "last_name"=>"Zeisler"})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can still ask for attribute that is nil on mock' do
|
75
|
+
expect(person_mock[:middle_name]).to eq(nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'ar will include values with nil' do
|
79
|
+
expect(person_ar.attributes).to eq({"id"=>nil, "company_id"=>nil, "first_name"=>"Dustin", "middle_name"=>nil, "last_name"=>"Zeisler", "address_1"=>nil, "address_2"=>nil, "city"=>nil, "state_id"=>nil, "zip_code_id"=>nil, "title"=>nil, "department"=>nil, "person_email"=>nil, "work_phone"=>nil, "cell_phone"=>nil, "home_phone"=>nil, "fax"=>nil, "user_id_assistant"=>nil, "birth_date"=>nil, "needs_review"=>nil, "created_at"=>nil, "updated_at"=>nil})
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'compare access to attribute' do
|
83
|
+
expect(person_mock.first_name).to eq person_ar.first_name
|
84
|
+
expect(person_mock[:first_name]).to eq person_ar.first_name
|
85
|
+
expect(person_mock['first_name']).to eq person_ar.first_name
|
86
|
+
expect(person_ar[:first_name]).to eq person_mock.first_name
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'associations' do
|
93
|
+
|
94
|
+
let(:zip_code){ZipCode.create(zip_code: '97023')}
|
95
|
+
let(:create_attributes){attributes.merge({zip_code: zip_code})}
|
96
|
+
|
97
|
+
let(:person_ar){Person.new(create_attributes)}
|
98
|
+
let(:person_mock){PersonMock.new(create_attributes)}
|
99
|
+
|
100
|
+
# DO NOT Depend on this or your code will break in production
|
101
|
+
# Work Around: To access associations call method
|
102
|
+
# Implementation Fix: remove association from fields and make getter and setter method
|
103
|
+
|
104
|
+
it 'The Mock will include associations in attributes' do
|
105
|
+
expect(person_mock.attributes).to eq({:first_name=>"Dustin", :last_name=>"Zeisler", zip_code: zip_code, "first_name"=>"Dustin", "last_name"=>"Zeisler"})
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'Ar will not include associations in attributes' do
|
109
|
+
expect(person_ar.attributes).to eq({"id"=>nil, "company_id"=>nil, "first_name"=>"Dustin", "middle_name"=>nil, "last_name"=>"Zeisler", "address_1"=>nil, "address_2"=>nil, "city"=>nil, "state_id"=>nil, "zip_code_id"=>2, "title"=>nil, "department"=>nil, "person_email"=>nil, "work_phone"=>nil, "cell_phone"=>nil, "home_phone"=>nil, "fax"=>nil, "user_id_assistant"=>nil, "birth_date"=>nil, "needs_review"=>nil, "created_at"=>nil, "updated_at"=>nil})
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'column_names' do
|
115
|
+
|
116
|
+
let(:column_names){["company_id", "first_name", "middle_name", "last_name", "address_1", "address_2", "city", "state_id", "zip_code_id", "title", "department", "person_email", "work_phone", "cell_phone", "home_phone", "fax", "user_id_assistant", "birth_date", "needs_review", "created_at", "updated_at"]}
|
117
|
+
|
118
|
+
it 'mock does not include id column' do
|
119
|
+
expect(PersonMock.column_names).to eq column_names
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'AR does include id column' do
|
123
|
+
expect(Person.column_names).to eq column_names.unshift('id')
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '::find_by' do
|
129
|
+
|
130
|
+
let!(:ar_record){Person.create(attributes)}
|
131
|
+
let!(:mock_record){PersonMock.create(attributes)}
|
132
|
+
let!(:mock_record_2){PersonMock.create(attributes.merge({title: 'Developer'}))}
|
133
|
+
|
134
|
+
it 'AR' do
|
135
|
+
expect(ar_record).to eq Person.find_by(first_name: 'Dustin', last_name: 'Zeisler')
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'Mock' do
|
139
|
+
PersonMock.create(first_name: 'Dustin', last_name: 'Zeisler', title: 'Developer')
|
140
|
+
expect(PersonMock.create(title: 'Developer', first_name: 'Dustin', last_name: 'Adams')).to eq PersonMock.find_by(title: 'Developer', last_name: 'Adams')
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '::where' do
|
146
|
+
|
147
|
+
let(:ar_record){Person.create(attributes)}
|
148
|
+
let(:mock_record){PersonMock.create(attributes)}
|
149
|
+
let(:mock_record_2){PersonMock.create(attributes.merge(title: 'Developer'))}
|
150
|
+
|
151
|
+
it 'AR' do
|
152
|
+
expect([ar_record]).to eq Person.where(first_name: 'Dustin', last_name: 'Zeisler')
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'Mock' do
|
156
|
+
expect([mock_record]).to eq PersonMock.where(first_name: 'Dustin', last_name: 'Zeisler')
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'Mock will not take sql string needs to be mocked' do
|
160
|
+
PersonMock.create(first_name: 'Dustin', last_name: 'Zeisler', title: 'Developer')
|
161
|
+
expect{PersonMock.where("first_name = 'Dustin'")}.to raise_error
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_mocker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,6 +94,62 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: debase
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: ruby-debug-ide
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.4'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.4'
|
97
153
|
description: Create mocks from active record models without loading rails or running
|
98
154
|
a database. The Mock's methods have the same arguments as the AR model and if they
|
99
155
|
change you get a error in your test.
|
@@ -132,12 +188,17 @@ files:
|
|
132
188
|
- lib/active_mocker/schema_reader.rb
|
133
189
|
- lib/active_mocker/table.rb
|
134
190
|
- lib/active_mocker/version.rb
|
191
|
+
- lib/active_record/app/models/person.rb
|
192
|
+
- lib/active_record/app/models/zip_code.rb
|
193
|
+
- lib/active_record/ar.rb
|
194
|
+
- lib/active_record/db/schema.rb
|
135
195
|
- lib/file_reader.rb
|
136
196
|
- lib/string_reader.rb
|
137
197
|
- spec/lib/active_mocker/active_record/schema_spec.rb
|
138
198
|
- spec/lib/active_mocker/base_spec.rb
|
139
199
|
- spec/lib/active_mocker/model_reader_spec.rb
|
140
200
|
- spec/lib/active_mocker/schema_reader_spec.rb
|
201
|
+
- spec/lib/compare_mocker_and_record_spec.rb
|
141
202
|
- spec/lib/model.rb
|
142
203
|
- spec/lib/person.rb
|
143
204
|
- spec/lib/schema.rb
|
@@ -171,6 +232,7 @@ test_files:
|
|
171
232
|
- spec/lib/active_mocker/base_spec.rb
|
172
233
|
- spec/lib/active_mocker/model_reader_spec.rb
|
173
234
|
- spec/lib/active_mocker/schema_reader_spec.rb
|
235
|
+
- spec/lib/compare_mocker_and_record_spec.rb
|
174
236
|
- spec/lib/model.rb
|
175
237
|
- spec/lib/person.rb
|
176
238
|
- spec/lib/schema.rb
|