diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index 00f60c881c..1ff5b39d03 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -59,6 +59,10 @@ class MeetingsController < ApplicationController end 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 def copy diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 2e9a9a96ef..39108b53c2 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -94,12 +94,15 @@ class Meeting < ActiveRecord::Base end def copy(attrs) - copy = self.clone + copy = self.dup + copy.author = attrs.delete(:author) copy.attributes = attrs 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 end diff --git a/spec/controllers/.meetings_controller_spec.rb.swp b/spec/controllers/.meetings_controller_spec.rb.swp new file mode 100644 index 0000000000..2c4fb7411b Binary files /dev/null and b/spec/controllers/.meetings_controller_spec.rb.swp differ diff --git a/spec/controllers/meetings_controller_spec.rb b/spec/controllers/meetings_controller_spec.rb index 45704a9063..2f2b0646c4 100644 --- a/spec/controllers/meetings_controller_spec.rb +++ b/spec/controllers/meetings_controller_spec.rb @@ -18,7 +18,7 @@ describe MeetingsController do end describe "html" do before(:each) do - get "index" + get "index", :project_id => @p.id end it {response.should be_success} it {assigns(:meetings_by_start_year_month_date).should eql @ms} @@ -34,7 +34,7 @@ describe MeetingsController do end describe "html" do before(:each) do - get "show" + get "show", :id => @m.id end it {response.should be_success} end @@ -50,7 +50,7 @@ describe MeetingsController do end describe "html" do before(:each) do - get "new" + get "new", :project_id => @p.id end it {response.should be_success} it {assigns(:meeting).should eql @m} @@ -59,39 +59,35 @@ describe MeetingsController do describe "new with copy" do before(:each) do - Project.stub!(:find).and_return(@p) - @m = mock_model(Meeting) - @m.stub!(:project=) - @m.stub!(:author=) - Meeting.stub!(:new).and_return(@m) + Project.stub!(:find).with(@p.id.to_s).and_return(@p) + end + describe "with a valid meeting ID" do + before(:each) do + @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 - #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 before(:each) do - Meeting.stub!(:find).and_raise(ActiveRecord::RecordNotFound) + Meeting.delete_all end describe "html" do before(:each) do - get "new", :copy_from_id => 1 + get "new", :project_id => @p.id, :copy_from_id => 42 end it {response.should be_success} - it {assigns(:meeting).should eql @m} + it {assigns(:meeting).should be_kind_of Meeting} end end end @@ -104,7 +100,7 @@ describe MeetingsController do end describe "html" do before(:each) do - get "edit" + get "edit", :id => @m.id end it {response.should be_success} it {assigns(:meeting).should eql @m} diff --git a/spec/factories/meeting_participant_factory.rb b/spec/factories/meeting_participant_factory.rb index 7c9abba9f3..79a2a8bbca 100644 --- a/spec/factories/meeting_participant_factory.rb +++ b/spec/factories/meeting_participant_factory.rb @@ -1,4 +1,6 @@ FactoryGirl.define do factory :meeting_participant do |mp| + user + meeting end end