# Copyright (c) 2008-2013 Michael Dvorkin and contributors. # # Fat Free CRM is freely distributable under the terms of MIT license. # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ require File.expand_path("../acceptance_helper.rb", __FILE__) feature 'Leads', %q{ In order to increase sales As a user I want to manage leads } do before(:each) do do_login_if_not_already(:first_name => 'Bill', :last_name => 'Murray') end scenario 'should view a list of leads' do 4.times { |i| FactoryGirl.create(:lead, :first_name => "L", :last_name => "Ead #{i}") } visit leads_page page.should have_content('L Ead 0') page.should have_content('L Ead 1') page.should have_content('L Ead 2') page.should have_content('L Ead 3') page.should have_content('Create Lead') end scenario 'should create a new lead', :js => true do visit leads_page click_link 'Create Lead' page.should have_selector('#lead_first_name', :visible => true) fill_in 'lead_first_name', :with => 'Mr' fill_in 'lead_last_name', :with => 'Lead' fill_in 'lead_email', :with => 'mr_lead@example.com' fill_in 'lead_phone', :with => '+44 1234 567890' click_link 'Comment' fill_in 'comment_body', :with => 'This is an important lead.' click_link('Status') select 'Contacted', :from => 'lead_status' click_button 'Create Lead' page.should have_content('Mr Lead') find('#leads').click_link('Mr Lead') page.should have_content('Contacted') page.should have_content('mr_lead@example.com') page.should have_content('+44 1234 567890') page.should have_content('This is an important lead.') click_link "Dashboard" page.should have_content("Bill Murray created lead Mr Lead") page.should have_content("Bill Murray created comment on Mr Lead") end scenario "remembers the comment field when the creation was unsuccessful", :js => true do visit leads_page click_link 'Create Lead' click_link 'Comment' fill_in 'comment_body', :with => 'This is an important lead.' click_button 'Create Lead' page.should have_field('comment_body', :with => 'This is an important lead.') end scenario 'should view and edit a lead', :js => true do FactoryGirl.create(:lead, :first_name => "Mr", :last_name => "Lead", :email => "mr_lead@example.com") visit leads_page click_link 'Mr Lead' page.should have_content('Mr Lead') click_link('Edit') fill_in 'lead_first_name', :with => 'Mrs' fill_in 'lead_phone', :with => '+44 0987 654321' click_link('Status') select 'Rejected', :from => 'lead_status' click_button 'Save Lead' find('#title').should have_content('Mrs Lead') click_link "Dashboard" page.should have_content("Bill Murray updated lead Mrs Lead") end scenario 'should delete a lead', :js => true do FactoryGirl.create(:lead, :first_name => "Mr", :last_name => "Lead", :email => "mr_lead@example.com") visit leads_page click_link 'Mr Lead' click_link 'Delete?' page.should have_content('Are you sure you want to delete this lead?') click_link 'Yes' page.should have_content('Mr Lead has been deleted.') page.should_not have_content('Mr Lead') page.should_not have_content('mr_lead@example.com') end scenario 'should search for a lead', :js => true do 2.times { |i| FactoryGirl.create(:lead, :first_name => "Lead", :last_name => "\##{i}", :email => "lead#{i}@example.com") } visit leads_page find('#leads').should have_content('Lead #0') find('#leads').should have_content('Lead #1') fill_in 'query', :with => 'Lead #0' find('#leads').should have_content('Lead #0') find('#leads').should_not have_content('Lead #1') fill_in 'query', :with => 'Lead' find('#leads').should have_content('Lead #0') find('#leads').should have_content('Lead #1') fill_in 'query', :with => 'Non-existant lead' find('#leads').should_not have_content('Lead #0') find('#leads').should_not have_content('Lead #1') end end