Sha256: f054c90c3937dc133fd54a7592adfb4976d3cfd384c301188209857b38dcd6ff

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Saulabs::Reportable do

  before(:all) do
    User.create!(:login => 'test 1', :created_at => Time.now - 1.days,  :profile_visits => 1)
    User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :profile_visits => 2)
  end

  it 'should return a Saulabs::Reportable::ResultSet' do
    User.registrations_report.should be_instance_of(Saulabs::Reportable::ResultSet)
  end

  it 'should return a result set that stores the name of the model the report was invoked on' do
    User.registrations_report.model_name.should == User.name
  end

  it 'should return a result set that stores the name of the report that was invoked' do
    User.registrations_report.report_name.should == 'registrations'
  end

  describe 'for inherited models' do

    before(:all) do
      SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days, :profile_visits => 3)
    end

    it 'should return a result set that stores the model the report was invoked on' do
      SpecialUser.registrations_report.model_name.should == SpecialUser.name
    end

    it 'should include all data when invoked on the base model class' do
      result = User.registrations_report.to_a

      result[9][1].should == 1.0
      result[8][1].should == 2.0
    end

    it 'should include only data for instances of the inherited model when invoked on the inherited model class' do
      result = SpecialUser.registrations_report.to_a

      result[9][1].should == 0.0
      result[8][1].should == 1.0
    end

    after(:all) do
      SpecialUser.destroy_all
    end

  end

  after do
    Saulabs::Reportable::ReportCache.destroy_all
  end

  after(:all) do
    User.destroy_all
  end

end

class User < ActiveRecord::Base

  reportable :registrations, :limit => 10

end

class SpecialUser < User; end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reportable-1.1.2 spec/other/report_method_spec.rb
reportable-1.1.0 spec/other/report_method_spec.rb