Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished implementing scoping the display to just people owned by thi…

…s user
  • Loading branch information...
commit f97ca0c67cba46b2610f6aebf6dd4121acdcbfcf 1 parent 5b7569c
@jcasimir authored
View
2  app/controllers/people_controller.rb
@@ -2,7 +2,7 @@ class PeopleController < ApplicationController
before_filter :find_resource, :only => [:show, :destroy, :edit, :update]
def index
- @people = Person.all
+ @people = current_user.people
end
def show
View
2  app/views/people/index.html.haml
@@ -5,7 +5,7 @@
.people
- @people.each do |person|
.person
- %h4= link_to person, person
+ %h4= link_to person, person, :id => "person_#{person.id}"
= render :partial => 'email_addresses/email_addresses', :object => person.email_addresses
= render :partial => 'phone_numbers/phone_numbers', :object => person.phone_numbers
%ul.actions
View
3  spec/fabricators/email_address_fabricator.rb
@@ -0,0 +1,3 @@
+Fabricator(:email_address) do
+ address "sample@sample.com"
+end
View
5 spec/fabricators/person_fabricator.rb
@@ -2,4 +2,9 @@
first_name "John"
last_name "Doe"
user!
+end
+
+Fabricator(:person_with_details, :from => :person) do
+ email_addresses!(:count => 2){|person, i| Fabricate(:email_address, :address => "sample_#{i}@sample.com", :contact => person)}
+ phone_numbers!(:count => 2){|person, i| Fabricate(:phone_number, :number => "#{i.to_s*10}", :contact => person)}
end
View
3  spec/fabricators/phone_number_fabricator.rb
@@ -0,0 +1,3 @@
+Fabricator(:phone_number) do
+ number "2223334444"
+end
View
8 spec/fabricators/user_fabricator.rb
@@ -2,4 +2,12 @@
name "Sample User"
provider "twitter"
uid "123"
+end
+
+Fabricator(:user_with_people, :from => :user) do
+ people!(:count => 3){|user, i| Fabricate(:person, :first_name => "Sample", :last_name => "Person #{i}", :user => user) }
+end
+
+Fabricator(:user_with_people_with_details, :from => :user) do
+ people!(:count => 3){|user, i| Fabricate(:person_with_details, :first_name => "Sample", :last_name => "Person #{i}", :user => user) }
end
View
122 spec/integration/people_views_spec.rb
@@ -2,76 +2,84 @@
require 'capybara/rspec'
describe "the views for people", :type => :request do
- before(:all) do
- @person = Person.create(:first_name => "John", :last_name => "Doe")
- number_a = @person.phone_numbers.create(:number => "1234567")
- number_b = @person.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 people" do
+ describe "when logged in as a user" do
before(:all) do
- visit people_path
+ @user = Fabricate(:user_with_people_with_details)
+ login_as(@user)
end
+
+ describe "when looking at the list of people" do
+ before(:each) do
+ visit people_path
+ end
+
+ it "should display people associated with this user" do
+ @user.people.each do |person|
+ page.should have_link("person_#{person.id}")
+ end
+ end
- it "should display email addresses" do
- @person.email_addresses.each do |email_address|
- page.should have_selector('li', :text => email_address.address)
+ it "should display not display people associated with another user" do
+ @user_2 = Fabricate(:user_with_people)
+ visit(people_path)
+ @user_2.people.each do |person|
+ page.should_not have_link("person_#{person.id}")
+ end
end
end
- end
-
- describe "when looking at a single person" do
- before(:each) do
- visit person_path(@person)
- end
+
+ describe "when looking at a single person" do
+ before(:each) do
+ @person = @user.people.first
+ visit person_path(@person)
+ 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}")
+ 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
- end
- it "should have an add email address link" do
- page.should have_link("new_email_address")
- 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 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)
+ 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
- end
- it "should have edit links for each phone number" do
- @person.phone_numbers.each do |phone_number|
- page.should have_link("edit", :href => edit_phone_number_path(phone_number))
+ it "should have edit links for each phone number" do
+ @person.phone_numbers.each do |phone_number|
+ page.should have_link("edit", :href => edit_phone_number_path(phone_number))
+ end
+ end
+
+ it "should have delete links for each phone number" do
+ @person.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 = @person.phone_numbers.first
+ page.click_link("delete_phone_number_#{target.id}")
+ current_path.should == person_path(@person)
+ page.should_not have_link("delete", :href => phone_number_path(target))
+ 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
-
- it "should have delete links for each phone number" do
- @person.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 = @person.phone_numbers.first
- page.click_link("delete_phone_number_#{target.id}")
- current_path.should == person_path(@person)
- page.should_not have_link("delete", :href => phone_number_path(target))
- 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
View
9 spec/support/omniauth.rb
@@ -0,0 +1,9 @@
+def login_as(user)
+ OmniAuth.config.test_mode = true
+ OmniAuth.config.mock_auth[:twitter] = {
+ "provider" => user.provider,
+ "uid" => user.uid,
+ "user_info" => {"name"=>user.name}
+ }
+ visit(login_path)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.