Add feed and item model and start with a feeds controller

This commit is contained in:
Aaron Mueller 2012-04-07 19:15:25 +02:00
parent 0427d66201
commit c1194b4d3c
15 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

View file

@ -0,0 +1,2 @@
class FeedsController < ApplicationController
end

View file

@ -0,0 +1,2 @@
module FeedsHelper
end

8
app/models/feed.rb Normal file
View file

@ -0,0 +1,8 @@
class Feed < ActiveRecord::Base
has_many :items
validates_uniqueness_of :url
validates_presence_of :title
scope :recent, order(:published, :asc).limit(10)
end

6
app/models/item.rb Normal file
View file

@ -0,0 +1,6 @@
class Item < ActiveRecord::Base
belongs_to :feed
validates_presence_of :title, :author, :content
validates_uniqueness_of :url
end

View file

@ -0,0 +1,10 @@
class CreateFeeds < ActiveRecord::Migration
def change
create_table :feeds do |t|
t.string :url
t.string :title
t.timestamps
end
end
end

View file

@ -0,0 +1,15 @@
class CreateItems < ActiveRecord::Migration
def change
create_table :items do |t|
t.string :title
t.string :url
t.string :author
t.text :content
t.time :published
t.references :feed
t.timestamps
end
end
end

34
db/schema.rb Normal file
View file

@ -0,0 +1,34 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120407165240) do
create_table "feeds", :force => true do |t|
t.string "url"
t.string "title"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "items", :force => true do |t|
t.string "title"
t.string "url"
t.string "author"
t.text "content"
t.time "published"
t.integer "feed_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end

9
test/fixtures/feeds.yml vendored Normal file
View file

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
uri: MyString
title: MyString
two:
uri: MyString
title: MyString

15
test/fixtures/items.yml vendored Normal file
View file

@ -0,0 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
title: MyString
url: MyString
author: MyString
content: MyText
published: 2012-04-07 18:52:40
two:
title: MyString
url: MyString
author: MyString
content: MyText
published: 2012-04-07 18:52:40

View file

@ -0,0 +1,7 @@
require 'test_helper'
class FeedsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

7
test/unit/feed_test.rb Normal file
View file

@ -0,0 +1,7 @@
require 'test_helper'
class FeedTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class FeedHelperTest < ActionView::TestCase
end

7
test/unit/item_test.rb Normal file
View file

@ -0,0 +1,7 @@
require 'test_helper'
class ItemTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end