Skip to content

Instantly share code, notes, and snippets.

@scottshea
Created May 11, 2012 22:41
Show Gist options
  • Save scottshea/2662886 to your computer and use it in GitHub Desktop.
Save scottshea/2662886 to your computer and use it in GitHub Desktop.
dcp spec again
require 'spec_helper'
describe DcpMeeting do
it { should have_one :checkpoint }
it { should belong_to :coach }
it { should belong_to :organization }
it_should_behave_like "Meeting Delegates"
it "should be made with blueprints" do
m = DcpMeeting.make!
m.should_not be_nil
m.coach.should_not be_nil
end
it "should be attended if there is a checkpoint and it was attended in person" do
m = DcpMeeting.new
m.attended?.should be_false
cp = mock_model(DcpCheckpoint)
cp.should_receive(:attended_on_site?).and_return(true)
m.stub(:checkpoint).and_return(cp)
m.attended?.should be_true
end
it "should build a new checkpoint if one doesnt exist" do
part = mock_model(DcpParticipant)
ps = mock_model(ProgramSession)
m = DcpMeeting.new(:program_session => ps, :meeting_time => DateTime.now)
m.stub_chain(:program_offering, :participants, :first).and_return(part)
m.checkpoint.should be_nil
cp = m.build_dcp_checkpoint
m.checkpoint.should == cp
cp.recorded_at.should_not be_blank
cp.dcp_meeting.should == m
cp.participant.should == part
cp.program_session.should == ps
cp.attendance_type.should == AttendanceType[:IN_PERSON]
end
it "should create a new checkpoint if one doesnt exist and set the service date if passed in" do
make_albertsons_orgs
part = mock_model(DcpParticipant)
part.stub!(:valid?).and_return(true)
part.stub!(:save).and_return(true)
ps = mock_model(ProgramSession)
ps.stub!(:valid?).and_return(true)
ps.stub!(:save).and_return(true)
schedule = mock_model(Schedule)
meeting_time = 10.days.ago.to_datetime
m = DcpMeeting.create!(:program_session => ps, :organization => Organization.find_by_name(ALBERTSONS_STORE_NAME),
:meeting_date => meeting_time.to_s(:mdY), :meeting_time_of_day => meeting_time.to_s(:hm),
:meeting_type => MeetingType[:CORE], :schedule => schedule)
m.stub_chain(:program_offering, :participants, :first).and_return(part)
m.checkpoint.should be_nil
service_date = 3.days.ago
cp = m.create_dcp_checkpoint!(service_date)
m.checkpoint.should == cp
cp.recorded_at.should_not be_blank
cp.recorded_at.should == service_date
cp.new_record?.should be_false
cp.dcp_meeting.should == m
cp.participant.should == part
cp.program_session.should == ps
cp.attendance_type.should == AttendanceType[:IN_PERSON]
end
it "should create a new checkpoint if one doesnt exist and default the service date to the meeting date and local time zone if one isnt passed in" do
make_albertsons_orgs
part = mock_model(DcpParticipant)
part.stub!(:valid?).and_return(true)
part.stub!(:save).and_return(true)
ps = mock_model(ProgramSession)
ps.stub!(:valid?).and_return(true)
ps.stub!(:save).and_return(true)
schedule = mock_model(Schedule)
org = Organization.find_by_name(ALBERTSONS_STORE_NAME)
m = DcpMeeting.create!(
:program_session => ps,
:organization => org,
:meeting_date => "2011-02-14",
:meeting_time_of_day => "08:30 AM",
:meeting_type => MeetingType[:CORE],
:schedule => schedule)
m.stub_chain(:program_offering, :participants, :first).and_return(part)
m.checkpoint.should be_nil
cp = m.create_dcp_checkpoint!(nil)
m.checkpoint.should == cp
cp.recorded_at.should_not be_blank
cp.recorded_at_in_local_time.to_s(:Ymd).should == "2011-02-14"
cp.recorded_at_in_local_time.to_s(:hmp).should == "08:30 AM"
cp.new_record?.should be_false
cp.dcp_meeting.should == m
cp.participant.should == part
cp.program_session.should == ps
cp.attendance_type.should == AttendanceType[:IN_PERSON]
end
describe "organization delegates" do
it_should_behave_like "Meeting Delegates"
subject do
m = DcpMeeting.new(:organization => mock_model(Organization, :name => "Test Organization", :address => "An address string", :main_phone_number => "111-111-1111"))
puts "AAAAAAAAAA"
raise m.organization.inspect
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment