Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added integration tests for companies/email_addresses

  • Loading branch information...
commit ecc74192196b6e23a7e3752b418613c5e6530140 1 parent 6062f11
@jcasimir jcasimir authored
View
9 app/views/companies/_email_addresses.html.erb
@@ -0,0 +1,9 @@
+<ul>
+ <% email_addresses.each do |email_address| %>
+ <li>
+ <%= email_address.address%>
+ <%= link_to "edit", edit_email_address_path(email_address) %>
+ <%= link_to "delete", email_address_path(email_address), :method => :delete, :id => "delete_email_address_#{email_address.id}" %>
+ </li>
+ <% end %>
+</ul>
View
4 app/views/companies/index.html.erb
@@ -3,10 +3,14 @@
<table>
<tr>
<th>Name</th>
+ <th>Email Addresses</th>
+ <th>Phone Numbers</th>
</tr>
<% for company in @companies %>
<tr>
<td><%= company.name %></td>
+ <td><%= render :partial => 'email_addresses', :object => company.email_addresses %>
+ <td><%= render :partial => 'phone_numbers', :object => company.phone_numbers %>
<td><%= link_to "Show", company %></td>
<td><%= link_to "Edit", edit_company_path(company) %></td>
<td><%= link_to "Destroy", company, :confirm => 'Are you sure?', :method => :delete %></td>
View
7 app/views/companies/show.html.erb
@@ -13,6 +13,13 @@
<%= link_to "Add a New Phone Number", new_phone_number_path(:company_id => @company), :id => "new_phone_number" %>
<p>
+ <strong>Email Addresses:</strong>
+ <%= render :partial => 'email_addresses', :object => @company.email_addresses %>
+</p>
+
+<%= link_to "Add a New Email Address", new_email_address_path(:company_id => @company), :id => "new_email_address" %>
+
+<p>
<%= link_to "Edit", edit_company_path(@company) %> |
<%= link_to "Destroy", @company, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View All", companies_path %>
View
81 spec/integration/companies_views_spec.rb
@@ -6,8 +6,8 @@
@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")
+ @company.email_addresses.create(:address => "john@doe.com")
+ @company.email_addresses.create(:address => "doe@john.com")
end
describe "when looking at the list of companies" do
@@ -15,11 +15,17 @@
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
+ it "should display email addresses" do
+ @company.email_addresses.each do |email_address|
+ page.should have_selector('li', :text => email_address.address)
+ end
+ end
+
+ it "should display phone numbers" do
+ @company.phone_numbers.each do |phone_number|
+ page.should have_selector('li', :text => phone_number.number)
+ end
+ end
end
describe "when looking at a single company" do
@@ -27,26 +33,26 @@
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 delete links for each email address" do
+ @company.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
+ @company.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|
@@ -70,14 +76,14 @@
end
end
- it "should show the person after deleting a phone number" do
+ it "should show the company 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
+ it "should show the company 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)
@@ -86,7 +92,7 @@
page.should have_selector('li', :text => sample_number)
end
- it "should show the person including the updated number after editing a phone number" do
+ it "should show the company including the updated number after editing a phone number" do
target = @company.phone_numbers.first
original_number = target.number
new_number = original_number.reverse
@@ -97,13 +103,12 @@
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
+
+ it "should show the company after deleting an email address" do
+ target = @company.email_addresses.first
+ page.click_link("delete_email_address_#{target.id}")
+ current_path.should == company_path(@company)
+ page.should_not have_link("delete_email_address_#{target.id}")
+ end
end
end

0 comments on commit ecc7419

Please sign in to comment.
Something went wrong with that request. Please try again.