Set up the feed_item model
authorNeil Smith <neil.git@njae.me.uk>
Sun, 5 Jan 2014 14:43:50 +0000 (14:43 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Sun, 5 Jan 2014 14:43:50 +0000 (14:43 +0000)
Gemfile
Gemfile.lock
app/models/feed_item.rb [new file with mode: 0644]
db/migrate/20140104143920_create_feed_items.rb [new file with mode: 0644]
db/schema.rb [new file with mode: 0644]
db/seeds.rb
spec/models/feed_item_spec.rb [new file with mode: 0644]

diff --git a/Gemfile b/Gemfile
index b2b01de5bde2732ec56091d9f8329c2b04432cf5..97cdf06dc5f6c16d8092465dafaf34b6085ceda0 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -39,7 +39,19 @@ end
 # gem 'unicorn'
 
 # Use Capistrano for deployment
-gem 'capistrano', group: :development
+gem 'capistrano', group: :development
 
 # Use debugger
 # gem 'debugger', group: [:development, :test]
+
+group :development, :test do
+  gem "rspec-rails"
+end
+
+group :test do
+  gem "factory_girl_rails"
+  gem "cucumber-rails", :require => false
+  gem "capybara"
+  gem "database_cleaner"
+  gem "launchy"
+end
\ No newline at end of file
index 27136cc1ff0c6dc29f3d45fdf4e155f1b79b7b3e..8085b7962e13524fc14842f035d237eacbd32ae4 100644 (file)
@@ -25,9 +25,20 @@ GEM
       multi_json (~> 1.3)
       thread_safe (~> 0.1)
       tzinfo (~> 0.3.37)
+    addressable (2.3.5)
     arel (4.0.1)
     atomic (1.1.14)
     builder (3.1.4)
+    capistrano (3.0.1)
+      i18n
+      rake (>= 10.0.0)
+      sshkit (>= 0.0.23)
+    capybara (2.2.0)
+      mime-types (>= 1.16)
+      nokogiri (>= 1.3.3)
+      rack (>= 1.0.0)
+      rack-test (>= 0.5.4)
+      xpath (~> 2.0)
     coffee-rails (4.0.1)
       coffee-script (>= 2.2.0)
       railties (>= 4.0.0, < 5.0)
@@ -35,8 +46,28 @@ GEM
       coffee-script-source
       execjs
     coffee-script-source (1.6.3)
+    cucumber (1.3.10)
+      builder (>= 2.1.2)
+      diff-lcs (>= 1.1.3)
+      gherkin (~> 2.12)
+      multi_json (>= 1.7.5, < 2.0)
+      multi_test (>= 0.0.2)
+    cucumber-rails (1.4.0)
+      capybara (>= 1.1.2)
+      cucumber (>= 1.2.0)
+      nokogiri (>= 1.5.0)
+      rails (>= 3.0.0)
+    database_cleaner (1.2.0)
+    diff-lcs (1.2.5)
     erubis (2.7.0)
     execjs (2.0.2)
+    factory_girl (4.3.0)
+      activesupport (>= 3.0.0)
+    factory_girl_rails (4.3.0)
+      factory_girl (~> 4.3.0)
+      railties (>= 3.0.0)
+    gherkin (2.12.2)
+      multi_json (~> 1.3)
     hike (1.2.3)
     i18n (0.6.9)
     jbuilder (1.5.3)
@@ -46,12 +77,21 @@ GEM
       railties (>= 3.0, < 5.0)
       thor (>= 0.14, < 2.0)
     json (1.8.1)
+    launchy (2.4.2)
+      addressable (~> 2.3)
     mail (2.5.4)
       mime-types (~> 1.16)
       treetop (~> 1.4.8)
     mime-types (1.25.1)
+    mini_portile (0.5.2)
     minitest (4.7.5)
     multi_json (1.8.2)
+    multi_test (0.0.3)
+    net-scp (1.1.2)
+      net-ssh (>= 2.6.5)
+    net-ssh (2.7.0)
+    nokogiri (1.6.1)
+      mini_portile (~> 0.5.0)
     pg (0.17.1)
     polyglot (0.3.3)
     rack (1.5.2)
@@ -73,6 +113,18 @@ GEM
     rake (10.1.1)
     rdoc (3.12.2)
       json (~> 1.4)
+    rspec-core (2.14.7)
+    rspec-expectations (2.14.4)
+      diff-lcs (>= 1.1.3, < 2.0)
+    rspec-mocks (2.14.4)
+    rspec-rails (2.14.1)
+      actionpack (>= 3.0)
+      activemodel (>= 3.0)
+      activesupport (>= 3.0)
+      railties (>= 3.0)
+      rspec-core (~> 2.14.0)
+      rspec-expectations (~> 2.14.0)
+      rspec-mocks (~> 2.14.0)
     sass (3.2.13)
     sass-rails (4.0.1)
       railties (>= 4.0.0, < 5.0)
@@ -90,10 +142,17 @@ GEM
       actionpack (>= 3.0)
       activesupport (>= 3.0)
       sprockets (~> 2.8)
+    sshkit (1.3.0)
+      net-scp (>= 1.1.2)
+      net-ssh
+      term-ansicolor
+    term-ansicolor (1.2.2)
+      tins (~> 0.8)
     thor (0.18.1)
     thread_safe (0.1.3)
       atomic
     tilt (1.4.1)
+    tins (0.13.1)
     treetop (1.4.15)
       polyglot
       polyglot (>= 0.3.1)
@@ -103,16 +162,25 @@ GEM
     uglifier (2.4.0)
       execjs (>= 0.3.0)
       json (>= 1.8.0)
+    xpath (2.0.0)
+      nokogiri (~> 1.3)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
+  capistrano
+  capybara
   coffee-rails (~> 4.0.0)
+  cucumber-rails
+  database_cleaner
+  factory_girl_rails
   jbuilder (~> 1.2)
   jquery-rails
+  launchy
   pg
   rails (= 4.0.2)
+  rspec-rails
   sass-rails (~> 4.0.0)
   sdoc
   turbolinks
diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb
new file mode 100644 (file)
index 0000000..db0613d
--- /dev/null
@@ -0,0 +1,22 @@
+class FeedItem < ActiveRecord::Base
+  validates_presence_of :feed_name, :title, :description
+  validates_uniqueness_of :title, :scope => :feed_name
+  validate :feed_name_must_be_legal
+
+  def FeedItem.valid_feed_name?(feed_name)
+    Rack::Utils::escape(feed_name) == feed_name and
+      Rack::Utils::unescape(feed_name) == feed_name and
+      feed_name != 'index' and
+      feed_name != 'show' and
+      feed_name != 'update' and
+      feed_name != 'action'
+  end
+
+  private
+
+  def feed_name_must_be_legal
+    unless FeedItem.valid_feed_name?(feed_name)
+      errors.add(:feed_name, 'is invalid')
+    end
+  end
+end
diff --git a/db/migrate/20140104143920_create_feed_items.rb b/db/migrate/20140104143920_create_feed_items.rb
new file mode 100644 (file)
index 0000000..11b82c1
--- /dev/null
@@ -0,0 +1,12 @@
+class CreateFeedItems < ActiveRecord::Migration
+  def change
+    create_table :feed_items do |t|
+      t.string :feed_name
+      t.string :title
+      t.string :description
+
+      t.timestamps
+    end
+    add_index :feed_items, :feed_name
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644 (file)
index 0000000..7c01265
--- /dev/null
@@ -0,0 +1,29 @@
+# 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 that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20140104143920) do
+
+  # These are extensions that must be enabled in order to support this database
+  enable_extension "plpgsql"
+
+  create_table "feed_items", force: true do |t|
+    t.string   "feed_name"
+    t.string   "title"
+    t.string   "description"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
+  add_index "feed_items", ["feed_name"], name: "index_feed_items_on_feed_name", using: :btree
+
+end
index 4edb1e857ee6c203463c7fa0387aae32496ec93d..b557ca3757eb45d0815e33e939b9c6516a366532 100644 (file)
@@ -5,3 +5,12 @@
 #
 #   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
 #   Mayor.create(name: 'Emanuel', city: cities.first)
+
+FeedItem.delete_all
+(1..20).each do |item_number|
+  ('a'..'j').each do |feed_name|
+    FeedItem.create(:feed_name => "feed-#{feed_name}",
+      :title => "feed-#{feed_name}-item-" + sprintf("%02d", item_number),
+      :description => "Feed #{feed_name}, Item #{item_number} has a description")
+  end
+end
\ No newline at end of file
diff --git a/spec/models/feed_item_spec.rb b/spec/models/feed_item_spec.rb
new file mode 100644 (file)
index 0000000..68eddb0
--- /dev/null
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe FeedItem do
+  pending "add some examples to (or delete) #{__FILE__}"
+end