best_boy 2.0.2 → 2.0.3
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/lib/best_boy/models/active_record/best_boy_event.rb +6 -0
- data/lib/best_boy/version.rb +1 -1
- metadata +3 -149
- data/spec/controllers/best_boy_controller_spec.rb +0 -23
- data/spec/dummy/Procfile +0 -1
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/test_events_controller.rb +0 -9
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/test_event.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/test_events/index.html.haml +0 -9
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -54
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -29
- data/spec/dummy/config/environments/production.rb +0 -69
- data/spec/dummy/config/environments/test.rb +0 -32
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/best_boy.rb +0 -19
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130702102348_create_tests.rb +0 -7
- data/spec/dummy/db/migrate/20130702102713_create_best_boy_events_table.rb +0 -17
- data/spec/dummy/db/migrate/20130702102714_add_event_source_to_best_boy_events_table.rb +0 -11
- data/spec/dummy/db/migrate/20130702104631_change_tests_to_testevents.rb +0 -5
- data/spec/dummy/db/migrate/20131108085915_create_best_boy_reports.rb +0 -30
- data/spec/dummy/db/schema.rb +0 -61
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/tmp/cache/assets/development/sass/4a6e68811662121fe1049014c3677ece8bd5de12/bootstrap.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/207d5e64e2cebd2453c18bd64d2961e9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2b348013eb6ff07d5c30fbd231f48ead +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/385fe425643c1aa4f6d65ff6562e536e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3df20dbdd9feb9b6181ccaf69566f9b7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/428540decb22e109bd1221fbc0543fab +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4b137a5fed68ef0fcfef0ec706e46313 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5a42f175bf885737d4e31c9985d6fe07 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5fa93bf05e13e230b8f400edb70fef1d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5faa5b46b3032de437b4cb56b03865c6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6eaff7b9f6611fc81edb0b1b45f3fd2e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/73a1efeff5a637a701c94afff8697e19 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7f6a8adf47d3f3d25e88800bba7470f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8aa4f4408b1d26bd374de22fa249c0ed +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a50fa992e0426e9c5d165ef9274cb535 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc05356ab498eeba43f3f7e8b496eb10 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c4db8bd94cb08dd1291ec04b1d06a493 +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/da46dd3b99291773829efe873601b4b7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/db1632e0b72a95b4e7bbf489a0ffecbc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ebb402e0bb3b027cc688fe002bdee3f7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/models/best_boy_event_spec.rb +0 -20
- data/spec/models/day_report_spec.rb +0 -115
- data/spec/models/eventable_spec.rb +0 -51
- data/spec/models/month_report_spec.rb +0 -113
- data/spec/spec_helper.rb +0 -107
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class CreateBestBoyEventsTable < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
create_table :best_boy_events, :force => true do |t|
|
|
4
|
-
t.integer :owner_id
|
|
5
|
-
t.string :owner_type
|
|
6
|
-
t.string :event
|
|
7
|
-
t.timestamps
|
|
8
|
-
end
|
|
9
|
-
add_index :best_boy_events, :owner_type
|
|
10
|
-
add_index :best_boy_events, [:owner_id, :owner_type]
|
|
11
|
-
add_index :best_boy_events, :event
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.down
|
|
15
|
-
drop_table :best_boy_events
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
class AddEventSourceToBestBoyEventsTable < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :best_boy_events, :event_source, :string
|
|
4
|
-
add_index :best_boy_events, :event_source
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def self.down
|
|
8
|
-
remove_index :best_boy_events, :event_source
|
|
9
|
-
remove_column :best_boy_events, :event_source
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
class CreateBestBoyReports < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
create_table :best_boy_day_reports, :force => true do |t|
|
|
4
|
-
t.string :owner_type
|
|
5
|
-
t.string :event
|
|
6
|
-
t.string :event_source
|
|
7
|
-
t.integer :month_report_id
|
|
8
|
-
t.integer :occurrences, default: 0
|
|
9
|
-
t.timestamps
|
|
10
|
-
end
|
|
11
|
-
add_index :best_boy_day_reports, [:owner_type, :event, :event_source], :name => :index_best_boy_day_reports_aggregated_columns
|
|
12
|
-
add_index :best_boy_day_reports, :created_at
|
|
13
|
-
add_index :best_boy_day_reports, :month_report_id
|
|
14
|
-
|
|
15
|
-
create_table :best_boy_month_reports, :force => true do |t|
|
|
16
|
-
t.string :owner_type
|
|
17
|
-
t.string :event
|
|
18
|
-
t.string :event_source
|
|
19
|
-
t.integer :occurrences, default: 0
|
|
20
|
-
t.timestamps
|
|
21
|
-
end
|
|
22
|
-
add_index :best_boy_month_reports, [:owner_type, :event, :event_source], :name => :index_best_boy_month_reports_aggregated_columns
|
|
23
|
-
add_index :best_boy_month_reports, :created_at
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def self.down
|
|
27
|
-
drop_table :best_boy_month_reports
|
|
28
|
-
drop_table :best_boy_day_reports
|
|
29
|
-
end
|
|
30
|
-
end
|
data/spec/dummy/db/schema.rb
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
|
5
|
-
#
|
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
|
7
|
-
# database schema. If you need to create the application database on another
|
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
11
|
-
#
|
|
12
|
-
# It's strongly recommended that you check this file into your version control system.
|
|
13
|
-
|
|
14
|
-
ActiveRecord::Schema.define(version: 20131108085915) do
|
|
15
|
-
|
|
16
|
-
create_table "best_boy_day_reports", force: true do |t|
|
|
17
|
-
t.string "owner_type"
|
|
18
|
-
t.string "event"
|
|
19
|
-
t.string "event_source"
|
|
20
|
-
t.integer "month_report_id"
|
|
21
|
-
t.integer "occurrences", default: 0
|
|
22
|
-
t.datetime "created_at"
|
|
23
|
-
t.datetime "updated_at"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
add_index "best_boy_day_reports", ["created_at"], name: "index_best_boy_day_reports_on_created_at"
|
|
27
|
-
add_index "best_boy_day_reports", ["month_report_id"], name: "index_best_boy_day_reports_on_month_report_id"
|
|
28
|
-
add_index "best_boy_day_reports", ["owner_type", "event", "event_source"], name: "index_best_boy_day_reports_aggregated_columns"
|
|
29
|
-
|
|
30
|
-
create_table "best_boy_events", force: true do |t|
|
|
31
|
-
t.integer "owner_id"
|
|
32
|
-
t.string "owner_type"
|
|
33
|
-
t.string "event"
|
|
34
|
-
t.datetime "created_at"
|
|
35
|
-
t.datetime "updated_at"
|
|
36
|
-
t.string "event_source"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
add_index "best_boy_events", ["event"], name: "index_best_boy_events_on_event"
|
|
40
|
-
add_index "best_boy_events", ["event_source"], name: "index_best_boy_events_on_event_source"
|
|
41
|
-
add_index "best_boy_events", ["owner_id", "owner_type"], name: "index_best_boy_events_on_owner_id_and_owner_type"
|
|
42
|
-
add_index "best_boy_events", ["owner_type"], name: "index_best_boy_events_on_owner_type"
|
|
43
|
-
|
|
44
|
-
create_table "best_boy_month_reports", force: true do |t|
|
|
45
|
-
t.string "owner_type"
|
|
46
|
-
t.string "event"
|
|
47
|
-
t.string "event_source"
|
|
48
|
-
t.integer "occurrences", default: 0
|
|
49
|
-
t.datetime "created_at"
|
|
50
|
-
t.datetime "updated_at"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
add_index "best_boy_month_reports", ["created_at"], name: "index_best_boy_month_reports_on_created_at"
|
|
54
|
-
add_index "best_boy_month_reports", ["owner_type", "event", "event_source"], name: "index_best_boy_month_reports_aggregated_columns"
|
|
55
|
-
|
|
56
|
-
create_table "test_events", force: true do |t|
|
|
57
|
-
t.datetime "created_at"
|
|
58
|
-
t.datetime "updated_at"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
end
|
data/spec/dummy/db/test.sqlite3
DELETED
|
Binary file
|
data/spec/dummy/public/404.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/404.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
|
23
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
|
24
|
-
</div>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
data/spec/dummy/public/422.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/422.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>The change you wanted was rejected.</h1>
|
|
23
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
24
|
-
</div>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
data/spec/dummy/public/500.html
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/500.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>We're sorry, but something went wrong.</h1>
|
|
23
|
-
</div>
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|
|
File without changes
|
data/spec/dummy/script/rails
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
-
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
-
require 'rails/commands'
|
|
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
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|