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,113 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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'
|
|
76
|
-
require 'shoulda'
|
|
77
|
-
|
|
78
|
-
Rails.backtrace_cleaner.remove_silencers!
|
|
79
|
-
|
|
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 }
|
|
83
|
-
|
|
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
|
|
92
|
-
config.mock_with :rspec
|
|
93
|
-
|
|
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
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class Example < ActiveRecord::Base
|
|
106
|
-
has_a_best_boy
|
|
107
|
-
end
|