This repository was archived by the owner on May 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] 『最新の情報を取得』 #14
Open
shiraryu
wants to merge
21
commits into
master
Choose a base branch
from
get-information
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] 『最新の情報を取得』 #14
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
093fa33
channelsテーブル追加
2fdccd6
外部キー修正
7f11b9e
テーブル修正
78b1ac7
migration整理
bc5b4e9
最新情報の取得ボタン追加
5c0ecd8
routes.rb記述修正
a9b62c0
fetch_items内修正(途中段階)
1173a64
fetch_items内でchanged使用
c3544d4
fetch_items内の更新を検知する
d1ba0e5
fetch_items内の修正(zipメソッド試験採用)
1dd4911
channel.items.firstによる分岐修正
38748bd
fetch_items内の無駄削除&修正
def2846
フィード登録時に自動取得
097f0fc
モデル内のメソッド名変更
aa9d946
create内のメソッド名修正
006f2a9
create & fetch_items内の記述を修正
df2b593
items_saveメソッドに関する記述修正
19e8f72
items_saveメソッドに関する記述再修正
69e0061
items_saveメソッド修正(create, fetch_itemsアクション内も)
5e084a6
消し忘れコード削除
0938d91
update_itemsに名称変更、self省略
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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,35 @@ | ||
require 'rss' | ||
# https://news.yahoo.co.jp/pickup/rss.xml | ||
# https://rss-weather.yahoo.co.jp/rss/days/7320.xml | ||
class ChannelsController < ApplicationController | ||
|
||
def index | ||
@channels = Channel.all | ||
end | ||
|
||
def new | ||
@channel = Channel.new | ||
end | ||
|
||
def create | ||
@channel = Channel.new(channel_params) | ||
if @channel.save | ||
@channel.update_items | ||
redirect_to channels_path | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def fetch_items | ||
channel = Channel.find(params[:channel_id]) | ||
channel.update_items | ||
redirect_to channels_path | ||
end | ||
|
||
private | ||
def channel_params | ||
params.require(:channel).permit(:url) | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,18 @@ | ||
class Channel < ApplicationRecord | ||
|
||
has_many :items, dependent: :destroy | ||
validates :url, format: /\A#{URI::regexp(%w(http https))}\z/ | ||
|
||
def update_items | ||
source_channel = RSS::Parser.parse(url).channel | ||
assign_attributes(title: source_channel.title, description: source_channel.description) | ||
save if changed? | ||
|
||
source_channel.items.each do |source_item| | ||
item = items.find_or_initialize_by(title: source_item.title) | ||
item.assign_attributes(link: source_item.link, pubdate: source_item.pubDate) | ||
item.save if item.changed? | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,3 @@ | ||
class Item < ApplicationRecord | ||
belongs_to :channel | ||
end |
3 changes: 2 additions & 1 deletion
3
app/views/feeds/index.html.erb → app/views/channels/index.html.erb
This file contains hidden or 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,12 +1,13 @@ | ||
<% @channels.each do |channel| %> | ||
<h3><strong><%= channel.title %></strong></h3> | ||
<h4><%= channel.description %><h4> | ||
<%= button_to '最新の情報を取得', channel_fetch_items_path(channel), :method => :get %> | ||
<% channel.items.each do |item| %> | ||
<p> | ||
<%= link_to item.link do %> | ||
<h4><strong><%= item.title %></strong></h4> | ||
<% end %> | ||
<%= time_ago_in_words(item.pubDate) %>前 | ||
<%= time_ago_in_words(item.pubdate) %>前 | ||
</p> | ||
<% end %> | ||
<% end %> |
8 changes: 4 additions & 4 deletions
8
app/views/feeds/new.html.erb → app/views/channels/new.html.erb
This file contains hidden or 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 hidden or 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,5 @@ | ||
Rails.application.routes.draw do | ||
resources :feeds, only: [:index, :new, :create] | ||
resources :channels, only: [:index, :new, :create] do | ||
get 'fetch_items' | ||
end | ||
end |
This file contains hidden or 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 hidden or 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,5 @@ | ||
class RenameFeedsToChannels < ActiveRecord::Migration[5.2] | ||
def change | ||
rename_table :feeds, :channels | ||
end | ||
end |
This file contains hidden or 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,12 @@ | ||
class CreateItems < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :items do |t| | ||
t.string :title | ||
t.string :link | ||
t.datetime :pubdate | ||
t.references :channel, foreign_key: true, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains hidden or 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 AddColumnToChannels < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :channels, :title, :string | ||
add_column :channels, :description, :string | ||
end | ||
end |
This file contains hidden or 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 hidden or 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,7 @@ | ||
require 'test_helper' | ||
|
||
class ChannelsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
File renamed without changes.
This file contains hidden or 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,11 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the '{}' from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value |
This file contains hidden or 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,19 @@ | ||
require 'test_helper' | ||
|
||
class ChannelTest < ActiveSupport::TestCase | ||
|
||
test "should save channel with valid url" do | ||
channel = Channel.new(url: "https://rss-weather.yahoo.co.jp/rss/days/7320.xml") | ||
assert channel.valid? | ||
end | ||
|
||
test "should not save feed when scheme is not http/https" do | ||
channel = Channel.new(url: "javascript:alert('XSS');//http://shiraishi.jp/") | ||
assert channel.invalid? | ||
end | ||
|
||
test "should not save channel without url" do | ||
channel = Channel.new | ||
assert channel.invalid? | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
test/controllers/feeds_controller_test.rb → test/models/item_test.rb
This file contains hidden or 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 hidden or 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.
一つのコミットにはその目的のものだけ含まれてるべきなので、こういう修正は「最新情報の取得ボタン追加」とは別のコミットにしましょう
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.
fixtures :allのコメント消したのもそう
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.
すいません、前回も指摘いただいていたのに、、、もっと注意して目的ごとにその都度コミットします!