Sha256: a005f6e9322f7db9e8a5193c9d8a919e697bcaf6f247f0e4906092b20a2da7e8

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

# coding: utf-8
require 'spec_helper'
require 'acts_as_footprintable/footprinter'

describe ActsAsFootprintable::Footprinter do

  it "should not be a footprinter" do
    NotUser.should_not be_footprinter
  end

  it "should be a footprinter" do
    User.should be_footprinter
  end

  describe "ユーザーのアクセス履歴を" do
    before do
      @user = User.create!(:name => "user")
      (1..5).each do |index|
        footprintable = Footprintable.create!(:name => "footprintable#{index}")
        second_footprintable = SecondFootprintable.create!(:name => "second_footprintable#{index}")
        3.times do
          footprintable.leave_footprints @user
          second_footprintable.leave_footprints @user
        end
      end
    end

    context "対象のモデル毎に" do
      it "取得できること" do
        @user.access_histories_for(Footprintable).should have(5).items
        @user.access_histories_for(Footprintable).map{|footprint| footprint.footprintable.name}.should == (1..5).to_a.reverse.map{|index| "footprintable#{index}"}
      end

      it "件数を絞り込めること" do
        @user.access_histories_for(Footprintable, 3).should have(3).items
        @user.access_histories_for(Footprintable, 3).map{|footprint| footprint.footprintable.name}.should == (3..5).to_a.reverse.map{|index| "footprintable#{index}"}
      end
    end

    context "全てのモデルを通じて" do
      it "取得できること" do
        @user.access_histories.should have(10).items
        @user.access_histories.map{|footprint| footprint.footprintable.name}.should == (1..5).to_a.reverse.inject([]) do |results, index|
          results.push "second_footprintable#{index}"
          results.push "footprintable#{index}"
          results
        end
      end

      it "件数を絞り込める事" do
        @user.access_histories(3).should have(3).items
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_footprintable-0.2.2 spec/footprinter_spec.rb