Skip to content

Commit

Permalink
Fixed form validation issue on asset landing pages, refactored form v…
Browse files Browse the repository at this point in the history
…alidation specs

[fatfreecrm#52 state:open]
  • Loading branch information
Mike Dvorkin committed Jun 29, 2009
1 parent 28adde7 commit 743ae60
Show file tree
Hide file tree
Showing 16 changed files with 598 additions and 312 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions app/stylesheets/rails.sass
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

.fieldWithErrors
input
:border
:bottom 1px solid lightpink
:right 1px solid lightpink
:background pink

// Flash messages.
Expand Down
2 changes: 1 addition & 1 deletion app/views/accounts/update.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
4 changes: 2 additions & 2 deletions app/views/campaigns/update.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/contacts/update.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/leads/promote.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/leads/update.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/opportunities/update.js.rjs
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 2 additions & 0 deletions public/stylesheets/rails.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions public/stylesheets/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
122 changes: 74 additions & 48 deletions spec/views/accounts/update.rjs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
109 changes: 70 additions & 39 deletions spec/views/campaigns/update.rjs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 743ae60

Please sign in to comment.