Skip to content

Commit

Permalink
Added relationships model
Browse files Browse the repository at this point in the history
  • Loading branch information
JessSumner committed Sep 3, 2015
1 parent 34ef597 commit be13d2d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 27 deletions.
2 changes: 2 additions & 0 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Relationship < ActiveRecord::Base
end
14 changes: 14 additions & 0 deletions app/views/shared/_homepage.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<%= render 'shared/user_info' %>
</section>
<section class="micropost_form">
<%= render 'shared/micropost_form' %>
</section>
</aside>
<div class="col-md-8">
<h3>Micropost Feed</h3>
<%= render 'shared/feed' %>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/shared/_welcome.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="center jumbotron">
<h1>Welcome to the Sample App</h1>

<h2>
This is the home page for the
<a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a> sample application.
</h2>

<%= link_to "Sign up now!" , signup_path , class: "btn btn-lg btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/' %>
29 changes: 2 additions & 27 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
<% if logged_in? %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<%= render 'shared/user_info' %>
</section>
<section class="micropost_form">
<%= render 'shared/micropost_form' %>
</section>
</aside>
<div class="col-md-8">
<h3>Micropost Feed</h3>
<%= render 'shared/feed' %>
</div>
</div>
<%= render 'shared/homepage' %>
<% else %>
<div class="center jumbotron">
<h1>Welcome to the Sample App</h1>

<h2>
This is the home page for the
<a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a> sample application.
</h2>

<%= link_to "Sign up now!" , signup_path , class: "btn btn-lg btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/' %>

<%= render 'shared/welcome' %>
<% end %>
13 changes: 13 additions & 0 deletions db/migrate/20150903200654_create_relationships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateRelationships < ActiveRecord::Migration
def change
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id

t.timestamps null: false
end
add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], unique: true
end
end
Binary file added test/fixtures/rails.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/fixtures/relationships.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
follower_id: 1
followed_id: 1

two:
follower_id: 1
followed_id: 1
7 changes: 7 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ archer:
activated: true
activated_at: <%= Time.zone.now %>

mallory:
name: Mallory Archer
email: [email protected]
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>

<% 30.times do |n| %>
user_<%= n %>:
name: <%= "User #{n}" %>
Expand Down
14 changes: 14 additions & 0 deletions test/integration/microposts_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ def setup
get user_path(users(:archer))
assert_select 'a', text: 'delete', count: 0
end

test "micropost sidebar count" do
log_in_as(@user)
get root_path
assert_match "33 microposts", response.body
#User with zero microposts
other_user = users(:mallory)
log_in_as(other_user)
get root_path
assert_match "0 microposts", response.body
other_user.microposts.create!(content: "I need a drink")
get root_path
assert_match "1 micropost", response.body
end
end
7 changes: 7 additions & 0 deletions test/models/relationship_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RelationshipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit be13d2d

Please sign in to comment.