Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented polymorphic connection between companies/people and email…
…_addresses/phone_numbers
- Loading branch information
Showing
15 changed files
with
179 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class EmailAddress < ActiveRecord::Base | ||
attr_accessible :address, :person_id | ||
attr_accessible :address, :contact_id, :contact_type | ||
|
||
belongs_to :person | ||
belongs_to :contact, :polymorphic => true | ||
|
||
validates_presence_of :address, :person | ||
validates_presence_of :address, :contact | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ul> | ||
<% phone_numbers.each do |phone_number| %> | ||
<li> | ||
<%= phone_number.number%> | ||
<%= link_to "edit", edit_phone_number_path(phone_number), :id => "edit_phone_number_#{phone_number.id}" %> | ||
<%= link_to "delete", phone_number_path(phone_number), :method => :delete, :id => "delete_phone_number_#{phone_number.id}" %> | ||
</li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
db/migrate/20110420161636_change_email_addresses_to_relate_to_polymorphic_contacts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ChangeEmailAddressesToRelateToPolymorphicContacts < ActiveRecord::Migration | ||
def self.up | ||
EmailAddress.destroy_all | ||
remove_column :email_addresses, :person_id | ||
add_column :email_addresses, :contact_id, :integer | ||
add_column :email_addresses, :contact_type, :string | ||
end | ||
|
||
def self.down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
require 'spec_helper' | ||
require 'capybara/rspec' | ||
|
||
describe "the views for companies", :type => :request do | ||
before(:all) do | ||
@company = Company.create(:name => "Sample Corp") | ||
number_a = @company.phone_numbers.create(:number => "1234567") | ||
number_b = @company.phone_numbers.create(:number => "7654321") | ||
#@person.email_addresses.create(:address => "john@doe.com") | ||
#@person.email_addresses.create(:address => "doe@john.com") | ||
end | ||
|
||
describe "when looking at the list of companies" do | ||
before(:all) do | ||
visit companies_path | ||
end | ||
|
||
# it "should display email addresses" do | ||
# @person.email_addresses.each do |email_address| | ||
# page.should have_selector('li', :text => email_address.address) | ||
# end | ||
# end | ||
end | ||
|
||
describe "when looking at a single company" do | ||
before(:each) do | ||
visit company_path(@company) | ||
end | ||
|
||
# it "should have delete links for each email address" do | ||
# @person.email_addresses.each do |email_address| | ||
# page.should have_link("delete_email_address_#{email_address.id}") | ||
# end | ||
# end | ||
# | ||
# it "should have an add email address link" do | ||
# page.should have_link("new_email_address") | ||
# end | ||
# | ||
# it "should go to the new email address form when the link is clicked" do | ||
# click_link "new_email_address" | ||
# current_path.should == new_email_address_path | ||
# end | ||
# | ||
# it "should display each of the email addresses" do | ||
# @person.email_addresses.each do |email_address| | ||
# page.should have_selector('li', :text => email_address.address) | ||
# end | ||
# end | ||
|
||
it "should have edit links for each phone number" do | ||
@company.phone_numbers.each do |phone_number| | ||
page.should have_link("edit", :href => edit_phone_number_path(phone_number)) | ||
end | ||
end | ||
|
||
it "should have an add phone number link" do | ||
page.should have_link("new_phone_number") | ||
end | ||
|
||
it "should display each of the phone numbers" do | ||
@company.phone_numbers.each do |phone_number| | ||
page.should have_selector('li', :text => phone_number.number) | ||
end | ||
end | ||
|
||
it "should have delete links for each phone number" do | ||
@company.phone_numbers.each do |phone_number| | ||
page.should have_link("delete", :href => phone_number_path(phone_number)) | ||
end | ||
end | ||
|
||
it "should show the person after deleting a phone number" do | ||
target = @company.phone_numbers.first | ||
page.click_link("delete_phone_number_#{target.id}") | ||
current_path.should == company_path(@company) | ||
page.should_not have_link("delete", :href => phone_number_path(target)) | ||
end | ||
|
||
it "should show the person including the new number after creating a phone number" do | ||
page.click_link("new_phone_number") | ||
sample_number = "3334445555" | ||
page.fill_in("phone_number_number", :with => sample_number) | ||
page.click_button("phone_number_submit") | ||
current_path.should == company_path(@company) | ||
page.should have_selector('li', :text => sample_number) | ||
end | ||
|
||
it "should show the person including the updated number after editing a phone number" do | ||
target = @company.phone_numbers.first | ||
original_number = target.number | ||
new_number = original_number.reverse | ||
page.click_link("edit_phone_number_#{target.id}") | ||
current_path.should == edit_phone_number_path(target) | ||
page.fill_in("phone_number_number", :with => new_number) | ||
page.click_button("phone_number_submit") | ||
current_path.should == company_path(@company) | ||
page.should have_selector('li', :text => new_number) | ||
end | ||
|
||
|
||
# it "should show the person after deleting an email address" do | ||
# target = @person.email_addresses.first | ||
# page.click_link("delete_email_address_#{target.id}") | ||
# current_path.should == person_path(@person) | ||
# page.should_not have_link("delete_email_address_#{target.id}") | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters