reparty 0.1.2 → 0.1.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/History.md +7 -0
- data/app/mailers/report_mailer.rb +2 -0
- data/app/views/report_mailer/daily.html.erb +1 -1
- data/lib/reparty/email.rb +4 -0
- data/lib/reparty/report/active_record.rb +11 -4
- data/lib/reparty/version.rb +1 -1
- data/spec/email_spec.rb +24 -0
- data/spec/reparty_spec.rb +5 -5
- data/spec/report/active_record_spec.rb +34 -2
- metadata +5 -3
data/History.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.1.3
|
2
|
+
|
3
|
+
- Better testing and coverage.
|
4
|
+
- Fixed grouping of items by date. Now groups by day, not by time period.
|
5
|
+
- Support scopes in ActiveRecord report
|
6
|
+
- Add an email title configuration (config.title)
|
7
|
+
|
1
8
|
## 0.1.2
|
2
9
|
|
3
10
|
- Accidentally included rake task twice by defining both an Engine and a Railtie
|
@@ -3,6 +3,8 @@ ActionMailer::Base.view_paths = File.expand_path('../../views/', __FILE__)
|
|
3
3
|
class ReportMailer < ActionMailer::Base
|
4
4
|
def daily(to)
|
5
5
|
|
6
|
+
@title = Reparty::Email.title
|
7
|
+
|
6
8
|
@reports = Reparty::Email.reports
|
7
9
|
@reports.each {|r| r.attach(attachments)}
|
8
10
|
attachments.inline['spacer.gif'] = File.read(Reparty.root + 'app/assets/images/spacer.gif')
|
data/lib/reparty/email.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
1
3
|
module Reparty
|
2
4
|
class Report
|
3
5
|
class ActiveRecord < Report
|
@@ -6,8 +8,13 @@ module Reparty
|
|
6
8
|
def initialize(*args, &block)
|
7
9
|
super(args.shift)
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
if args.first.is_a?(Symbol)
|
12
|
+
@model = Kernel.const_get(args.first.to_s.capitalize)
|
13
|
+
elsif args.first.is_a?(::ActiveRecord::Relation)
|
14
|
+
@model = args.first
|
15
|
+
else
|
16
|
+
raise "Report::ActiveRecord: model undefined"
|
17
|
+
end
|
11
18
|
|
12
19
|
@operation = args.fetch(1, :count)
|
13
20
|
@field = :created_at
|
@@ -27,9 +34,9 @@ module Reparty
|
|
27
34
|
|
28
35
|
def daily_dataset
|
29
36
|
if @operation == :total
|
30
|
-
7.downto(1).map { |x| @model.where("#{@field.to_s} < ?", DateTime.now-x).send(:count, @field) }
|
37
|
+
7.downto(1).map { |x| @model.where("#{@field.to_s} < ?", DateTime.now.at_midnight-x).send(:count, @field) }
|
31
38
|
else
|
32
|
-
7.downto(1).map { |x| @model.where("DATE(#{@field.to_s}) = ?", DateTime.now-x).send(@operation, @field) }
|
39
|
+
7.downto(1).map { |x| @model.where("DATE(#{@field.to_s}) = ?", DateTime.now.to_date-x).send(@operation, @field) }
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
data/lib/reparty/version.rb
CHANGED
data/spec/email_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Reparty::Email do
|
4
|
+
describe "provides variables" do
|
5
|
+
let(:klass) { subject.class }
|
6
|
+
|
7
|
+
let(:from) { "test@test.com" }
|
8
|
+
let(:subj) { "Test Subject" }
|
9
|
+
let(:title) { "Test Title" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
Reparty.config do |config|
|
13
|
+
config.from = from
|
14
|
+
config.subject = subj
|
15
|
+
config.title = title
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it { klass.from.should eq(from) }
|
20
|
+
it { klass.subject.should eq(subj) }
|
21
|
+
it { klass.title.should eq(title) }
|
22
|
+
it { klass.reports.should be_empty }
|
23
|
+
end
|
24
|
+
end
|
data/spec/reparty_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Reparty do
|
4
|
-
it
|
4
|
+
it "should have a version number" do
|
5
5
|
Reparty::VERSION.should_not be_nil
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it "configures properly" do
|
9
9
|
Reparty.config do |config|
|
10
|
-
config.sender =
|
10
|
+
config.sender = "test@test.com"
|
11
11
|
end
|
12
|
-
Reparty.configuration.sender.should ==
|
12
|
+
Reparty.configuration.sender.should == "test@test.com"
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "adds reports" do
|
16
16
|
Reparty.config do |config|
|
17
17
|
config.add_report Reparty::Report, "Some Report"
|
18
18
|
end
|
@@ -1,15 +1,47 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Reparty::Report::ActiveRecord do
|
4
4
|
before(:each) do
|
5
5
|
User.delete_all
|
6
|
+
[
|
7
|
+
{:name => "Someone", :score => 7, :created_at => DateTime.now - 2},
|
8
|
+
{:name => "Sometwo", :score => 4, :created_at => DateTime.now - 2},
|
9
|
+
{:name => "Somethree", :score => 6, :created_at => DateTime.now - 4},
|
10
|
+
{:name => "Somefour", :score => 8, :created_at => DateTime.now - 5},
|
11
|
+
{:name => "Somefive", :score => 2, :created_at => DateTime.now - 6},
|
12
|
+
{:name => "Somesix", :score => 4, :created_at => DateTime.now - 7},
|
13
|
+
{:name => "Someseven", :score => 5, :created_at => DateTime.now - 8},
|
14
|
+
].each{|u| User.create!(u) }
|
6
15
|
end
|
7
16
|
|
8
|
-
it
|
17
|
+
it "configures cleanly" do
|
9
18
|
Reparty.config do |config|
|
10
19
|
config.add_report Reparty::Report::ActiveRecord, "Users", :user, :count, field: :updated_at
|
11
20
|
end
|
12
21
|
Reparty.reports.last.should be_kind_of(Reparty::Report::ActiveRecord)
|
13
22
|
Reparty.reports.last.field.should == :updated_at
|
14
23
|
end
|
24
|
+
|
25
|
+
describe "when configured" do
|
26
|
+
subject { Reparty.reports.first }
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
Reparty.config do |config|
|
30
|
+
config.add_report Reparty::Report::ActiveRecord, "Users", :user
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
its(:daily_dataset) { should == [1,1,1,1,0,2,0] }
|
35
|
+
its(:yesterday) { should == 0 }
|
36
|
+
its(:total) { should == 7 }
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "accepts scopes" do
|
41
|
+
Reparty.config do |config|
|
42
|
+
config.add_report Reparty::Report::ActiveRecord, "Users", User.where("score > 2")
|
43
|
+
end
|
44
|
+
|
45
|
+
Reparty.reports.first.daily_dataset.should == [1,0,1,1,0,2,0]
|
46
|
+
end
|
15
47
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: reparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Dorr
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/reparty/version.rb
|
217
217
|
- lib/tasks/reparty.rake
|
218
218
|
- reparty.gemspec
|
219
|
+
- spec/email_spec.rb
|
219
220
|
- spec/reparty_spec.rb
|
220
221
|
- spec/report/active_record_spec.rb
|
221
222
|
- spec/report_spec.rb
|
@@ -235,7 +236,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
236
|
- !ruby/object:Gem::Version
|
236
237
|
segments:
|
237
238
|
- 0
|
238
|
-
hash:
|
239
|
+
hash: -2326617942831094702
|
239
240
|
version: '0'
|
240
241
|
none: false
|
241
242
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -244,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
245
|
- !ruby/object:Gem::Version
|
245
246
|
segments:
|
246
247
|
- 0
|
247
|
-
hash:
|
248
|
+
hash: -2326617942831094702
|
248
249
|
version: '0'
|
249
250
|
none: false
|
250
251
|
requirements: []
|
@@ -254,6 +255,7 @@ signing_key:
|
|
254
255
|
specification_version: 3
|
255
256
|
summary: Stupid easy business analytics
|
256
257
|
test_files:
|
258
|
+
- spec/email_spec.rb
|
257
259
|
- spec/reparty_spec.rb
|
258
260
|
- spec/report/active_record_spec.rb
|
259
261
|
- spec/report_spec.rb
|