Merge branch 'likes'
* likes: Data model for "Like" Conflicts: app/models/user.rb db/schema.rb
This commit is contained in:
commit
c4b5b16e6f
@ -9,6 +9,7 @@ class Asciicast < ActiveRecord::Base
|
||||
|
||||
belongs_to :user
|
||||
has_many :comments, :order => :created_at, :dependent => :destroy
|
||||
has_many :likes, :dependent => :destroy
|
||||
|
||||
scope :featured, where(:featured => true)
|
||||
|
||||
|
4
app/models/like.rb
Normal file
4
app/models/like.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Like < ActiveRecord::Base
|
||||
belongs_to :asciicast, :counter_cache => true
|
||||
belongs_to :user
|
||||
end
|
@ -1,5 +1,9 @@
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
has_many :user_tokens, :dependent => :destroy
|
||||
has_many :asciicasts, :dependent => :destroy
|
||||
has_many :likes, :dependent => :destroy
|
||||
|
||||
validates :provider, :presence => true
|
||||
validates :uid, :presence => true
|
||||
validates :nickname, :presence => true
|
||||
|
14
db/migrate/20120406114956_create_likes.rb
Normal file
14
db/migrate/20120406114956_create_likes.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class CreateLikes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :likes do |t|
|
||||
t.integer :asciicast_id, :null => false
|
||||
t.integer :user_id, :null => false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :likes, :asciicast_id
|
||||
add_index :likes, :user_id
|
||||
add_index :likes, [:user_id, :asciicast_id]
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class AddLikesCountToAsciicast < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :asciicasts, :likes_count, :integer, :null => false, :default => 0
|
||||
add_index :asciicasts, :likes_count
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
@ -36,10 +36,12 @@ ActiveRecord::Schema.define(:version => 20120409142151) do
|
||||
t.string "username"
|
||||
t.text "snapshot"
|
||||
t.integer "comments_count", :default => 0, :null => false
|
||||
t.integer "likes_count", :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "asciicasts", ["created_at"], :name => "index_asciicasts_on_created_at"
|
||||
add_index "asciicasts", ["featured"], :name => "index_asciicasts_on_featured"
|
||||
add_index "asciicasts", ["likes_count"], :name => "index_asciicasts_on_likes_count"
|
||||
add_index "asciicasts", ["recorded_at"], :name => "index_asciicasts_on_recorded_at"
|
||||
add_index "asciicasts", ["user_id"], :name => "index_asciicasts_on_user_id"
|
||||
add_index "asciicasts", ["user_token"], :name => "index_asciicasts_on_user_token"
|
||||
@ -55,6 +57,17 @@ ActiveRecord::Schema.define(:version => 20120409142151) do
|
||||
add_index "comments", ["asciicast_id"], :name => "index_comments_on_asciicast_id"
|
||||
add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
|
||||
|
||||
create_table "likes", :force => true do |t|
|
||||
t.integer "asciicast_id", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "likes", ["asciicast_id"], :name => "index_likes_on_asciicast_id"
|
||||
add_index "likes", ["user_id", "asciicast_id"], :name => "index_likes_on_user_id_and_asciicast_id"
|
||||
add_index "likes", ["user_id"], :name => "index_likes_on_user_id"
|
||||
|
||||
create_table "user_tokens", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.string "token", :null => false
|
||||
|
8
spec/factories/likes.rb
Normal file
8
spec/factories/likes.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# Read about factories at http://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :like do
|
||||
asciicast_id 1
|
||||
user_id 1
|
||||
end
|
||||
end
|
4
spec/models/like_spec.rb
Normal file
4
spec/models/like_spec.rb
Normal file
@ -0,0 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Like do
|
||||
end
|
Loading…
Reference in New Issue
Block a user