Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed form validation issue on asset landing pages, refactored form v…

…alidation specs

[#52 state:open]
  • Loading branch information...
commit 743ae60c0db014c6cd382c0abe2d761a738ccc25 1 parent 28adde7
@michaeldv michaeldv authored
View
2  CHANGELOG
@@ -7,6 +7,8 @@ then you win. –- Mahatma Gandhi
Sun, Jun 28, 2009
---------------------------------------------------------------------
- Another iteration on User Profiles; all users now have personal profile page.
+- Fixed form validation issue on asset landing pages.
+- Refactored form validation specs.
Sat, Jun 27, 2009
---------------------------------------------------------------------
View
3  app/stylesheets/rails.sass
@@ -24,6 +24,9 @@
.fieldWithErrors
input
+ :border
+ :bottom 1px solid lightpink
+ :right 1px solid lightpink
:background pink
// Flash messages.
View
2  app/views/accounts/update.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@account)
+id = called_from_landing_page? ? "edit_account" : dom_id(@account)
if @account.errors.empty?
if called_from_landing_page?
View
4 app/views/campaigns/update.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@campaign)
+id = called_from_landing_page? ? "edit_campaign" : dom_id(@campaign)
if @campaign.errors.empty?
if called_from_landing_page?
@@ -10,7 +10,7 @@ if @campaign.errors.empty?
page[id].visual_effect :highlight, :duration => 1.0
page << refresh_sidebar(:index, :filters)
end
-else
+else
page[id].replace_html :partial => "edit"
page.call "crm.date_select_popup", :campaign_starts_on
page.call "crm.date_select_popup", :campaign_ends_on
View
2  app/views/contacts/update.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@contact)
+id = called_from_landing_page? ? "edit_contact" : dom_id(@contact)
if @contact.errors.empty?
if called_from_landing_page?
View
2  app/views/leads/promote.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@lead)
+id = called_from_landing_page? ? "convert_lead" : dom_id(@lead)
if @lead.status == "converted"
if called_from_landing_page?
View
2  app/views/leads/update.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@lead)
+id = called_from_landing_page? ? "edit_lead" : dom_id(@lead)
if @lead.errors.empty?
if called_from_landing_page?
View
2  app/views/opportunities/update.js.rjs
@@ -1,4 +1,4 @@
-id = dom_id(@opportunity)
+id = called_from_landing_page? ? "edit_opportunity" : dom_id(@opportunity)
if @opportunity.errors.empty?
if called_from_landing_page?
View
2  public/stylesheets/rails.css
@@ -20,6 +20,8 @@
padding: 0px; }
.fieldWithErrors input {
+ border-bottom: 1px solid lightpink;
+ border-right: 1px solid lightpink;
background: pink; }
p.flash_warning, p.flash_error {
View
2  public/stylesheets/screen.css
@@ -516,6 +516,8 @@ tt {
padding: 0px; }
.fieldWithErrors input {
+ border-bottom: 1px solid lightpink;
+ border-right: 1px solid lightpink;
background: pink; }
p.flash_warning, p.flash_error {
View
122 spec/views/accounts/update.rjs_spec.rb
@@ -5,67 +5,93 @@
before(:each) do
login_and_assign
- @account = Factory(:account, :id => 42, :user => @current_user)
- assigns[:account] = @account
+
+ assigns[:account] = @account = Factory(:account, :user => @current_user)
assigns[:users] = [ @current_user ]
end
-
- it "no errors: should flip [edit_account] form when called from account landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
- render "accounts/update.js.rjs"
-
- response.should_not have_rjs("account_42")
- response.should include_text('crm.flip_form("edit_account"')
- end
- it "no errors: should update sidebar when called from account landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ describe "no errors:" do
+ describe "on account landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ end
+
+ it "should flip [edit_account] form" do
+ render "accounts/update.js.rjs"
+ response.should_not have_rjs("account_#{@account.id}")
+ response.should include_text('crm.flip_form("edit_account"')
+ end
- render "accounts/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "accounts/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
- it "no errors: should update sidebar when called from opportunities index page" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts"
+ describe "on accounts index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts"
+ end
- render "accounts/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=filters]")
- with_tag("div[id=recently]")
- end
- end
+ it "should update sidebar" do
+ render "accounts/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=filters]")
+ with_tag("div[id=recently]")
+ end
+ end
- it "no errors: should replace [edit_account] form with account partial and highligh it when called from account index" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts"
- render "accounts/update.js.rjs"
+ it "should replace [edit_account] form with account partial and highligh it" do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts"
+ render "accounts/update.js.rjs"
- response.should have_rjs("account_42") do |rjs|
- with_tag("li[id=account_42]")
+ response.should have_rjs("account_#{@account.id}") do |rjs|
+ with_tag("li[id=account_#{@account.id}]")
+ end
+ response.should include_text(%Q/$("account_#{@account.id}").visualEffect("highlight"/)
+ end
end
- response.should include_text('$("account_42").visualEffect("highlight"')
- end
+ end # no errors
- it "no errors: should update sidebar" do
- render "accounts/update.js.rjs"
-
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=recently]")
+ describe "validation errors:" do
+ before(:each) do
+ @account.errors.add(:error)
end
- end
-
- it "errors: should redraw the [edit_account] form and shake it" do
- @account.errors.add(:error)
- render "accounts/update.js.rjs"
+
+ describe "on account landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ end
+
+ it "should redraw the [edit_account] form and shake it" do
+ render "accounts/update.js.rjs"
- response.should have_rjs("account_42") do |rjs|
- with_tag("form[class=edit_account]")
+ response.should have_rjs("edit_account") do |rjs|
+ with_tag("form[class=edit_account]")
+ end
+ response.should include_text('$("edit_account").visualEffect("shake"')
+ response.should include_text('focus()')
+ end
end
- response.should include_text('$("account_42").visualEffect("shake"')
- response.should include_text('focus()')
- end
+
+ describe "on accounts index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts"
+ end
+
+ it "should redraw the [edit_account] form and shake it" do
+ render "accounts/update.js.rjs"
+ response.should have_rjs("account_#{@account.id}") do |rjs|
+ with_tag("form[class=edit_account]")
+ end
+ response.should include_text(%Q/$("account_#{@account.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+ end # errors
end
View
109 spec/views/campaigns/update.rjs_spec.rb
@@ -5,53 +5,84 @@
before(:each) do
login_and_assign
- @campaign = Factory(:campaign, :id => 42, :user => @current_user)
- assigns[:campaign] = @campaign
+ assigns[:campaign] = @campaign = Factory(:campaign, :user => @current_user)
assigns[:users] = [ @current_user ]
assigns[:status] = Setting.as_hash(:campaign_status)
assigns[:campaign_status_total] = { :called_off => 1, :completed => 1, :on_hold => 1, :planned => 1, :started => 1, :other => 1, :all => 6 }
end
- it "no errors: should flip [edit_campaign] form when called from campaign landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ describe "no errors:" do
+ describe "on landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
+
+ it "should flip [edit_campaign] form" do
+ render "campaigns/update.js.rjs"
+ response.should_not have_rjs("campaign_#{@campaign.id}")
+ response.should include_text('crm.flip_form("edit_campaign"')
+ end
- render "campaigns/update.js.rjs"
- response.should_not have_rjs("campaign_42")
- response.should include_text('crm.flip_form("edit_campaign"')
- end
-
- it "no errors: should update sidebar when called from campaign landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
-
- render "campaigns/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "campaigns/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
-
- it "no errors: should replace [Edit Campaign] with campaign partial and highligh it when called outside campaign landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/campaigns"
-
- render "campaigns/update.js.rjs"
- response.should have_rjs("campaign_42") do |rjs|
- with_tag("li[id=campaign_42]")
+
+ describe "on index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns"
+ end
+
+ it "should replace [Edit Campaign] with campaign partial and highligh it" do
+ render "campaigns/update.js.rjs"
+ response.should have_rjs("campaign_#{@campaign.id}") do |rjs|
+ with_tag("li[id=campaign_#{@campaign.id}]")
+ end
+ response.should include_text(%Q/$("campaign_#{@campaign.id}").visualEffect("highlight"/)
+ end
end
- response.should include_text('$("campaign_42").visualEffect("highlight"')
- end
-
- it "errors: should redraw the [edit_campaign] form and shake it" do
- @campaign.errors.add(:error)
-
- render "campaigns/update.js.rjs"
- response.should have_rjs("campaign_42") do |rjs|
- with_tag("form[class=edit_campaign]")
+ end # no errors
+
+ describe "validation errors:" do
+ describe "on landing page -" do
+ before(:each) do
+ @campaign.errors.add(:error)
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
+
+ it "should redraw the [edit_campaign] form and shake it" do
+ render "campaigns/update.js.rjs"
+ response.should have_rjs("edit_campaign") do |rjs|
+ with_tag("form[class=edit_campaign]")
+ end
+ response.should include_text('crm.date_select_popup("campaign_starts_on")')
+ response.should include_text('crm.date_select_popup("campaign_ends_on")')
+ response.should include_text('$("edit_campaign").visualEffect("shake"')
+ response.should include_text('focus()')
+ end
end
- response.should include_text('crm.date_select_popup("campaign_starts_on")')
- response.should include_text('crm.date_select_popup("campaign_ends_on")')
- response.should include_text('$("campaign_42").visualEffect("shake"')
- response.should include_text('focus()')
- end
+ describe "on index page -" do
+ before(:each) do
+ @campaign.errors.add(:error)
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns"
+ end
+
+ it "should redraw the [edit_campaign] form and shake it" do
+ render "campaigns/update.js.rjs"
+ response.should have_rjs("campaign_#{@campaign.id}") do |rjs|
+ with_tag("form[class=edit_campaign]")
+ end
+ response.should include_text('crm.date_select_popup("campaign_starts_on")')
+ response.should include_text('crm.date_select_popup("campaign_ends_on")')
+ response.should include_text(%Q/$("campaign_#{@campaign.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+ end # errors
end
View
168 spec/views/contacts/update.rjs_spec.rb
@@ -5,79 +5,137 @@
before(:each) do
login_and_assign
- @account = Factory(:account, :id => 987654)
- @contact = Factory(:contact, :id => 42, :user => @current_user)
- assigns[:contact] = @contact
+
+ assigns[:contact] = @contact = Factory(:contact, :user => @current_user)
assigns[:users] = [ @current_user ]
- assigns[:account] = @account
+ assigns[:account] = @account = Factory(:account)
assigns[:accounts] = [ @account ]
end
-
- it "no errors: should flip [edit_contact] form when called from contact landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/contacts/123"
- render "contacts/update.js.rjs"
- response.should_not have_rjs("contact_42")
- response.should include_text('crm.flip_form("edit_contact"')
- end
+ describe "no errors:" do
+ describe "on contact landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts/123"
+ end
- it "no errors: should update sidebar when called from contact landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/contacts/123"
+ it "should flip [edit_contact] form" do
+ render "contacts/update.js.rjs"
+ response.should_not have_rjs("contact_#{@contact.id}")
+ response.should include_text('crm.flip_form("edit_contact"')
+ end
- render "contacts/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
- it "no errors: should update sidebar when called from contacts index page" do
- request.env["HTTP_REFERER"] = "http://localhost/contacts"
+ describe "on contacts index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts"
+ end
+
+ it "should replace [Edit Contact] with contact partial and highligh it" do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts"
+
+ render "contacts/update.js.rjs"
+ response.should have_rjs("contact_#{@contact.id}") do |rjs|
+ with_tag("li[id=contact_#{@contact.id}]")
+ end
+ response.should include_text(%Q/$("contact_#{@contact.id}").visualEffect("highlight"/)
+ end
- render "contacts/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=recently]")
+ end
+ end
end
- end
- it "no errors: should update recently viewed items when called outside the contacts (i.e. embedded)" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ end
+
+ it "should replace [Edit Contact] with contact partial and highligh it" do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts"
+
+ render "contacts/update.js.rjs"
+ response.should have_rjs("contact_#{@contact.id}") do |rjs|
+ with_tag("li[id=contact_#{@contact.id}]")
+ end
+ response.should include_text(%Q/$("contact_#{@contact.id}").visualEffect("highlight"/)
+ end
- render "contacts/update.js.rjs"
- response.should have_rjs("recently") do |rjs|
- with_tag("div[class=caption]")
+ it "should update recently viewed items" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("recently") do |rjs|
+ with_tag("div[class=caption]")
+ end
+ end
end
- end
-
- it "no errors: should replace [Edit Contact] with contact partial and highligh it when called outside contact landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/contacts"
+ end # no errors
- render "contacts/update.js.rjs"
- response.should have_rjs("contact_42") do |rjs|
- with_tag("li[id=contact_42]")
+ describe "validation errors:" do
+ before(:each) do
+ @contact.errors.add(:error)
end
- response.should include_text('$("contact_42").visualEffect("highlight"')
- end
-
- it "errors: should redraw the [edit_contact] form and shake it" do
- @contact.errors.add(:error)
- render "contacts/update.js.rjs"
- response.should have_rjs("contact_42") do |rjs|
- with_tag("form[class=edit_contact]")
+ describe "on contact landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts/123"
+ end
+
+ it "should redraw the [edit_contact] form and shake it" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("edit_contact") do |rjs|
+ with_tag("form[class=edit_contact]")
+ end
+ response.should include_text('crm.create_or_select_account(false)')
+ response.should include_text('$("edit_contact").visualEffect("shake"')
+ response.should include_text('focus()')
+ end
end
- response.should include_text('crm.create_or_select_account(false)')
- response.should include_text('$("contact_42").visualEffect("shake"')
- response.should include_text('focus()')
- end
- it "errors: should show disabled accounts dropdown when called from accounts landing page" do
- @contact.errors.add(:error)
- request.env["HTTP_REFERER"] = ref = "http://localhost/accounts/123"
+ describe "on contacts index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/contacts"
+ end
- render "contacts/update.js.rjs"
- response.should include_text("crm.create_or_select_account(#{ref =~ /\/accounts\//})")
- end
+ it "should redraw the [edit_contact] form and shake it" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("contact_#{@contact.id}") do |rjs|
+ with_tag("form[class=edit_contact]")
+ end
+ response.should include_text('crm.create_or_select_account(false)')
+ response.should include_text(%Q/$("contact_#{@contact.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = @referer = "http://localhost/accounts/123"
+ end
+ it "errors: should show disabled accounts dropdown" do
+ render "contacts/update.js.rjs"
+ response.should include_text("crm.create_or_select_account(#{@referer =~ /\/accounts\//})")
+ end
+
+ it "should redraw the [edit_contact] form and shake it" do
+ render "contacts/update.js.rjs"
+ response.should have_rjs("contact_#{@contact.id}") do |rjs|
+ with_tag("form[class=edit_contact]")
+ end
+ response.should include_text(%Q/$("contact_#{@contact.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+ end # errors
end
View
170 spec/views/leads/promote.rjs_spec.rb
@@ -5,86 +5,138 @@
before(:each) do
login_and_assign
- @account = Factory(:account)
+
assigns[:users] = [ @current_user ]
- assigns[:account] = @account
+ assigns[:account] = @account = Factory(:account)
assigns[:accounts] = [ @account ]
assigns[:contact] = Factory(:contact)
assigns[:opportunity] = Factory(:opportunity)
assigns[:lead_status_total] = { :contacted => 1, :converted => 1, :new => 1, :rejected => 1, :other => 1, :all => 5 }
end
- it "converted: should flip [Convert Lead] form when called from lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads/123"
- assigns[:lead] = Factory(:lead, :id => 42, :status => "converted", :user => @current_user, :assignee => @current_user)
+ describe "no errors :" do
+ before(:each) do
+ assigns[:lead] = @lead = Factory(:lead, :status => "converted", :user => @current_user, :assignee => @current_user)
+ end
- render "leads/promote.js.rjs"
- response.should_not have_rjs("lead_42")
- response.should include_text('crm.flip_form("convert_lead"')
- end
+ describe "from lead landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads/123"
+ end
- it "converted: should update sidebar when called from lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads/123"
- assigns[:lead] = Factory(:lead, :id => 42, :status => "converted", :user => @current_user, :assignee => @current_user)
+ it "should flip [Convert Lead] form" do
+ render "leads/promote.js.rjs"
+ response.should_not have_rjs("lead_#{@lead.id}")
+ response.should include_text('crm.flip_form("convert_lead"')
+ end
- render "leads/promote.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
- it "converted: should update sidebar when called from leads index page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads"
- assigns[:lead] = Factory(:lead, :id => 42, :status => "converted", :user => @current_user, :assignee => @current_user)
+ describe "from lead index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads"
+ end
+
+ it "should replace [Convert Lead] with lead partial and highligh it" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("li[id=lead_#{@lead.id}]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("highlight"/)
+ end
- render "leads/promote.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=filters]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=filters]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("filters").visualEffect("shake"')
+ end
end
- response.should include_text('$("filters").visualEffect("shake"')
- end
- it "converted: should update recently viewed items when called outside the leads (i.e. embedded)" do
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
- assigns[:lead] = Factory(:lead, :id => 42, :status => "converted", :user => @current_user, :assignee => @current_user)
+ describe "from related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
- render "leads/promote.js.rjs"
- response.should have_rjs("recently") do |rjs|
- with_tag("div[class=caption]")
- end
- end
+ it "should replace [Convert Lead] with lead partial and highligh it" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("li[id=lead_#{@lead.id}]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("highlight"/)
+ end
- it "converted: should replace [Convert Lead] with lead partial and highligh it when called outside lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads"
- assigns[:lead] = Factory(:lead, :id => 42, :status => "converted", :user => @current_user, :assignee => @current_user)
+ it "should update recently viewed items" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("recently") do |rjs|
+ with_tag("div[class=caption]")
+ end
+ end
+ end
+ end # no errors
- render "leads/promote.js.rjs"
- response.should have_rjs("lead_42") do |rjs|
- with_tag("li[id=lead_42]")
+ describe "validation errors:" do
+ before(:each) do
+ assigns[:lead] = @lead = Factory(:lead, :status => "new", :user => @current_user, :assignee => @current_user)
end
- response.should include_text('$("lead_42").visualEffect("highlight"')
- end
- it "couldn't convert: should redraw the [Convert Lead] form and shake it" do
- assigns[:lead] = Factory(:lead, :id => 42, :status => "new", :user => @current_user, :assignee => @current_user)
-
- render "leads/promote.js.rjs"
- response.should have_rjs("lead_42") do |rjs|
- with_tag("form[class=edit_lead]")
+ describe "from lead landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads/123"
+ end
+
+ it "should redraw the [Convert Lead] form and shake it" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("convert_lead") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text(%Q/$("convert_lead").visualEffect("shake"/)
+ end
end
- response.should include_text('$("lead_42").visualEffect("shake"')
- end
- it "couldn't convert: should handle new or existing account and set up calendar field" do
- assigns[:lead] = Factory(:lead, :id => 42, :status => "new", :user => @current_user, :assignee => @current_user)
-
- render "leads/promote.js.rjs"
- response.should include_text("crm.create_or_select_account")
- response.should include_text('crm.date_select_popup("opportunity_closes_on")')
- response.should include_text('$("account_name").focus()')
- end
+ describe "from lead index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads"
+ end
+
+ it "should redraw the [Convert Lead] form and shake it" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("shake"/)
+ end
+ end
+
+ describe "from related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
+ it "should redraw the [Convert Lead] form and shake it" do
+ render "leads/promote.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("shake"/)
+ end
+ end
+
+ it "should handle new or existing account and set up calendar field" do
+ render "leads/promote.js.rjs"
+ response.should include_text("crm.create_or_select_account")
+ response.should include_text('crm.date_select_popup("opportunity_closes_on")')
+ response.should include_text('$("account_name").focus()')
+ end
+ end # errors
end
View
150 spec/views/leads/update.rjs_spec.rb
@@ -5,70 +5,126 @@
before(:each) do
login_and_assign
- @lead = Factory(:lead, :id => 42, :user => @current_user, :assignee => Factory(:user))
- assigns[:lead] = @lead
+ assigns[:lead] = @lead = Factory(:lead, :user => @current_user, :assignee => Factory(:user))
assigns[:users] = [ @current_user ]
assigns[:campaigns] = [ Factory(:campaign) ]
assigns[:lead_status_total] = { :contacted => 1, :converted => 1, :new => 1, :rejected => 1, :other => 1, :all => 5 }
end
-
- it "no errors: should flip [edit_lead] form when called from lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads/123"
- render "leads/update.js.rjs"
- response.should_not have_rjs("lead_42")
- response.should include_text('crm.flip_form("edit_lead"')
- end
+ describe "no errors:" do
+ describe "on landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads/123"
+ end
- it "no errors: should update sidebar when called from lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads/123"
+ it "should flip [edit_lead] form" do
+ render "leads/update.js.rjs"
+ response.should_not have_rjs("lead_#{@lead.id}")
+ response.should include_text('crm.flip_form("edit_lead"')
+ end
- render "leads/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
+ it "should update sidebar" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
- it "no errors: should update sidebar when called from leads index page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads"
+ describe "on index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads"
+ end
- render "leads/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=filters]")
- with_tag("div[id=recently]")
+ it "should replace [Edit Lead] with lead partial and highligh it" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("li[id=lead_#{@lead.id}]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("highlight"/)
+ end
+
+ it "should update sidebar" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=filters]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("filters").visualEffect("shake"')
+ end
end
- response.should include_text('$("filters").visualEffect("shake"')
- end
- it "no errors: should update recently viewed items when called outside the leads (i.e. embedded)" do
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
- render "leads/update.js.rjs"
- response.should have_rjs("recently") do |rjs|
- with_tag("div[class=caption]")
+ it "should replace [Edit Lead] with lead partial and highligh it" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("li[id=lead_#{@lead.id}]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("highlight"/)
+ end
+
+ it "should update recently viewed items" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("recently") do |rjs|
+ with_tag("div[class=caption]")
+ end
+ end
end
- end
-
- it "no errors: should replace [Edit Lead] with lead partial and highligh it when called outside lead landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/leads"
+ end # no errors
- render "leads/update.js.rjs"
- response.should have_rjs("lead_42") do |rjs|
- with_tag("li[id=lead_42]")
+ describe "validation errors :" do
+ before(:each) do
+ @lead.errors.add(:error)
end
- response.should include_text('$("lead_42").visualEffect("highlight"')
- end
-
- it "errors: should redraw the [edit_lead] form and shake it" do
- @lead.errors.add(:error)
- render "leads/update.js.rjs"
- response.should have_rjs("lead_42") do |rjs|
- with_tag("form[class=edit_lead]")
+ describe "on landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads/123"
+ end
+
+ it "should redraw the [edit_lead] form and shake it" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("edit_lead") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text('$("edit_lead").visualEffect("shake"')
+ response.should include_text('focus()')
+ end
end
- response.should include_text('$("lead_42").visualEffect("shake"')
- response.should include_text('focus()')
- end
+ describe "on index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/leads"
+ end
+
+ it "should redraw the [edit_lead] form and shake it" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
+ end
+
+ it "should redraw the [edit_lead] form and shake it" do
+ render "leads/update.js.rjs"
+ response.should have_rjs("lead_#{@lead.id}") do |rjs|
+ with_tag("form[class=edit_lead]")
+ end
+ response.should include_text(%Q/$("lead_#{@lead.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+ end # errors
end
View
168 spec/views/opportunities/update.rjs_spec.rb
@@ -5,83 +5,137 @@
before(:each) do
login_and_assign
- @account = Factory(:account, :id => 987654)
- @opportunity = Factory(:opportunity, :id => 42, :user => @current_user, :assignee => Factory(:user))
- assigns[:opportunity] = @opportunity
+
+ assigns[:opportunity] = @opportunity = Factory(:opportunity, :user => @current_user, :assignee => Factory(:user))
assigns[:users] = [ @current_user ]
- assigns[:account] = @account
+ assigns[:account] = @account = Factory(:account)
assigns[:accounts] = [ @account ]
assigns[:stage] = Setting.as_hash(:opportunity_stage)
- assigns[:opportunity_stage_total] = {:prospecting=>10, :final_review=>1, :qualification=>1, :won=>2, :all=>20, :analysis=>1, :lost=>0, :presentation=>2, :other=>0, :proposal=>1, :negotiation=>2}
+ assigns[:opportunity_stage_total] = { :prospecting => 10, :final_review => 1, :won => 2, :all => 20, :analysis => 1, :lost => 0, :presentation => 2, :other => 0, :proposal => 1, :negotiation => 2 }
end
-
- it "no errors: should flip [edit_opportunity] form when called from opportunity landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/opportunities/123"
- render "opportunities/update.js.rjs"
- response.should_not have_rjs("opportunity_42")
- response.should include_text('crm.flip_form("edit_opportunity"')
- end
+ describe "no errors:" do
+ describe "on opportunity landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/opportunities/123"
+ end
- it "no errors: should update sidebar when called from opportunity landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/opportunities/123"
+ it "should flip [edit_opportunity] form" do
+ render "opportunities/update.js.rjs"
+ response.should_not have_rjs("opportunity_#{@opportunity.id}")
+ response.should include_text('crm.flip_form("edit_opportunity"')
+ end
- render "opportunities/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=summary]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=summary]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("summary").visualEffect("shake"')
+ end
end
- response.should include_text('$("summary").visualEffect("shake"')
- end
- it "no errors: should update sidebar when called from opportunities index page" do
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
+ describe "on opportunities index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/opportunities"
+ end
+
+ it "should replace [Edit Opportunity] with opportunity partial and highligh it" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("opportunity_#{@opportunity.id}") do |rjs|
+ with_tag("li[id=opportunity_#{@opportunity.id}]")
+ end
+ response.should include_text(%Q/$("opportunity_#{@opportunity.id}").visualEffect("highlight"/)
+ end
- render "opportunities/update.js.rjs"
- response.should have_rjs("sidebar") do |rjs|
- with_tag("div[id=filters]")
- with_tag("div[id=recently]")
+ it "should update sidebar" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("sidebar") do |rjs|
+ with_tag("div[id=filters]")
+ with_tag("div[id=recently]")
+ end
+ response.should include_text('$("filters").visualEffect("shake"')
+ end
end
- response.should include_text('$("filters").visualEffect("shake"')
- end
- it "no errors: should update recently viewed items when called outside the opportunities (i.e. embedded)" do
- request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
+ end
- render "opportunities/update.js.rjs"
- response.should have_rjs("recently") do |rjs|
- with_tag("div[class=caption]")
+ it "should update recently viewed items" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("recently") do |rjs|
+ with_tag("div[class=caption]")
+ end
+ end
+
+ it "should replace [Edit Opportunity] with opportunity partial and highligh it" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("opportunity_#{@opportunity.id}") do |rjs|
+ with_tag("li[id=opportunity_#{@opportunity.id}]")
+ end
+ response.should include_text(%Q/$("opportunity_#{@opportunity.id}").visualEffect("highlight"/)
+ end
end
end
-
- it "no errors: should replace [Edit Opportunity] with opportunity partial and highligh it when called outside opportunity landing page" do
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
- render "opportunities/update.js.rjs"
- response.should have_rjs("opportunity_42") do |rjs|
- with_tag("li[id=opportunity_42]")
+ describe "validation errors:" do
+ before(:each) do
+ @opportunity.errors.add(:error)
end
- response.should include_text('$("opportunity_42").visualEffect("highlight"')
- end
-
- it "errors: should redraw the [edit_opportunity] form and shake it" do
- @opportunity.errors.add(:error)
- render "opportunities/update.js.rjs"
- response.should have_rjs("opportunity_42") do |rjs|
- with_tag("form[class=edit_opportunity]")
+ describe "on opportunity landing page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/opportunities/123"
+ end
+
+ it "should redraw the [edit_opportunity] form and shake it" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("edit_opportunity") do |rjs|
+ with_tag("form[class=edit_opportunity]")
+ end
+ response.should include_text('crm.create_or_select_account(false)')
+ response.should include_text('$("edit_opportunity").visualEffect("shake"')
+ response.should include_text('focus()')
+ end
end
- response.should include_text('crm.create_or_select_account(false)')
- response.should include_text('$("opportunity_42").visualEffect("shake"')
- response.should include_text('focus()')
- end
- it "errors: should show disabled accounts dropdown when called from accounts landing page" do
- @opportunity.errors.add(:error)
- request.env["HTTP_REFERER"] = ref = "http://localhost/accounts/123"
+ describe "on opportunities index page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = "http://localhost/opportunities"
+ end
- render "opportunities/update.js.rjs"
- response.should include_text("crm.create_or_select_account(#{ref =~ /\/accounts\//})")
- end
+ it "should redraw the [edit_opportunity] form and shake it" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("opportunity_#{@opportunity.id}") do |rjs|
+ with_tag("form[class=edit_opportunity]")
+ end
+ response.should include_text('crm.create_or_select_account(false)')
+ response.should include_text(%Q/$("opportunity_#{@opportunity.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+
+ describe "on related asset page -" do
+ before(:each) do
+ request.env["HTTP_REFERER"] = @referer = "http://localhost/accounts/123"
+ end
+ it "should show disabled accounts dropdown when called from accounts landing page" do
+ render "opportunities/update.js.rjs"
+ response.should include_text("crm.create_or_select_account(#{@referer =~ /\/accounts\//})")
+ end
+
+ it "should redraw the [edit_opportunity] form and shake it" do
+ render "opportunities/update.js.rjs"
+ response.should have_rjs("opportunity_#{@opportunity.id}") do |rjs|
+ with_tag("form[class=edit_opportunity]")
+ end
+ response.should include_text(%Q/$("opportunity_#{@opportunity.id}").visualEffect("shake"/)
+ response.should include_text('focus()')
+ end
+ end
+ end # errors
end
Please sign in to comment.
Something went wrong with that request. Please try again.