active_mocker 1.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +61 -25
  4. data/Rakefile +1 -1
  5. data/active_mocker.gemspec +3 -3
  6. data/lib/active_hash/init.rb +13 -22
  7. data/lib/active_mocker.rb +1 -0
  8. data/lib/active_mocker/active_record/unknown_class_method.rb +1 -1
  9. data/lib/active_mocker/active_record/unknown_module.rb +3 -3
  10. data/lib/active_mocker/collection_association.rb +19 -20
  11. data/lib/active_mocker/config.rb +7 -4
  12. data/lib/active_mocker/field.rb +4 -4
  13. data/lib/active_mocker/generate.rb +75 -18
  14. data/lib/active_mocker/logger.rb +10 -1
  15. data/lib/active_mocker/mock_class_methods.rb +12 -2
  16. data/lib/active_mocker/mock_instance_methods.rb +3 -2
  17. data/lib/active_mocker/mock_requires.rb +2 -1
  18. data/lib/active_mocker/mock_template.erb +25 -22
  19. data/lib/active_mocker/public_methods.rb +6 -2
  20. data/lib/active_mocker/version.rb +1 -1
  21. data/sample_app_rails_4/app/models/micropost.rb +0 -2
  22. data/sample_app_rails_4/bin/rspec +16 -0
  23. data/sample_app_rails_4/config/application.rb +0 -3
  24. data/sample_app_rails_4/config/database.yml +5 -6
  25. data/sample_app_rails_4/config/environments/development.rb +0 -2
  26. data/sample_app_rails_4/config/environments/test.rb +0 -1
  27. data/sample_app_rails_4/config/initializers/active_mocker.rb +7 -5
  28. data/sample_app_rails_4/db/migrate/20130311191400_create_users.rb +1 -1
  29. data/sample_app_rails_4/db/migrate/20130315015932_add_admin_to_users.rb +1 -1
  30. data/sample_app_rails_4/db/schema.rb +4 -3
  31. data/sample_app_rails_4/lib/tasks/{mocks.rake → active_mocker.rake} +5 -5
  32. data/sample_app_rails_4/lib/unit_logger.rb +22 -0
  33. data/sample_app_rails_4/spec/compare_mocker_and_record_spec.rb +110 -4
  34. data/sample_app_rails_4/spec/mocks/micropost_mock.rb +31 -27
  35. data/sample_app_rails_4/spec/mocks/relationship_mock.rb +29 -24
  36. data/sample_app_rails_4/spec/mocks/user_mock.rb +69 -58
  37. data/sample_app_rails_4/spec/spec_helper.rb +6 -7
  38. data/sample_app_rails_4/spec/user_mock_spec.rb +14 -7
  39. data/spec/lib/active_mocker/collection_association_spec.rb +17 -3
  40. data/spec/lib/active_mocker/generate_spec.rb +8 -6
  41. data/spec/lib/active_mocker/model_reader_spec.rb +5 -0
  42. data/spec/lib/active_mocker/schema_reader_spec.rb +1 -1
  43. data/spec/lib/readme_spec.rb +199 -205
  44. data/spec/unit_logger.rb +24 -0
  45. metadata +22 -32
  46. data/mocks/micropost_mock.rb +0 -108
  47. data/mocks/relationship_mock.rb +0 -109
  48. data/mocks/user_mock.rb +0 -199
  49. data/plan_mock.rb +0 -2323
  50. data/sample_app_rails_4/config/cucumber.yml +0 -8
  51. data/sample_app_rails_4/db/development.sqlite3 +0 -0
  52. data/sample_app_rails_4/db/test.sqlite3 +0 -0
  53. data/spec/lib/active_mocker/performance/base_spec.rb +0 -454
  54. data/spec/lib/active_mocker/performance/large_schema.rb +0 -3576
  55. data/spec/lib/active_mocker/performance/migration/20140327205359_migration.rb +0 -0
  56. data/spec/lib/active_mocker/performance/schema_reader_spec.rb +0 -96
  57. data/spec/lib/compare_mocker_and_record_spec.rb +0 -133
@@ -1,96 +0,0 @@
1
- require 'rspec'
2
- $:.unshift File.expand_path('../../', __FILE__)
3
- require 'string_reader'
4
- require 'file_reader'
5
- require 'active_mocker/table'
6
- require 'active_mocker/field'
7
- require 'active_mocker/active_record/schema'
8
- require 'active_mocker/schema_reader'
9
- require 'active_support/all'
10
-
11
- describe ActiveMocker::SchemaReader, pending: true do
12
-
13
- let(:schema_file){ File.join(File.expand_path('../../', __FILE__), 'performance/large_schema.rb') }
14
-
15
- context 'reads from file' do
16
-
17
- let(:subject){described_class.new({schema_file: schema_file, clear_cache: true})}
18
-
19
- describe '#search' do
20
-
21
- it 'takes a table name and will return its attributes' do
22
- described_class.new({schema_file: schema_file}).search("people")
23
- end
24
-
25
- end
26
-
27
- let(:people_search){subject.search("people")}
28
-
29
- describe '#column_names' do
30
-
31
- it 'returns an array of columns from the schema.rb' do
32
- expect(people_search.name).to eq 'people'
33
- expect(people_search.column_names).to eq ["id", "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"]
34
- end
35
-
36
- end
37
-
38
- describe '#fields' do
39
-
40
- it 'returns all fields from schema' do
41
- expect(people_search.fields[1].to_h).to eq({:name=>"company_id", :type=>:integer, :options=>[]})
42
- end
43
-
44
- end
45
-
46
- describe '#name' do
47
-
48
- it 'returns the name of the table' do
49
- expect(people_search.name).to eq("people")
50
- end
51
-
52
-
53
- end
54
-
55
- describe 'plans table' do
56
-
57
- before(:all) do
58
- # described_class.new({clear_cache: true})
59
- end
60
-
61
- after(:all) do
62
- # described_class.new({clear_cache: true})
63
- end
64
-
65
- let(:subject){described_class.new({schema_file: schema_file, clear_cache: false})}
66
-
67
- it 'find table' do
68
-
69
- 10.times do
70
- # 0.019135
71
- # 8.0e-06
72
- # 3.0e-06
73
- # 6.3e-05
74
- # 3.0e-06
75
- # 2.0e-06
76
- # 3.0e-06
77
- # 3.0e-06
78
- # 2.0e-06
79
- # 2.0e-06
80
- start = Time.now
81
- subject.search("plans").name
82
- # subject.search("disclosures").name
83
- # subject.search("bmg_tpa_masters").name
84
- # subject.search("bmg_rk_masters").name
85
- puts Time.now - start
86
- end
87
-
88
- end
89
-
90
- end
91
-
92
- end
93
-
94
-
95
-
96
- end
@@ -1,133 +0,0 @@
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', pending: true do
7
-
8
- before(:each) do
9
- ActiveMocker::Base.configure do |config|
10
- config.schema_file = project_root + '/lib/active_record/db/schema.rb'
11
- config.model_dir = project_root + '/lib/active_record/app/models'
12
- config.schema_file_reader = nil
13
- config.model_file_reader = nil
14
- config.log_level = Logger::WARN
15
- config.clear_cache = true
16
- config.migration_dir = '/Users/zeisler/dev/active_mocker/spec/lib/active_mocker/performance/migration'
17
- end
18
- ActiveMocker::Base.mock('Person')
19
- end
20
-
21
- after(:each) do
22
- PersonMock.destroy_all
23
- Person.destroy_all
24
- end
25
-
26
- let(:attributes){{name: 'Dustin Zeisler', last_name: 'dustin@example.com'}}
27
-
28
- describe '::superclass' do
29
-
30
- it 'mock has super of active hash' do
31
- expect(PersonMock.superclass.name).to eq "ActiveHash::Base"
32
- end
33
-
34
- it 'ar has super of ar' do
35
- expect(Person.superclass.name).to eq "ActiveRecord::Base"
36
-
37
- end
38
-
39
- end
40
-
41
- describe '::create' do
42
-
43
- let(:create_attributes){attributes}
44
-
45
- it 'mock will take all attributes that AR takes' do
46
-
47
- person = Person.create(create_attributes)
48
- person_mock = PersonMock.create(create_attributes)
49
-
50
- end
51
-
52
- end
53
-
54
- describe '#attributes' do
55
-
56
- let(:person_ar){Person.new(attributes)}
57
- let(:person_mock){PersonMock.new(attributes)}
58
-
59
- it 'they are the same' do
60
- expect(person_mock.attributes).to eq person_ar.attributes
61
- end
62
-
63
- end
64
-
65
- describe 'associations' do
66
-
67
- let(:zip_code){ZipCode.create(zip_code: '97023')}
68
- let(:create_attributes){attributes.merge({zip_code: zip_code})}
69
-
70
- let(:person_ar){Person.new(create_attributes)}
71
- let(:person_mock){PersonMock.new(create_attributes)}
72
-
73
- it 'the Mock when adding an association will not set the _id attribute, do it manually' do
74
- expect(person_mock.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})
75
- expect(person_mock.zip_code).to eq zip_code
76
- end
77
-
78
- it 'Ar will not include associations in attributes' 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"=>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})
80
- end
81
-
82
- end
83
-
84
- describe 'column_names' do
85
-
86
- 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"]}
87
-
88
- it 'they are the same' do
89
- expect(PersonMock.column_names).to eq Person.column_names
90
- end
91
-
92
- end
93
-
94
- describe '::find_by' do
95
-
96
- let!(:ar_record){Person.create(attributes)}
97
- let!(:mock_record){PersonMock.create(attributes)}
98
- let!(:mock_record_2){PersonMock.create(attributes.merge({title: 'Developer'}))}
99
-
100
- it 'AR' do
101
- expect(ar_record).to eq Person.find_by(first_name: 'Dustin', last_name: 'Zeisler')
102
- end
103
-
104
- it 'Mock' do
105
- PersonMock.create(first_name: 'Dustin', last_name: 'Zeisler', title: 'Developer')
106
- expect(PersonMock.create(title: 'Developer', first_name: 'Dustin', last_name: 'Adams')).to eq PersonMock.find_by(title: 'Developer', last_name: 'Adams')
107
- end
108
-
109
- end
110
-
111
- describe '::where' do
112
-
113
- let(:ar_record){Person.create(attributes)}
114
- let(:mock_record){PersonMock.create(attributes)}
115
- let(:mock_record_2){PersonMock.create(attributes.merge(title: 'Developer'))}
116
-
117
- it 'AR' do
118
- expect([ar_record]).to eq Person.where(first_name: 'Dustin', last_name: 'Zeisler')
119
- end
120
-
121
- it 'Mock' do
122
- expect([mock_record]).to eq PersonMock.where(first_name: 'Dustin', last_name: 'Zeisler')
123
- end
124
-
125
- it 'Mock will not take sql string needs to be mocked' do
126
- PersonMock.create(first_name: 'Dustin', last_name: 'Zeisler', title: 'Developer')
127
- expect{PersonMock.where("first_name = 'Dustin'")}.to raise_error
128
- end
129
-
130
- end
131
-
132
-
133
- end