reparty 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
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')
@@ -8,7 +8,7 @@
8
8
  <body>
9
9
  <table cellpadding="0" cellspacing="0" border="0" align="center" width="600">
10
10
  <tr>
11
- <td><h1>Your Daily Report:</h1></td>
11
+ <td><h1><%= @title %></h1></td>
12
12
  </tr>
13
13
  <% @reports.each do |report| -%>
14
14
  <tr><td>
data/lib/reparty/email.rb CHANGED
@@ -12,6 +12,10 @@ module Reparty
12
12
  def subject
13
13
  Reparty.configuration.subject || "Reparty Report!"
14
14
  end
15
+
16
+ def title
17
+ Reparty.configuration.title || 'Your Daily Report:'
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -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
- raise "Report::ActiveRecord: model undefined" unless args.first.is_a?(Symbol)
10
- @model = Kernel.const_get(args.first.to_s.capitalize)
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
 
@@ -1,3 +1,3 @@
1
1
  module Reparty
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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 'should have a version number' do
4
+ it "should have a version number" do
5
5
  Reparty::VERSION.should_not be_nil
6
6
  end
7
7
 
8
- it 'configures properly' do
8
+ it "configures properly" do
9
9
  Reparty.config do |config|
10
- config.sender = 'test@test.com'
10
+ config.sender = "test@test.com"
11
11
  end
12
- Reparty.configuration.sender.should == 'test@test.com'
12
+ Reparty.configuration.sender.should == "test@test.com"
13
13
  end
14
14
 
15
- it 'adds reports' do
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 "Reparty::Report::ActiveRecord" do
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 'configures cleanly' do
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.2
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: 364078878128042041
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: 364078878128042041
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