Sha256: 8f9cb95854d9cad4f40c585217fc570f0eacd890479dab1d031f300db0a1e264

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# coding: utf-8
require 'spec_helper'

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{|footprintable| 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
      end
    end

    context "全てのモデルを通じて" do
      it "取得できること" do
        @user.access_histories.should have(10).items
        @user.access_histories.map{|footprintable| 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.0 spec/footprinter_spec.rb