best_boy 1.3.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.
- data/README.md +36 -3
- data/Rakefile +45 -7
- data/app/controllers/best_boy/best_boy_events_controller.rb +147 -98
- data/app/helpers/best_boy/best_boy_view_helper.rb +9 -0
- data/app/views/best_boy/best_boy_events/details.html.erb +33 -27
- data/app/views/best_boy/best_boy_events/monthly_details.html.erb +9 -9
- data/app/views/best_boy/best_boy_events/stats.html.erb +20 -19
- data/lib/best_boy/engine.rb +2 -0
- data/lib/best_boy/models/active_record/best_boy/eventable.rb +19 -0
- data/lib/best_boy/models/active_record/best_boy_day_report.rb +65 -0
- data/lib/best_boy/models/active_record/best_boy_event.rb +1 -11
- data/lib/best_boy/models/active_record/best_boy_month_report.rb +63 -0
- data/lib/best_boy/version.rb +1 -1
- data/lib/generators/active_record/best_boy_generator.rb +4 -1
- data/lib/generators/active_record/templates/create_best_boy_reports.rb +30 -0
- data/lib/tasks/recover_report_history.rake +146 -0
- data/spec/{best_boy → controllers}/best_boy_controller_spec.rb +6 -4
- data/spec/dummy/app/views/test_events/index.html.haml +9 -1
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/db/migrate/20131108085915_create_best_boy_reports.rb +30 -0
- data/spec/dummy/db/schema.rb +27 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +10092 -0
- data/spec/dummy/log/test.log +531 -0
- data/spec/dummy/tmp/cache/assets/development/sass/f99cb4f6f36f128b2d6950c813eec72c66616bfc/bootstrap.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/01af51e20498d87feb18694bed0d0731 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/057daf732c672b9e0ec8bd233ec79077 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1565c81151c1e0fe577f787a645bca3d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1c90620581903652712500bb92915909 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3241270f308313221453f51980c07883 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a59d6acf2f4543a36d946d653b08dab +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a5f8aba9c98833836df55cdc5502ee8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/42804a4f90448633879c06a33e49f4e6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/48279ff6b6f65f85e766c3a7ae0c71f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/642b8ba757f92502a3a3281a956eec2a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/64fe0e7bbf53d3cf292e85e123137bcb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/77e01a708457c1d4aac9446e173321a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8ac87e607a25fc208fc1da0c60b24b8b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8dab559778ce584628d484b9d919cfa8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8fde9b9595ed926214e7858402849bb2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c9e7400c0b4cf9165368acf909971237 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e58e48ebcd3216893f3b053ee6a3d7eb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e5cfb1a438298274f827c0cbea06e7dc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f14dc22e71f0438b9fc154ec08da7c10 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/models/best_boy_event_spec.rb +20 -0
- data/spec/models/day_report_spec.rb +115 -0
- data/spec/models/eventable_spec.rb +51 -0
- data/spec/models/month_report_spec.rb +113 -0
- data/spec/spec_helper.rb +96 -40
- metadata +110 -123
- data/.gitignore +0 -10
- data/.rspec +0 -1
- data/.travis.yml +0 -3
- data/Gemfile +0 -3
- data/LICENSE.txt +0 -20
- data/best_boy.gemspec +0 -38
- data/db/bestboy.db +0 -0
- data/spec/best_boy/best_boy_event_spec.rb +0 -62
- data/spec/best_boy/eventable_spec.rb +0 -20
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe BestBoyEvent, 'with creating' do
|
|
4
|
+
it "should have valid model" do
|
|
5
|
+
example = TestEvent.create
|
|
6
|
+
best_boy_event = BestBoyEvent.create(:event => "create")
|
|
7
|
+
best_boy_event.owner = example
|
|
8
|
+
best_boy_event.should be_valid
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe BestBoyEvent, 'with associations' do
|
|
13
|
+
it { should belong_to(:owner) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe BestBoyEvent, 'with validations' do
|
|
17
|
+
it "should require a event" do
|
|
18
|
+
BestBoyEvent.create(:event => "").should_not be_valid
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe BestBoy::DayReport do
|
|
4
|
+
|
|
5
|
+
let(:owner) { TestEvent.create }
|
|
6
|
+
let(:month_report) do
|
|
7
|
+
BestBoy::MonthReport.create({
|
|
8
|
+
owner_type: owner.class.to_param,
|
|
9
|
+
event: "create"
|
|
10
|
+
})
|
|
11
|
+
end
|
|
12
|
+
let(:day_report) do
|
|
13
|
+
BestBoy::DayReport.create({
|
|
14
|
+
owner_type: owner.class.to_param,
|
|
15
|
+
event: "create",
|
|
16
|
+
month_report_id: month_report.to_param
|
|
17
|
+
})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
subject { day_report }
|
|
21
|
+
|
|
22
|
+
context "with associations" do
|
|
23
|
+
it { expect(subject).to belong_to(:month_report) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "with validations" do
|
|
27
|
+
it "validates presence of attributes" do
|
|
28
|
+
expect(subject).to validate_presence_of(:month_report_id)
|
|
29
|
+
expect(subject).to validate_presence_of(:owner_type)
|
|
30
|
+
expect(subject).to validate_presence_of(:event)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "with scopes" do
|
|
35
|
+
it "aggregates DayReports of specific day" do
|
|
36
|
+
collection = BestBoy::DayReport.order('created_at DESC')
|
|
37
|
+
expect(collection.created_on(Time.now)).to include(day_report)
|
|
38
|
+
expect(collection.created_on(1.day.ago)).to_not include(day_report)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "aggregates DayReports of last week" do
|
|
42
|
+
Time.zone = "Berlin"
|
|
43
|
+
|
|
44
|
+
report_from_last_week = BestBoy::DayReport.create({owner_type: "TestEvent", event: "create"}).tap { |e| e.created_at = 8.days.ago; e.save }
|
|
45
|
+
report_from_this_week = BestBoy::DayReport.create({owner_type: "TestEvent", event: "create", month_report_id: month_report.id })
|
|
46
|
+
|
|
47
|
+
collection = BestBoy::DayReport.order('created_at DESC')
|
|
48
|
+
expect(collection.week).to include(report_from_this_week)
|
|
49
|
+
expect(collection.week).not_to include(report_from_last_week)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "with class methods" do
|
|
55
|
+
describe "#current_for" do
|
|
56
|
+
context "when day_report exists" do
|
|
57
|
+
Time.zone = "Berlin"
|
|
58
|
+
|
|
59
|
+
existing_report = BestBoy::DayReport.create_for("ExampleClass", "create")
|
|
60
|
+
existing_with_source = BestBoy::DayReport.create_for("ExampleClass", "create", "api")
|
|
61
|
+
|
|
62
|
+
demanded = BestBoy::DayReport.current_for(Time.now, "ExampleClass", "create").last
|
|
63
|
+
demanded_with_source = BestBoy::DayReport.current_for(Time.now, "ExampleClass", "create", "api").last
|
|
64
|
+
|
|
65
|
+
it { expect(demanded).to be_eql existing_report }
|
|
66
|
+
it { expect(demanded_with_source).to be_eql existing_with_source }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "when no today's day_report is present" do
|
|
70
|
+
it "delivers empty ActiceRecord::Relation" do
|
|
71
|
+
expect(BestBoy::DayReport.current_for(Time.now, "GibberishClass", "create")).to be_empty
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#current_or_create_for" do
|
|
78
|
+
context "when day_report exists" do
|
|
79
|
+
Time.zone = "Berlin"
|
|
80
|
+
|
|
81
|
+
owner = TestEvent.create
|
|
82
|
+
existing_report = BestBoy::DayReport.create_for(owner.class.to_s, "create")
|
|
83
|
+
existing_with_source = BestBoy::DayReport.create_for(owner.class.to_s, "create", "api")
|
|
84
|
+
|
|
85
|
+
demanded = BestBoy::DayReport.current_or_create_for(owner.class.to_s, "create")
|
|
86
|
+
demanded_with_source = BestBoy::DayReport.current_or_create_for(owner.class.to_s, "create", "api")
|
|
87
|
+
|
|
88
|
+
it { expect(demanded).to be_eql existing_report }
|
|
89
|
+
it { expect(demanded_with_source).to be_eql existing_with_source }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "when no today's day_report is present" do
|
|
93
|
+
it "creates a new month_report" do
|
|
94
|
+
BestBoy::DayReport.destroy_all
|
|
95
|
+
scope = BestBoy::DayReport.where(owner_type: TestEvent.to_s, event: "create")
|
|
96
|
+
expect{ BestBoy::DayReport.current_or_create_for(owner.class.to_s, "create") }.to change(scope.created_on(Time.now), :count).by(1)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "#create_for" do
|
|
102
|
+
owner = TestEvent.create
|
|
103
|
+
report = BestBoy::DayReport.create_for(owner.class.to_s, "create")
|
|
104
|
+
report_with_source = BestBoy::DayReport.create_for(owner.class.to_s, "create", "api")
|
|
105
|
+
|
|
106
|
+
it { expect(report).to be_valid }
|
|
107
|
+
it { expect(report.owner_type).to be_eql(owner.class.to_s) }
|
|
108
|
+
it { expect(report.event_source).to be_nil }
|
|
109
|
+
|
|
110
|
+
it { expect(report_with_source).to be_valid }
|
|
111
|
+
it { expect(report_with_source.owner_type).to be_eql(owner.class.to_s) }
|
|
112
|
+
it { expect(report_with_source.event_source).to be_eql("api") }
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe BestBoy::Eventable do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@example = TestEvent.create
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should send valid create event" do
|
|
9
|
+
best_boy_event = @example.best_boy_events.first.should_not be_nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should send valid destroy event" do
|
|
13
|
+
@example.destroy
|
|
14
|
+
BestBoyEvent.where(:owner_type => "User", :event => "destroy").should_not be_nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be an eventable" do
|
|
18
|
+
@example.respond_to?("eventable?").should eql(true)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "with reporting" do
|
|
22
|
+
let(:month_report) do
|
|
23
|
+
BestBoy::MonthReport.where(
|
|
24
|
+
owner_type: @example.class,
|
|
25
|
+
event: 'create'
|
|
26
|
+
).first
|
|
27
|
+
end
|
|
28
|
+
let(:day_report) do
|
|
29
|
+
BestBoy::DayReport.where(
|
|
30
|
+
owner_type: @example.class,
|
|
31
|
+
event: 'create'
|
|
32
|
+
).first
|
|
33
|
+
end
|
|
34
|
+
it "loads reports" do
|
|
35
|
+
expect(month_report).to be_present
|
|
36
|
+
expect(day_report).to be_present
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "increases occurrence counter when a new instance is created" do
|
|
40
|
+
BestBoy::MonthReport.any_instance.should_receive(:increment!).and_return(true)
|
|
41
|
+
BestBoy::DayReport.any_instance.should_receive(:increment!).and_return(true)
|
|
42
|
+
TestEvent.create
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "increases occurrence counter when an instance is destroyed" do
|
|
46
|
+
BestBoy::MonthReport.any_instance.should_receive(:increment!).and_return(true)
|
|
47
|
+
BestBoy::DayReport.any_instance.should_receive(:increment!).and_return(true)
|
|
48
|
+
TestEvent.first.destroy
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe BestBoy::MonthReport do
|
|
4
|
+
|
|
5
|
+
let(:owner) { TestEvent.create }
|
|
6
|
+
let(:month_report) do
|
|
7
|
+
BestBoy::MonthReport.create({
|
|
8
|
+
owner_type: owner.class.to_param,
|
|
9
|
+
event: "create"
|
|
10
|
+
})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
subject { month_report }
|
|
14
|
+
|
|
15
|
+
describe "with associations" do
|
|
16
|
+
it { expect(subject).to have_many(:day_reports) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "with validations" do
|
|
20
|
+
it "validates presence of attributes" do
|
|
21
|
+
expect(subject).to validate_presence_of(:owner_type)
|
|
22
|
+
expect(subject).to validate_presence_of(:event)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "with scopes" do
|
|
27
|
+
it "aggregates MonthReports of specific month" do
|
|
28
|
+
collection = BestBoy::MonthReport.order('created_at DESC')
|
|
29
|
+
expect(collection.between(Time.now.beginning_of_month, Time.now)).to include(month_report)
|
|
30
|
+
expect(collection.between(2.month.ago.beginning_of_month, 2.month.ago)).to_not include(month_report)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "aggregates MonthReports of specific month period" do
|
|
34
|
+
report_from_first_month = BestBoy::MonthReport.create({owner_type: "TestEvent", event: "create"}).tap { |e| e.created_at = 2.month.ago; e.save }
|
|
35
|
+
report_from_last_month = BestBoy::MonthReport.create({owner_type: "TestEvent", event: "create"}).tap { |e| e.created_at = 1.month.ago }
|
|
36
|
+
|
|
37
|
+
collection = BestBoy::MonthReport.order('created_at DESC')
|
|
38
|
+
expect(collection.between(3.month.ago, Time.now)).to include(report_from_first_month)
|
|
39
|
+
expect(collection.between(3.month.ago, Time.now)).to include(report_from_last_month)
|
|
40
|
+
expect(collection.between(1.month.ago, Time.now)).to_not include(report_from_first_month)
|
|
41
|
+
expect(collection.between(3.month.ago, 2.month.ago)).to_not include(report_from_last_month)
|
|
42
|
+
expect(collection.between(6.month.ago, 4.month.ago)).to_not include(report_from_last_month)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "aggregates MonthReports of specific day" do
|
|
46
|
+
collection = BestBoy::MonthReport.order('created_at DESC')
|
|
47
|
+
expect(collection.created_on(Time.now)).to include(month_report)
|
|
48
|
+
expect(collection.created_on(1.day.ago)).to_not include(month_report)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "with class methods" do
|
|
53
|
+
describe "#current_for" do
|
|
54
|
+
context "when day_report exists" do
|
|
55
|
+
existing_report = BestBoy::MonthReport.create_for("TestEventClass", "create")
|
|
56
|
+
existing_with_source = BestBoy::MonthReport.create_for("TestEventClass", "create", "api")
|
|
57
|
+
|
|
58
|
+
demanded = BestBoy::MonthReport.current_for(Time.now, "TestEventClass", "create").last
|
|
59
|
+
demanded_with_source = BestBoy::MonthReport.current_for(Time.now, "TestEventClass", "create", "api").last
|
|
60
|
+
|
|
61
|
+
it { expect(demanded).to be_eql existing_report }
|
|
62
|
+
it { expect(demanded_with_source).to be_eql existing_with_source }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "when no today's day_report is present" do
|
|
66
|
+
it "delivers empty ActiceRecord::Relation" do
|
|
67
|
+
expect(BestBoy::MonthReport.current_for(Time.now, "GibberishClass", "create")).to be_empty
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "#current_or_create_for" do
|
|
73
|
+
context "when month_report exists" do
|
|
74
|
+
owner = TestEvent.create
|
|
75
|
+
existing_report = BestBoy::MonthReport.create_for(owner.class, "create")
|
|
76
|
+
existing_with_source = BestBoy::MonthReport.create_for(owner.class, "create", "api")
|
|
77
|
+
|
|
78
|
+
demanded = BestBoy::MonthReport.current_or_create_for(owner.class, "create")
|
|
79
|
+
demanded_with_source = BestBoy::MonthReport.current_or_create_for(owner.class, "create", "api")
|
|
80
|
+
|
|
81
|
+
it { expect(demanded).to eql existing_report }
|
|
82
|
+
it { expect(demanded_with_source).to eql existing_with_source }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when no month_report is present" do
|
|
86
|
+
it "creates a new month_report" do
|
|
87
|
+
BestBoy::MonthReport.destroy_all
|
|
88
|
+
scope = BestBoy::MonthReport.where(owner_type: TestEvent.to_s, event: "create")
|
|
89
|
+
expect(scope.between(Time.now.beginning_of_month, Time.now)).to be_empty
|
|
90
|
+
expect{ BestBoy::MonthReport.current_or_create_for(owner.class, "create") }.to change(scope.between(Time.now.beginning_of_month, Time.now), :count).by(1)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "#create_for" do
|
|
96
|
+
owner = TestEvent.create
|
|
97
|
+
report = BestBoy::MonthReport.create_for(owner.class, "create")
|
|
98
|
+
report_with_source = BestBoy::MonthReport.create_for(owner.class, "create", "api")
|
|
99
|
+
|
|
100
|
+
it { expect(report).to be_valid }
|
|
101
|
+
it { expect(report_with_source).to be_valid }
|
|
102
|
+
|
|
103
|
+
it { expect(report.owner_type).to be_eql(owner.class.to_s) }
|
|
104
|
+
it { expect(report_with_source.owner_type).to be_eql(owner.class.to_s) }
|
|
105
|
+
|
|
106
|
+
it { expect(report.event).to be_eql("create") }
|
|
107
|
+
it { expect(report_with_source.event).to be_eql("create") }
|
|
108
|
+
|
|
109
|
+
it { expect(report.event_source).to be_nil }
|
|
110
|
+
it { expect(report_with_source.event_source).to eql "api" }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,51 +1,107 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'bundler'
|
|
3
|
-
require 'active_record'
|
|
4
|
-
require 'active_support'
|
|
5
|
-
require "best_boy/models/active_record/best_boy_event.rb"
|
|
6
|
-
require "best_boy/models/active_record/best_boy/eventable.rb"
|
|
7
|
-
require "best_boy/
|
|
8
|
-
require
|
|
9
|
-
require
|
|
1
|
+
# require 'rubygems'
|
|
2
|
+
# require 'bundler'
|
|
3
|
+
# require 'active_record'
|
|
4
|
+
# require 'active_support'
|
|
5
|
+
# require "best_boy/models/active_record/best_boy_event.rb"
|
|
6
|
+
# require "best_boy/models/active_record/best_boy/eventable.rb"
|
|
7
|
+
# require "best_boy/models/active_record/best_boy_day_report.rb"
|
|
8
|
+
# require "best_boy/models/active_record/best_boy_month_report.rb"
|
|
9
|
+
# require "best_boy/controllers/best_boy_controller.rb"
|
|
10
|
+
# require 'rspec'
|
|
11
|
+
# require 'rspec/autorun'
|
|
12
|
+
# require 'shoulda'
|
|
13
|
+
|
|
14
|
+
# root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
15
|
+
# ActiveRecord::Base.establish_connection(
|
|
16
|
+
# :adapter => "sqlite3",
|
|
17
|
+
# :database => "#{root}/db/bestboy.db"
|
|
18
|
+
# )
|
|
19
|
+
# ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'examples'")
|
|
20
|
+
# ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'best_boy_events'")
|
|
21
|
+
# ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'best_boy_day_reports'")
|
|
22
|
+
# ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'best_boy_month_reports'")
|
|
23
|
+
# ActiveRecord::Schema.define do
|
|
24
|
+
# self.verbose = false
|
|
25
|
+
|
|
26
|
+
# create_table :best_boy_events, :force => true do |t|
|
|
27
|
+
# t.integer :owner_id
|
|
28
|
+
# t.string :owner_type
|
|
29
|
+
# t.string :event
|
|
30
|
+
# t.string :event_source
|
|
31
|
+
# t.timestamps
|
|
32
|
+
# end
|
|
33
|
+
# add_index :best_boy_events, :owner_id
|
|
34
|
+
# add_index :best_boy_events, :owner_type
|
|
35
|
+
# add_index :best_boy_events, [:owner_id, :owner_type]
|
|
36
|
+
# add_index :best_boy_events, :event
|
|
37
|
+
|
|
38
|
+
# create_table :best_boy_day_reports, :force => true do |t|
|
|
39
|
+
# t.string :owner_type
|
|
40
|
+
# t.string :event
|
|
41
|
+
# t.string :event_source
|
|
42
|
+
# t.integer :month_report_id
|
|
43
|
+
# t.integer :occurrences, default: 0
|
|
44
|
+
# t.timestamps
|
|
45
|
+
# end
|
|
46
|
+
# create_table :best_boy_month_reports, :force => true do |t|
|
|
47
|
+
# t.string :owner_type
|
|
48
|
+
# t.string :event
|
|
49
|
+
# t.string :event_source
|
|
50
|
+
# t.integer :occurrences, default: 0
|
|
51
|
+
# t.timestamps
|
|
52
|
+
# end
|
|
53
|
+
|
|
54
|
+
# add_index :best_boy_day_reports, :created_at
|
|
55
|
+
# add_index :best_boy_month_reports, :created_at
|
|
56
|
+
|
|
57
|
+
# create_table :examples, :force => true do |t|
|
|
58
|
+
# t.timestamps
|
|
59
|
+
# end
|
|
60
|
+
# end
|
|
61
|
+
|
|
62
|
+
# ActiveRecord::Base.send(:include, BestBoy::Eventable)
|
|
63
|
+
|
|
64
|
+
# RSpec.configure do |config|
|
|
65
|
+
# config.mock_with :rspec
|
|
66
|
+
# config.include BestBoyController::InstanceMethods
|
|
67
|
+
# end
|
|
68
|
+
|
|
69
|
+
# Rspec Setup for rails engines accoring to http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
|
|
70
|
+
|
|
71
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
72
|
+
|
|
73
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
74
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
75
|
+
require 'rspec/rails'
|
|
10
76
|
require 'shoulda'
|
|
11
77
|
|
|
12
|
-
|
|
13
|
-
ActiveRecord::Base.establish_connection(
|
|
14
|
-
:adapter => "sqlite3",
|
|
15
|
-
:database => "#{root}/db/bestboy.db"
|
|
16
|
-
)
|
|
17
|
-
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'examples'")
|
|
18
|
-
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'best_boy_events'")
|
|
19
|
-
ActiveRecord::Schema.define do
|
|
20
|
-
self.verbose = false
|
|
21
|
-
|
|
22
|
-
create_table :best_boy_events, :force => true do |t|
|
|
23
|
-
t.integer :owner_id
|
|
24
|
-
t.string :owner_type
|
|
25
|
-
t.string :event
|
|
26
|
-
t.string :event_source
|
|
27
|
-
t.timestamps
|
|
28
|
-
end
|
|
29
|
-
add_index :best_boy_events, :owner_id
|
|
30
|
-
add_index :best_boy_events, :owner_type
|
|
31
|
-
add_index :best_boy_events, [:owner_id, :owner_type]
|
|
32
|
-
add_index :best_boy_events, :event
|
|
33
|
-
|
|
34
|
-
create_table :examples, :force => true do |t|
|
|
35
|
-
t.timestamps
|
|
36
|
-
end
|
|
37
|
-
end
|
|
78
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
38
79
|
|
|
39
|
-
|
|
80
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
81
|
+
# in spec/support/ and its subdirectories.
|
|
82
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
40
83
|
|
|
41
84
|
RSpec.configure do |config|
|
|
85
|
+
# == Mock Framework
|
|
86
|
+
#
|
|
87
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
88
|
+
#
|
|
89
|
+
# config.mock_with :mocha
|
|
90
|
+
# config.mock_with :flexmock
|
|
91
|
+
# config.mock_with :rr
|
|
42
92
|
config.mock_with :rspec
|
|
43
|
-
config.include BestBoyController::InstanceMethods
|
|
44
|
-
end
|
|
45
93
|
|
|
46
|
-
|
|
94
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
95
|
+
# examples within a transaction, remove the following line or assign false
|
|
96
|
+
# instead of true.
|
|
97
|
+
config.use_transactional_fixtures = true
|
|
98
|
+
|
|
99
|
+
# If true, the base class of anonymous controllers will be inferred
|
|
100
|
+
# automatically. This will be the default behavior in future versions of
|
|
101
|
+
# rspec-rails.
|
|
102
|
+
config.infer_base_class_for_anonymous_controllers = false
|
|
47
103
|
end
|
|
48
104
|
|
|
49
105
|
class Example < ActiveRecord::Base
|
|
50
106
|
has_a_best_boy
|
|
51
|
-
end
|
|
107
|
+
end
|