Sha256: 512d41d8e7158a3cc7f56af5c38f172008bc52b2e4645e0c896ae8d9424cf20a

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require_relative '../spec_helper'

describe Reparty::Report::ActiveRecord do
  before(:each) do
    User.delete_all
    [
        {:name => "Someone",   :score => 7, :created_at => DateTime.now.utc - 2},
        {:name => "Sometwo",   :score => 4, :created_at => DateTime.now.utc - 2},
        {:name => "Somethree", :score => 6, :created_at => DateTime.now.utc - 4},
        {:name => "Somefour",  :score => 8, :created_at => DateTime.now.utc - 5},
        {:name => "Somefive",  :score => 2, :created_at => DateTime.now.utc - 6},
        {:name => "Somesix",   :score => 4, :created_at => DateTime.now.utc - 7},
        {:name => "Someseven", :score => 5, :created_at => DateTime.now.utc - 8},
    ].each{|u| User.create!(u) }
  end

  it "configures cleanly" do
    Reparty.config do |config|
      config.add_report Reparty::Report::ActiveRecord, "Users", :user, :count, field: :updated_at
    end
    Reparty.reports.last.should be_kind_of(Reparty::Report::ActiveRecord)
    Reparty.reports.last.field.should == :updated_at
    Reparty.reports.last.color.should == "#85bdad"
  end

  describe "when configured" do
    subject { Reparty.reports.first }

    before(:each) do
      Reparty.config do |config|
        config.add_report Reparty::Report::ActiveRecord, "Users", :user
      end
    end

    its(:daily_dataset) { should == [1,1,1,1,1,0,2] }
    its(:yesterday)     { should == 0 }
    its(:total)         { should == 7 }

  end

  it "accepts scopes" do
    Reparty.config do |config|
      config.add_report Reparty::Report::ActiveRecord, "Users", User.where("score > 2")
    end

    Reparty.reports.first.daily_dataset.should == [1,1,0,1,1,0,2]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reparty-0.2.0 spec/report/active_record_spec.rb