Merge pull request #47 from finnlabs/feature/rspec-299

RSpec 2.99 Upgrade
pull/6827/head
ulferts 10 years ago
commit 452fed1ba7
  1. 4
      spec/controllers/meeting_agendas_controller_spec.rb
  2. 6
      spec/controllers/meeting_minutes_controller_spec.rb
  3. 48
      spec/controllers/meetings_controller_spec.rb
  4. 30
      spec/mailers/meeting_mailer_spec.rb
  5. 10
      spec/models/meeting_agenda_spec.rb
  6. 2
      spec/models/meeting_content_journal_spec.rb
  7. 8
      spec/models/meeting_minutes_spec.rb
  8. 48
      spec/models/meeting_spec.rb
  9. 42
      spec/models/user_deletion_spec.rb
  10. 2
      spec/routing/previews_routing_spec.rb
  11. 2
      spec/support/plugin_spec_helper.rb

@ -20,11 +20,11 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe MeetingAgendasController do describe MeetingAgendasController, :type => :controller do
let(:meeting) { FactoryGirl.create(:meeting) } let(:meeting) { FactoryGirl.create(:meeting) }
let(:user) { FactoryGirl.create(:admin) } let(:user) { FactoryGirl.create(:admin) }
before { User.stub(:current).and_return(user) } before { allow(User).to receive(:current).and_return(user) }
describe 'preview' do describe 'preview' do
let(:text) { "Meeting agenda content" } let(:text) { "Meeting agenda content" }

@ -20,16 +20,16 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe MeetingMinutesController do describe MeetingMinutesController, :type => :controller do
let(:meeting) { FactoryGirl.create(:meeting) } let(:meeting) { FactoryGirl.create(:meeting) }
let(:user) { FactoryGirl.create(:admin) } let(:user) { FactoryGirl.create(:admin) }
before { User.stub(:current).and_return(user) } before { allow(User).to receive(:current).and_return(user) }
describe 'preview' do describe 'preview' do
let(:text) { "Meeting minutes content" } let(:text) { "Meeting minutes content" }
before { MeetingMinutes.any_instance.stub(:editable?).and_return(true) } before { allow_any_instance_of(MeetingMinutes).to receive(:editable?).and_return(true) }
it_behaves_like 'valid preview' do it_behaves_like 'valid preview' do
let(:preview_texts) { [text] } let(:preview_texts) { [text] }

@ -20,79 +20,79 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe MeetingsController do describe MeetingsController, :type => :controller do
before(:each) do before(:each) do
@p = mock_model(Project) @p = mock_model(Project)
@controller.stub!(:authorize) allow(@controller).to receive(:authorize)
@controller.stub!(:check_if_login_required) allow(@controller).to receive(:check_if_login_required)
end end
describe "GET" do describe "GET" do
describe "index" do describe "index" do
before(:each) do before(:each) do
Project.stub!(:find).and_return(@p) allow(Project).to receive(:find).and_return(@p)
@ms = [mock_model(Meeting), mock_model(Meeting), mock_model(Meeting)] @ms = [mock_model(Meeting), mock_model(Meeting), mock_model(Meeting)]
@ms.stub!(:from_tomorrow).and_return(@ms) allow(@ms).to receive(:from_tomorrow).and_return(@ms)
@p.stub!(:meetings).and_return(@ms) allow(@p).to receive(:meetings).and_return(@ms)
[:with_users_by_date, :page, :per_page].each do |meth| [:with_users_by_date, :page, :per_page].each do |meth|
@ms.should_receive(meth).and_return(@ms) expect(@ms).to receive(meth).and_return(@ms)
end end
@grouped = double('grouped') @grouped = double('grouped')
Meeting.should_receive(:group_by_time).with(@ms).and_return(@grouped) expect(Meeting).to receive(:group_by_time).with(@ms).and_return(@grouped)
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "index", :project_id => @p.id get "index", :project_id => @p.id
end end
it {response.should be_success} it {expect(response).to be_success}
it {assigns(:meetings_by_start_year_month_date).should eql @grouped } it {expect(assigns(:meetings_by_start_year_month_date)).to eql @grouped }
end end
end end
describe "show" do describe "show" do
before(:each) do before(:each) do
@m = mock_model(Meeting) @m = mock_model(Meeting)
Meeting.stub!(:find).and_return(@m) allow(Meeting).to receive(:find).and_return(@m)
@m.stub!(:project).and_return(@p) allow(@m).to receive(:project).and_return(@p)
@m.stub!(:agenda).stub!(:present?).and_return(false) allow(allow(@m).to receive(:agenda)).to receive(:present?).and_return(false)
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "show", :id => @m.id get "show", :id => @m.id
end end
it {response.should be_success} it {expect(response).to be_success}
end end
end end
describe "new" do describe "new" do
before(:each) do before(:each) do
Project.stub!(:find).and_return(@p) allow(Project).to receive(:find).and_return(@p)
@m = mock_model(Meeting) @m = mock_model(Meeting)
@m.stub!(:project=) allow(@m).to receive(:project=)
@m.stub!(:author=) allow(@m).to receive(:author=)
Meeting.stub!(:new).and_return(@m) allow(Meeting).to receive(:new).and_return(@m)
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "new", :project_id => @p.id get "new", :project_id => @p.id
end end
it {response.should be_success} it {expect(response).to be_success}
it {assigns(:meeting).should eql @m} it {expect(assigns(:meeting)).to eql @m}
end end
end end
describe "edit" do describe "edit" do
before(:each) do before(:each) do
@m = mock_model(Meeting) @m = mock_model(Meeting)
Meeting.stub!(:find).and_return(@m) allow(Meeting).to receive(:find).and_return(@m)
@m.stub(:project).and_return(@p) allow(@m).to receive(:project).and_return(@p)
end end
describe "html" do describe "html" do
before(:each) do before(:each) do
get "edit", :id => @m.id get "edit", :id => @m.id
end end
it {response.should be_success} it {expect(response).to be_success}
it {assigns(:meeting).should eql @m} it {expect(assigns(:meeting)).to eql @m}
end end
end end
end end

@ -20,7 +20,7 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe MeetingMailer do describe MeetingMailer, :type => :mailer do
let(:role) { FactoryGirl.create(:role, permissions: [:view_meetings]) } let(:role) { FactoryGirl.create(:role, permissions: [:view_meetings]) }
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:project) }
let(:author) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) } let(:author) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) }
@ -50,13 +50,13 @@ describe MeetingMailer do
it "renders the headers" do it "renders the headers" do
mail.subject.should include(meeting.project.name) expect(mail.subject).to include(meeting.project.name)
mail.subject.should include(meeting.title) expect(mail.subject).to include(meeting.title)
mail.to.should include(author.mail) expect(mail.to).to include(author.mail)
mail.from.should eq([Setting.mail_from]) expect(mail.from).to eq([Setting.mail_from])
mail.cc.should_not include(author.mail) expect(mail.cc).not_to include(author.mail)
mail.cc.should include(watcher1.mail) expect(mail.cc).to include(watcher1.mail)
mail.cc.should include(watcher2.mail) expect(mail.cc).to include(watcher2.mail)
end end
it "renders the text body" do it "renders the text body" do
@ -69,13 +69,13 @@ describe MeetingMailer do
end end
def check_meeting_mail_content(body) def check_meeting_mail_content(body)
body.should include(meeting.project.name) expect(body).to include(meeting.project.name)
body.should include(meeting.title) expect(body).to include(meeting.title)
body.should include(i18n.format_date meeting.start_date) expect(body).to include(i18n.format_date meeting.start_date)
body.should include(i18n.format_time meeting.start_time, false) expect(body).to include(i18n.format_time meeting.start_time, false)
body.should include(i18n.format_time meeting.end_time, false) expect(body).to include(i18n.format_time meeting.end_time, false)
body.should include(@participants[0].name) expect(body).to include(@participants[0].name)
body.should include(@participants[1].name) expect(body).to include(@participants[1].name)
end end
def save_and_open_mail_html_body(mail) def save_and_open_mail_html_body(mail)

@ -20,7 +20,7 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe "MeetingAgenda" do describe "MeetingAgenda", :type => :model do
before(:each) do before(:each) do
@a = FactoryGirl.build :meeting_agenda, :text => "Some content...\n\nMore content!\n\nExtraordinary content!!" @a = FactoryGirl.build :meeting_agenda, :text => "Some content...\n\nMore content!\n\nExtraordinary content!!"
end end
@ -32,7 +32,7 @@ describe "MeetingAgenda" do
@a.reload @a.reload
@a.lock! @a.lock!
@a.reload @a.reload
@a.locked.should be_true expect(@a.locked).to be_truthy
end end
end end
@ -43,7 +43,7 @@ describe "MeetingAgenda" do
@a.reload @a.reload
@a.unlock! @a.unlock!
@a.reload @a.reload
@a.locked.should be_false expect(@a.locked).to be_falsey
end end
end end
@ -51,11 +51,11 @@ describe "MeetingAgenda" do
describe "#editable?" do describe "#editable?" do
it "is editable when not locked" do it "is editable when not locked" do
@a.locked = false @a.locked = false
@a.editable?.should be_true expect(@a.editable?).to be_truthy
end end
it "is not editable when locked" do it "is not editable when locked" do
@a.locked = true @a.locked = true
@a.editable?.should be_false expect(@a.editable?).to be_falsey
end end
end end
end end

@ -22,7 +22,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'journal/meeting_content_journal' require 'journal/meeting_content_journal'
describe Journal do describe Journal, :type => :model do
include PluginSpecHelper include PluginSpecHelper
let(:journal) { FactoryGirl.build(:meeting_content_journal) } let(:journal) { FactoryGirl.build(:meeting_content_journal) }

@ -20,7 +20,7 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe "MeetingMinutes" do describe "MeetingMinutes", :type => :model do
before do before do
@min = FactoryGirl.build :meeting_minutes @min = FactoryGirl.build :meeting_minutes
end end
@ -33,7 +33,7 @@ describe "MeetingMinutes" do
end end
describe "with no agenda present" do describe "with no agenda present" do
it "is not editable" do it "is not editable" do
@min.editable?.should be_false expect(@min.editable?).to be_falsey
end end
end end
describe "with an agenda present" do describe "with an agenda present" do
@ -42,11 +42,11 @@ describe "MeetingMinutes" do
@mee.agenda = @a @mee.agenda = @a
end end
it "is not editable when the agenda is open" do it "is not editable when the agenda is open" do
@min.editable?.should be_false expect(@min.editable?).to be_falsey
end end
it "is editable when the agenda is closed" do it "is editable when the agenda is closed" do
@a.lock! @a.lock!
@min.editable?.should be_true expect(@min.editable?).to be_truthy
end end
end end
end end

@ -20,12 +20,12 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe Meeting do describe Meeting, :type => :model do
it {should belong_to :project} it {is_expected.to belong_to :project}
it {should belong_to :author} it {is_expected.to belong_to :author}
it {should validate_presence_of :title} it {is_expected.to validate_presence_of :title}
it {should validate_presence_of :start_time} it {is_expected.to validate_presence_of :start_time}
it {pending; should accept_nested_attributes_for :participants} # geht das? it {skip; is_expected.to accept_nested_attributes_for :participants} # geht das?
let(:project) { FactoryGirl.create(:project) } let(:project) { FactoryGirl.create(:project) }
let(:user1) { FactoryGirl.create(:user) } let(:user1) { FactoryGirl.create(:user) }
@ -43,34 +43,34 @@ describe Meeting do
end end
describe "to_s" do describe "to_s" do
it {@m.to_s.should == "dingens"} it {expect(@m.to_s).to eq("dingens")}
end end
describe "start_date" do describe "start_date" do
it {@m.start_date.should == Date.tomorrow} it {expect(@m.start_date).to eq(Date.tomorrow)}
end end
describe "start_month" do describe "start_month" do
it {@m.start_month.should == Date.tomorrow.month} it {expect(@m.start_month).to eq(Date.tomorrow.month)}
end end
describe "start_year" do describe "start_year" do
it {@m.start_year.should == Date.tomorrow.year} it {expect(@m.start_year).to eq(Date.tomorrow.year)}
end end
describe "end_time" do describe "end_time" do
it {@m.end_time.should == Date.tomorrow + 11.hours} it {expect(@m.end_time).to eq(Date.tomorrow + 11.hours)}
end end
describe "time-sorted finder" do describe "time-sorted finder" do
it {pending} it {skip}
end end
describe "Journalized Objects" do describe "Journalized Objects" do
before(:each) do before(:each) do
@project ||= FactoryGirl.create(:project_with_types) @project ||= FactoryGirl.create(:project_with_types)
@current = FactoryGirl.create(:user, :login => "user1", :mail => "user1@users.com") @current = FactoryGirl.create(:user, :login => "user1", :mail => "user1@users.com")
User.stub!(:current).and_return(@current) allow(User).to receive(:current).and_return(@current)
end end
it 'should work with meeting' do it 'should work with meeting' do
@ -78,7 +78,7 @@ describe Meeting do
initial_journal = @meeting.journals.first initial_journal = @meeting.journals.first
recreated_journal = @meeting.recreate_initial_journal! recreated_journal = @meeting.recreate_initial_journal!
initial_journal.identical?(recreated_journal).should be true expect(initial_journal.identical?(recreated_journal)).to be true
end end
end end
@ -90,7 +90,7 @@ describe Meeting do
end end
it "should contain the user" do it "should contain the user" do
meeting.all_changeable_participants.should == [user1] expect(meeting.all_changeable_participants).to eq([user1])
end end
end end
@ -106,7 +106,7 @@ describe Meeting do
end end
it "should not contain the user" do it "should not contain the user" do
meeting.all_changeable_participants.include?(user2).should be_false expect(meeting.all_changeable_participants.include?(user2)).to be_falsey
end end
end end
@ -117,7 +117,7 @@ describe Meeting do
end end
it "should contain the user" do it "should contain the user" do
meeting.all_changeable_participants.include?(locked_user).should be_true expect(meeting.all_changeable_participants.include?(locked_user)).to be_truthy
end end
end end
end end
@ -133,7 +133,7 @@ describe Meeting do
meeting.save! meeting.save!
end end
it { meeting.watchers.collect(&:user).should =~ [user1, user2] } it { expect(meeting.watchers.collect(&:user)).to match_array([user1, user2]) }
end end
describe :close_agenda_and_copy_to_minutes do describe :close_agenda_and_copy_to_minutes do
@ -144,11 +144,11 @@ describe Meeting do
end end
it "should create a meeting with the agenda's text" do it "should create a meeting with the agenda's text" do
meeting.minutes.text.should == meeting.agenda.text expect(meeting.minutes.text).to eq(meeting.agenda.text)
end end
it "should close the agenda" do it "should close the agenda" do
meeting.agenda.locked?.should be_true expect(meeting.agenda.locked?).to be_truthy
end end
end end
@ -166,22 +166,22 @@ describe Meeting do
it "should have the same start_time as the original meeting" do it "should have the same start_time as the original meeting" do
copy = meeting.copy({}) copy = meeting.copy({})
copy.start_time.should == meeting.start_time expect(copy.start_time).to eq(meeting.start_time)
end end
it "should delete the copied meeting author if no author is given as parameter" do it "should delete the copied meeting author if no author is given as parameter" do
copy = meeting.copy({}) copy = meeting.copy({})
copy.author.should be_nil expect(copy.author).to be_nil
end end
it "should set the author to the provided author if one is given" do it "should set the author to the provided author if one is given" do
copy = meeting.copy :author => user2 copy = meeting.copy :author => user2
copy.author.should == user2 expect(copy.author).to eq(user2)
end end
it "should clear participant ids and attended flags for all copied attendees" do it "should clear participant ids and attended flags for all copied attendees" do
copy = meeting.copy({}) copy = meeting.copy({})
copy.participants.all?{ |p| p.id.nil? && !p.attended }.should be_true expect(copy.participants.all?{ |p| p.id.nil? && !p.attended }).to be_truthy
end end
end end
end end

@ -20,7 +20,7 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe User, "#destroy" do describe User, :type => :model, "#destroy" do
let(:user) { FactoryGirl.create(:user) } let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) } let(:user2) { FactoryGirl.create(:user) }
let(:substitute_user) { DeletedUser.first } let(:substitute_user) { DeletedUser.first }
@ -43,13 +43,13 @@ describe User, "#destroy" do
shared_examples_for "updated journalized associated object" do shared_examples_for "updated journalized associated object" do
before do before do
User.stub(:current).and_return(user2) allow(User).to receive(:current).and_return(user2)
associations.each do |association| associations.each do |association|
associated_instance.send(association.to_s + "=", user2) associated_instance.send(association.to_s + "=", user2)
end end
associated_instance.save! associated_instance.save!
User.stub(:current).and_return(user) # in order to have the content journal created by the user allow(User).to receive(:current).and_return(user) # in order to have the content journal created by the user
associated_instance.reload associated_instance.reload
associations.each do |association| associations.each do |association|
associated_instance.send(association.to_s + "=", user) associated_instance.send(association.to_s + "=", user)
@ -60,35 +60,35 @@ describe User, "#destroy" do
associated_instance.reload associated_instance.reload
end end
it { associated_class.find_by_id(associated_instance.id).should == associated_instance } it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
it "should replace the user on all associations" do it "should replace the user on all associations" do
associations.each do |association| associations.each do |association|
associated_instance.send(association).should == substitute_user expect(associated_instance.send(association)).to eq(substitute_user)
end end
end end
it { associated_instance.journals.first.user.should == user2 } it { expect(associated_instance.journals.first.user).to eq(user2) }
it "should update first journal changes" do it "should update first journal changes" do
associations.each do |association| associations.each do |association|
associated_instance.journals.first.changed_data[(association.to_s + "_id").to_sym].last.should == user2.id expect(associated_instance.journals.first.changed_data[(association.to_s + "_id").to_sym].last).to eq(user2.id)
end end
end end
it { associated_instance.journals.last.user.should == substitute_user } it { expect(associated_instance.journals.last.user).to eq(substitute_user) }
it "should update second journal changes" do it "should update second journal changes" do
associations.each do |association| associations.each do |association|
associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].last.should == substitute_user.id expect(associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].last).to eq(substitute_user.id)
end end
end end
end end
shared_examples_for "created journalized associated object" do shared_examples_for "created journalized associated object" do
before do before do
User.stub(:current).and_return(user) # in order to have the content journal created by the user allow(User).to receive(:current).and_return(user) # in order to have the content journal created by the user
associations.each do |association| associations.each do |association|
associated_instance.send(association.to_s + "=", user) associated_instance.send(association.to_s + "=", user)
end end
associated_instance.save! associated_instance.save!
User.stub(:current).and_return(user2) allow(User).to receive(:current).and_return(user2)
associated_instance.reload associated_instance.reload
associations.each do |association| associations.each do |association|
associated_instance.send(association.to_s + "=", user2) associated_instance.send(association.to_s + "=", user2)
@ -99,23 +99,23 @@ describe User, "#destroy" do
associated_instance.reload associated_instance.reload
end end
it { associated_class.find_by_id(associated_instance.id).should == associated_instance } it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
it "should keep the current user on all associations" do it "should keep the current user on all associations" do
associations.each do |association| associations.each do |association|
associated_instance.send(association).should == user2 expect(associated_instance.send(association)).to eq(user2)
end end
end end
it { associated_instance.journals.first.user.should == substitute_user } it { expect(associated_instance.journals.first.user).to eq(substitute_user) }
it "should update the first journal" do it "should update the first journal" do
associations.each do |association| associations.each do |association|
associated_instance.journals.first.changed_data[(association.to_s + "_id").to_sym].last.should == substitute_user.id expect(associated_instance.journals.first.changed_data[(association.to_s + "_id").to_sym].last).to eq(substitute_user.id)
end end
end end
it { associated_instance.journals.last.user.should == user2 } it { expect(associated_instance.journals.last.user).to eq(user2) }
it "should update the last journal" do it "should update the last journal" do
associations.each do |association| associations.each do |association|
associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].first.should == substitute_user.id expect(associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].first).to eq(substitute_user.id)
associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].last.should == user2.id expect(associated_instance.journals.last.changed_data[(association.to_s + "_id").to_sym].last).to eq(user2.id)
end end
end end
end end
@ -182,8 +182,8 @@ describe User, "#destroy" do
participant.reload participant.reload
end end
it { meeting.participants.map(&:user).should =~ [DeletedUser.first, user2] } it { expect(meeting.participants.map(&:user)).to match_array([DeletedUser.first, user2]) }
it { participant.invited.should be_true } it { expect(participant.invited).to be_truthy }
it { participant.attended.should be_true } it { expect(participant.attended).to be_truthy }
end end
end end

@ -28,7 +28,7 @@
require 'spec_helper' require 'spec_helper'
describe 'preview' do describe 'preview', :type => :routing do
it "should connect POST /meetings/:meeting_id/agenda/preview to meeting_agendas#preview" do it "should connect POST /meetings/:meeting_id/agenda/preview to meeting_agendas#preview" do
expect(post("/meetings/1/agenda/preview")).to route_to(controller: 'meeting_agendas', expect(post("/meetings/1/agenda/preview")).to route_to(controller: 'meeting_agendas',
meeting_id: '1', meeting_id: '1',

@ -33,7 +33,7 @@ module PluginSpecHelper
journal.reload journal.reload
end end
it { journal.changed_data[:text][1].should == text } it { expect(journal.changed_data[:text][1]).to eq(text) }
end end
end end
end end

Loading…
Cancel
Save