Adapt specs to changed routes and implement copy spec

pull/6827/head
Hagen Schink 12 years ago
parent c4b3c4970b
commit 14f7e38d01
  1. 4
      app/controllers/meetings_controller.rb
  2. 9
      app/models/meeting.rb
  3. BIN
      spec/controllers/.meetings_controller_spec.rb.swp
  4. 54
      spec/controllers/meetings_controller_spec.rb
  5. 2
      spec/factories/meeting_participant_factory.rb

@ -59,6 +59,10 @@ class MeetingsController < ApplicationController
end end
def new def new
if params[:copy_from_id]
original_meeting = Meeting.find_by_id(params[:copy_from_id])
@meeting = original_meeting.copy(:author => User.current, :start_time => nil) if original_meeting
end
end end
def copy def copy

@ -94,12 +94,15 @@ class Meeting < ActiveRecord::Base
end end
def copy(attrs) def copy(attrs)
copy = self.clone copy = self.dup
copy.author = attrs.delete(:author) copy.author = attrs.delete(:author)
copy.attributes = attrs copy.attributes = attrs
copy.send(:set_initial_values) copy.send(:set_initial_values)
copy_participant_user_ids = copy.participants.collect(&:user_id)
copy.participants << self.participants.invited.reject{|p| copy_participant_user_ids.include? p.user_id}.collect(&:clone).each{|p| p.attended=false} # Make sure the participants have no id copy.participants.clear
copy.participants << self.participants
copy copy
end end

@ -18,7 +18,7 @@ describe MeetingsController do
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "index" get "index", :project_id => @p.id
end end
it {response.should be_success} it {response.should be_success}
it {assigns(:meetings_by_start_year_month_date).should eql @ms} it {assigns(:meetings_by_start_year_month_date).should eql @ms}
@ -34,7 +34,7 @@ describe MeetingsController do
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "show" get "show", :id => @m.id
end end
it {response.should be_success} it {response.should be_success}
end end
@ -50,7 +50,7 @@ describe MeetingsController do
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "new" get "new", :project_id => @p.id
end end
it {response.should be_success} it {response.should be_success}
it {assigns(:meeting).should eql @m} it {assigns(:meeting).should eql @m}
@ -59,39 +59,35 @@ describe MeetingsController do
describe "new with copy" do describe "new with copy" do
before(:each) do before(:each) do
Project.stub!(:find).and_return(@p) Project.stub!(:find).with(@p.id.to_s).and_return(@p)
@m = mock_model(Meeting) end
@m.stub!(:project=) describe "with a valid meeting ID" do
@m.stub!(:author=) before(:each) do
Meeting.stub!(:new).and_return(@m) @mc = FactoryGirl.create(:meeting, "duration"=>1.5, "location"=>"Raum 4", "title"=>"dingens", "updated_at"=>Time.parse("Thu Feb 17 11:33:22 +0100 2011"), :start_time=>Time.parse("Fri Feb 18 14:36:25 +0100 2011"))
@participants = [FactoryGirl.create(:meeting_participant, :meeting=>@mc)]
end
describe "html" do
before(:each) do
get "new", :project_id => @p.id, :copy_from_id => @mc.id
end
it {response.should be_success}
it {assigns(:meeting).title.should eql "dingens"}
it {assigns(:meeting).duration.should eql 1.5}
it {assigns(:meeting).location.should eql "Raum 4"}
it {assigns(:meeting).start_time.should eql (Date.tomorrow + 10.hours)}
it {assigns(:meeting).participants.should eql @participants}
end
end end
#describe "with a valid meeting ID" do
# before(:each) do
# @mc = mock_model(Meeting)
# Meeting.stub!(:find).and_return(@mc)
# @mc.stub!(:attributes).and_return({"duration"=>1.5, "location"=>"Raum 4", "title"=>"dingens", "updated_at"=>Time.parse("Thu Feb 17 11:33:22 +0100 2011")})
# @mc.stub!(:start_time).and_return(Time.parse("Fri Feb 18 14:36:25 +0100 2011"))
# @mc.stub!(:participants).and_return([mock_model(MeetingParticipant), mock_model(MeetingParticipant), mock_model(MeetingParticipant)])
# end
# describe "html" do
# before(:each) do
# get "new", :copy_from_id => 1
# end
# it {pending; response.should be_success}
# it {pending; assigns(:meeting).should eql @m}
# it {pending} # TODO: testen ob das richtig kopiert wird
# end
#end
describe "with an invalid meeting ID" do describe "with an invalid meeting ID" do
before(:each) do before(:each) do
Meeting.stub!(:find).and_raise(ActiveRecord::RecordNotFound) Meeting.delete_all
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "new", :copy_from_id => 1 get "new", :project_id => @p.id, :copy_from_id => 42
end end
it {response.should be_success} it {response.should be_success}
it {assigns(:meeting).should eql @m} it {assigns(:meeting).should be_kind_of Meeting}
end end
end end
end end
@ -104,7 +100,7 @@ describe MeetingsController do
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "edit" get "edit", :id => @m.id
end end
it {response.should be_success} it {response.should be_success}
it {assigns(:meeting).should eql @m} it {assigns(:meeting).should eql @m}

@ -1,4 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :meeting_participant do |mp| factory :meeting_participant do |mp|
user
meeting
end end
end end

Loading…
Cancel
Save