forked from design-beginners/debeg-idea
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a feature to send likes for ideas #7
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
// Place all the styles related to the welcome controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
.likeLink { | ||
float: right; | ||
} | ||
|
||
.ideaLink { | ||
float: left; | ||
} | ||
|
||
.list-group-item { | ||
clear: both; | ||
} |
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,6 +1,7 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :idea | ||
belongs_to :user | ||
has_many :likes, as: :likeable | ||
|
||
validates :body, length: { maximum: 1000 }, presence: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class Idea < ActiveRecord::Base | ||
has_many :comments | ||
belongs_to :user | ||
has_many :likes, as: :likeable | ||
|
||
validates :title, length: { maximum: 100 }, presence: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Like < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :likeable, polymorphic: true | ||
|
||
validates :user_id, uniqueness: {scope: [:likeable_id, :likeable_type]} | ||
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
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,14 @@ | ||
class CreateLikes < ActiveRecord::Migration | ||
def change | ||
create_table :likes do |t| | ||
t.integer :likeable_id | ||
t.string :likeable_type | ||
t.belongs_to :user, index: true | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :likes, [:likeable_id, :likeable_type] | ||
add_index :likes, [:likeable_id, :likeable_type, :user_id], unique: true | ||
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,9 @@ | ||
# Read about factories at https://github.com/thoughtbot/factory_girl | ||
|
||
FactoryGirl.define do | ||
factory :like do | ||
likeable_id 1 | ||
likeable_type "MyString" | ||
user nil | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
require 'spec_helper' | ||
|
||
describe 'アイデアに「いいね!」を付けられるようにする' do | ||
let(:idea) { create :idea } | ||
|
||
context '未ログイン状態でトップページにアクセスしたとき' do | ||
before { visit root_path(idea) } | ||
|
||
it 'いいね!用のリンクが表示されていないこと' do | ||
expect(page).to have_no_css 'a.like' | ||
end | ||
end | ||
|
||
context 'ログイン状態でトップページにアクセスしたとき' do | ||
before do | ||
idea | ||
login | ||
visit root_path | ||
end | ||
|
||
context 'いいね!を付ける前のとき' do | ||
it 'いいね!用のリンクが表示されていること' do | ||
expect(page).to have_css 'a.like' | ||
end | ||
end | ||
|
||
context 'いいね!ボタンを押したとき' do | ||
before do | ||
click_link 'いいね!' | ||
end | ||
|
||
it '"いいね!を取り消す"と表示されていること' do | ||
expect(page).to have_css 'a.dislike' | ||
end | ||
|
||
it '"いいね!"した人の数が表示されていること' do | ||
expect(page).to have_content "(1 いいね!)" | ||
end | ||
|
||
it '"いいね!"を取り消すことができること' do | ||
click_link 'いいね!を取り消す' | ||
expect(page).to have_content "(0 いいね!)" | ||
expect(page).to have_css 'a.like' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
describe Like do | ||
it { should belong_to(:user) } | ||
it { should belong_to(:likeable) } | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATCH
ですかね