Explorar el Código

Merge branch 'refs/heads/subscriptions'

Conflicts:
	app/models/layer.rb
	app/views/layers/show.html.haml
	config/routes.rb
	db/schema.rb
master
Adrian Short hace 11 años
padre
commit
62afe4a484
Se han modificado 20 ficheros con 144 adiciones y 63 borrados
  1. +3
    -0
      app/assets/javascripts/subscriptions.js.coffee
  2. +1
    -31
      app/controllers/feeds_controller.rb
  3. +1
    -2
      app/controllers/layers_controller.rb
  4. +46
    -0
      app/controllers/subscriptions_controller.rb
  5. +2
    -0
      app/helpers/subscriptions_helper.rb
  6. +2
    -1
      app/models/feed.rb
  7. +3
    -1
      app/models/layer.rb
  8. +5
    -0
      app/models/subscription.rb
  9. +0
    -9
      app/views/feeds/_form.html.haml
  10. +10
    -10
      app/views/layers/show.html.haml
  11. +16
    -0
      app/views/subscriptions/_form.html.haml
  12. +1
    -0
      config/application.rb
  13. +2
    -1
      config/routes.rb
  14. +7
    -0
      db/migrate/20130321173521_convert_feeds_layers_table_to_subscriptions.rb
  15. +5
    -0
      db/migrate/20130408142010_add_timestamps_to_subscriptions.rb
  16. +11
    -8
      db/schema.rb
  17. +11
    -0
      test/fixtures/subscriptions.yml
  18. +7
    -0
      test/functional/subscriptions_controller_test.rb
  19. +4
    -0
      test/unit/helpers/subscriptions_helper_test.rb
  20. +7
    -0
      test/unit/subscription_test.rb

+ 3
- 0
app/assets/javascripts/subscriptions.js.coffee Ver fichero

@@ -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/

+ 1
- 31
app/controllers/feeds_controller.rb Ver fichero

@@ -41,37 +41,7 @@ class FeedsController < ApplicationController
@feed = Feed.find(params[:id])
end

# POST /feeds
# POST /feeds.json
def create

Rails.logger.debug "Feed URL: %s" % params['feed']['feed_url']

if Feed.where(:feed_url => params['feed']['feed_url']).size == 1 # ensure this test returns the values we expect
Rails.logger.debug "Adding existing feed to a new layer"
@feed = Feed.where(:feed_url => params['feed']['feed_url']).first
@layer = Layer.find(params['feed']['new_layer_id']) # assumes that the specified layer exists
# Attach the existing feed to the specified layer (making sure we only add each one once)
@feed.layers << @layer unless @feed.layers.include?(@layer)
else
# Create a new feed
Rails.logger.debug "Creating a new feed"
@feed = Feed.new(params[:feed])
@layer = Layer.find(params['feed']['new_layer_id']) # assumes that the specified layer exists
@feed.layers << @layer unless @feed.layers.include?(@layer)
end

respond_to do |format|
if @feed.save
format.html { redirect_to @layer, notice: 'Feed added OK' }
format.json { render json: @feed, status: :created, location: @feed }
else
format.html { render action: "new" }
format.json { render json: @feed.errors, status: :unprocessable_entity }
end
end
end
# Feeds are created through the Subscriptions controller

# PUT /feeds/1
# PUT /feeds/1.json


+ 1
- 2
app/controllers/layers_controller.rb Ver fichero

@@ -16,8 +16,7 @@ class LayersController < ApplicationController
# GET /layers/1.json
def show
@layer = Layer.find(params[:id])
@feed = Feed.new
@feed.new_layer_id = @layer.id
@subscription = Subscription.new(:layer_id => @layer.id)

respond_to do |format|
format.html # show.html.erb


+ 46
- 0
app/controllers/subscriptions_controller.rb Ver fichero

@@ -0,0 +1,46 @@
class SubscriptionsController < ApplicationController
def create
Rails.logger.debug "Feed URL: %s" % params['subscription']['feed_url']

if Feed.where(:feed_url => params['subscription']['feed_url']).size == 1 # ensure this test returns the values we expect
Rails.logger.debug "Adding existing feed to a new layer"
@feed = Feed.where(:feed_url => params['subscription']['feed_url']).first
@layer = Layer.find(params['subscription']['layer_id']) # assumes that the specified layer exists
# Attach the existing feed to the specified layer (making sure we only add each one once)
# @feed.layers << @layer unless @feed.layers.include?(@layer)
else
# Create a new feed
Rails.logger.debug "Creating a new feed"
@feed = Feed.create(:feed_url => params[:subscription][:feed_url])
@layer = Layer.find(params['subscription']['layer_id']) # assumes that the specified layer exists
# @feed.layers << @layer unless @feed.layers.include?(@layer)
end

@subscription = Subscription.new(:feed => @feed, :layer => @layer)

begin
respond_to do |format|
if @subscription.save
format.html { redirect_to @layer, notice: 'Feed added OK' }
format.json { render json: @feed, status: :created, location: @feed }
else
format.html { render action: "new" }
format.json { render json: @feed.errors, status: :unprocessable_entity }
end
end
rescue ActiveRecord::RecordNotUnique
redirect_to @layer, alert: 'That feed is already on this layer'
end
end

def destroy
@subscription = Subscription.find(params[:id])
@layer = @subscription.layer
@subscription.destroy

respond_to do |format|
format.html { redirect_to @layer, notice: 'Subscription deleted OK' }
format.json { head :no_content }
end
end
end

+ 2
- 0
app/helpers/subscriptions_helper.rb Ver fichero

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

+ 2
- 1
app/models/feed.rb Ver fichero

@@ -1,6 +1,7 @@
class Feed < ActiveRecord::Base
has_many :posts, :dependent => :destroy
has_and_belongs_to_many :layers
has_many :subscriptions
has_many :layers, :through => :subscriptions, :uniq => true
attr_accessible :title, :url, :description, :generator, :last_fetched, :feed_url
attr_accessor :new_layer_id # non model attribute used when creating new feeds from within a layer



+ 3
- 1
app/models/layer.rb Ver fichero

@@ -1,6 +1,8 @@
class Layer < ActiveRecord::Base
has_many :subscriptions
has_many :feeds, :through => :subscriptions, :uniq => true

attr_accessible :name
has_and_belongs_to_many :feeds

# Unique name for Layar layer
def layar_name


+ 5
- 0
app/models/subscription.rb Ver fichero

@@ -0,0 +1,5 @@
class Subscription < ActiveRecord::Base
attr_accessor :feed_url
belongs_to :feed
belongs_to :layer
end

+ 0
- 9
app/views/feeds/_form.html.haml Ver fichero

@@ -8,17 +8,8 @@
- @feed.errors.full_messages.each do |msg|
%li= msg

.field
-#
= f.label :title
= f.text_field :title
.field
= f.label "URL"
= f.text_field :feed_url, :size => 120
= f.hidden_field :new_layer_id, :value => @feed.new_layer_id
= f.submit 'Save', :id => 'submit'
-#
.field
= f.label :last_fetched
= f.datetime_select :last_fetched
.actions

+ 10
- 10
app/views/layers/show.html.haml Ver fichero

@@ -12,7 +12,7 @@
%h2 Feeds

#new_feed
= render 'feeds/form'
= render 'subscriptions/form'

%p= link_to "Fetch all", :fetch_all, :class => "button"

@@ -25,21 +25,21 @@
%th
%th
- @layer_posts = 0
- @layer.feeds.each do |f|
- @layer_posts += f.posts.count
- @layer.subscriptions.each do |s|
- @layer_posts += s.feed.posts.count
%tr
%td
.feed_title
= link_to f.title, f
%td.right= f.posts.count
= link_to s.feed.title, s.feed
%td.right= s.feed.posts.count
%td
- if f.last_fetched.nil?
- if s.feed.last_fetched.nil?
never
- else
= (time_ago_in_words(f.last_fetched) + " ago").gsub(/ +/, "&nbsp;").html_safe
%td= link_to "Fetch", fetch_feed_url(f), :class => "button"
%td= link_to 'Edit', edit_feed_path(f), :class => "button"
%td= link_to 'Delete', delete_feed_layer_path(:feed_id => f.id), :confirm => "Delete #{f.title} from this layer?", :method => :delete, :class => "button"
= (time_ago_in_words(s.feed.last_fetched) + " ago").gsub(/ +/, "&nbsp;").html_safe
%td= link_to "Fetch", fetch_feed_url(s.feed), :class => "button"
%td= link_to 'Edit', edit_feed_path(s.feed), :class => "button"
%td= link_to 'Delete', s, :confirm => "Delete #{s.feed.title}?", :method => :delete, :class => "button"

%tr
%td


+ 16
- 0
app/views/subscriptions/_form.html.haml Ver fichero

@@ -0,0 +1,16 @@
= form_for @subscription do |f|
%h2 Add a feed

-if @subscription.errors.any?
#error_explanation
%h2= "#{pluralize(@subscription.errors.count, "error")} prohibited this feed from being saved:"
%ul
- @subscription.errors.full_messages.each do |msg|
%li= msg

.field
= f.label "URL"
= f.text_field :feed_url, :size => 120
= f.hidden_field :layer_id, :value => @subscription.layer.id
= f.submit 'Save', :id => 'submit'
.actions

+ 1
- 0
config/application.rb Ver fichero

@@ -75,6 +75,7 @@ module Apollo
# http://mongomapper.com/documentation/getting-started/rails.html
config.generators do |g|
g.template_engine :haml
g.stylesheets false
end
# Time.zone = 'London'
end


+ 2
- 1
config/routes.rb Ver fichero

@@ -11,10 +11,11 @@ Apollo::Application.routes.draw do
resources :users
resources :sessions
resources :password_resets
resources :subscriptions
get "posts/near"

resources :feeds, :except => :destroy do
resources :feeds, :except => [ :create, :destroy ] do
member do
get 'fetch'
end


+ 7
- 0
db/migrate/20130321173521_convert_feeds_layers_table_to_subscriptions.rb Ver fichero

@@ -0,0 +1,7 @@
class ConvertFeedsLayersTableToSubscriptions < ActiveRecord::Migration
def change
rename_table :feeds_layers, :subscriptions
add_column :subscriptions, :id, :primary_key
add_index :subscriptions, :id, :name => "id"
end
end

+ 5
- 0
db/migrate/20130408142010_add_timestamps_to_subscriptions.rb Ver fichero

@@ -0,0 +1,5 @@
class AddTimestampsToSubscriptions < ActiveRecord::Migration
def change
add_timestamps :subscriptions
end
end

+ 11
- 8
db/schema.rb Ver fichero

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130328153610) do
ActiveRecord::Schema.define(:version => 20130408142010) do

create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
@@ -40,13 +40,6 @@ ActiveRecord::Schema.define(:version => 20130328153610) do
t.datetime "last_fetched"
end

create_table "feeds_layers", :id => false, :force => true do |t|
t.integer "feed_id"
t.integer "layer_id"
end

add_index "feeds_layers", ["feed_id", "layer_id"], :name => "index_feeds_layers_on_feed_id_and_layer_id", :unique => true

create_table "layers", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
@@ -68,6 +61,16 @@ ActiveRecord::Schema.define(:version => 20130328153610) do
t.datetime "published"
end

create_table "subscriptions", :force => true do |t|
t.integer "feed_id"
t.integer "layer_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "subscriptions", ["feed_id", "layer_id"], :name => "index_feeds_layers_on_feed_id_and_layer_id", :unique => true
add_index "subscriptions", ["id"], :name => "id"

create_table "users", :force => true do |t|
t.string "email"
t.string "crypted_password"


+ 11
- 0
test/fixtures/subscriptions.yml Ver fichero

@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.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

+ 7
- 0
test/functional/subscriptions_controller_test.rb Ver fichero

@@ -0,0 +1,7 @@
require 'test_helper'

class SubscriptionsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

+ 4
- 0
test/unit/helpers/subscriptions_helper_test.rb Ver fichero

@@ -0,0 +1,4 @@
require 'test_helper'

class SubscriptionsHelperTest < ActionView::TestCase
end

+ 7
- 0
test/unit/subscription_test.rb Ver fichero

@@ -0,0 +1,7 @@
require 'test_helper'

class SubscriptionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

Cargando…
Cancelar
Guardar