<commit_before># == Schema Information
# Schema version: 20090213233547
#
# Table name: raids
#
#  id              :integer(4)      not null, primary key
#  date            :date
#  note            :string(255)
#  thread          :integer(4)
#  created_at      :datetime
#  updated_at      :datetime
#  attendees_count :integer(4)      default(0)
#

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Raid do
  before(:each) do
    @raid = Raid.make
    
    Raid.make(:date => 60.days.ago)
  end
  
  it "should be valid" do
    @raid.should be_valid
  end
  
  describe "#date_string" do
    it "should return today's date as a string if no date is given" do
      @raid.date = nil
      @raid.date_string.should == Date.today.to_s(:db)
    end

    it "should return a string of its date value" do
      @raid.date = 3.days.until(Date.today)
      @raid.date_string.should == 3.days.until(Date.today).to_s(:db)
    end

    it "should modify the date attribute" do
      @raid.date_string = '2003-01-01'
      @raid.date.to_s(:db).should match(/^2003-01-01.+/)
    end
  end
  
  describe "#update_attendee_cache" do
    it "should allow disabling of attendee cache updates" do
      member = Member.make(:attendance_30 => 1.00)
      
      @raid.update_attendee_cache = false
      @raid.attendees.make(:member => member, :attendance => 0.50)
      
      lambda do
        @raid.save
        member.reload
      end.should_not change(member, :attendance_30)
    end
  end
end

# -----------------------------------------------------------------------------

describe Raid do
  before(:each) do
    Raid.destroy_all
    
    @raids = {
      :today       => Raid.make,
      :two_months  => Raid.make(:date => 2.months.ago),
      :four_months => Raid.make(:date => 4.months.ago)
    }
  end
  
  it "should count the total number of raids in the last thirty days" do
    Raid.count_last_thirty_days.should == 1
  end
  
  it "should count the total number of raids in the last ninety days" do
    Raid.count_last_ninety_days.should == 2
  end
  
  it "should know if it was in the last thirty days" do
    @raids[:today].is_in_last_thirty_days?.should be_true
    @raids[:four_months].is_in_last_thirty_days?.should be_false
  end
  <commit_msg>Add a few more examples to Raid to cover some built-in but very important Rails stuff.<commit_after># == Schema Information
# Schema version: 20090213233547
#
# Table name: raids
#
#  id              :integer(4)      not null, primary key
#  date            :date
#  note            :string(255)
#  thread          :integer(4)
#  created_at      :datetime
#  updated_at      :datetime
#  attendees_count :integer(4)      default(0)
#

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Raid do
  before(:each) do
    @raid = Raid.make
    
    Raid.make(:date => 60.days.ago)
  end
  
  it "should be valid" do
    @raid.should be_valid
  end
  
  it "should have attendees" do
    5.times { @raid.attendees.make }
    
    @raid.reload
    @raid.attendees_count.should == 5
    @raid.attendees.size.should == 5
  end
  
  it "should have items" do
    8.times { @raid.items.make }
    
    @raid.reload
    @raid.items_count.should == 8
    @raid.items.size.should == 8
  end
  
  describe "#date_string" do
    it "should return today's date as a string if no date is given" do
      @raid.date = nil
      @raid.date_string.should == Date.today.to_s(:db)
    end

    it "should return a string of its date value" do
      @raid.date = 3.days.until(Date.today)
      @raid.date_string.should == 3.days.until(Date.today).to_s(:db)
    end

    it "should modify the date attribute" do
      @raid.date_string = '2003-01-01'
      @raid.date.to_s(:db).should match(/^2003-01-01.+/)
    end
  end
  
  describe "#update_attendee_cache" do
    before(:each) do
      @member = Member.make(:attendance_30 => 1.00)
      @raid.attendees.make(:member => @member, :attendance => 0.50)
    end
    
    it "should update attendee cache unless disabled" do
      @raid.update_attendee_cache = true
      
      lambda do
        @raid.save
        @member.reload
      end.should change(@member, :attendance_30)
    end
    
    it "should allow disabling of attendee cache updates" do
      @raid.update_attendee_cache = false
      
      lambda do
        @raid.save
        @member.reload
      end.should_not change(@member, :attendance_30)
    end
  end
end

# -----------------------------------------------------------------------------

describe Raid do
  before(:each) do
    Raid.destroy_all
    
    @raids = {
      :today       => Raid.make,
      :two_months  => Raid.make(:date => 2.months.ago),
      :four_months => Raid.make(:date => 4.months.ago)
    }
  end
  
  it "should count the total number of raids in the last thirty days" do
    Raid.count_last_thirty_days.should == 1
  end
  
  it "should count the total number of raids in the last ninety days" do
    Raid.count_last_ninety_days.should == 2
  end
  
  it "should know if it was in the last thirty days" do
    @raids[:today].is_in_last_thirty_days?.should be_true
    @raids[:four_months].is_in_last_thirty_days?.should be_false
  end
  
{'fraction_non_alphanumeric': 0.13369086381919174, 'fraction_numerical': 0.022601034284619806, 'mean_word_length': 2.2155172413793105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2066358', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1729, 'n_words': 456}