fix feeds response for last entry

This commit is contained in:
Lee Lawlor 2014-06-05 10:52:49 -04:00
parent f1b75e348f
commit 341a49d3e9
2 changed files with 23 additions and 3 deletions

View File

@ -190,7 +190,14 @@ class FeedController < ApplicationController
elsif params[:format] == 'csv'
@csv_headers = Feed.select_options(@channel, params)
elsif (params[:format] == 'txt' || params[:format] == 'text' || params[:format] == 'html' || params[:format].blank?)
output = add_prepend_append(@feed["field#{params[:field_id]}"])
# if no field_id, just return the json feed
if params[:field_id].blank?
output = @feed.to_json
else
output = add_prepend_append(@feed["field#{params[:field_id]}"])
end
else
output = @feed.to_json
end

View File

@ -13,6 +13,7 @@ describe FeedController do
@feed = FactoryGirl.create(:feed, :field1 => 5, :channel => @channel, :created_at => now, :entry_id => 6)
@feed = FactoryGirl.create(:feed, :field1 => 4, :channel => @channel, :created_at => now, :entry_id => 7)
@channel.last_entry_id = @feed.entry_id
@channel.field1 = 'temp'
@channel.save
@user.channels.push @channel
@ -26,13 +27,25 @@ describe FeedController do
it "should get first feed" do
get :show, {id: @feed1.id, channel_id: @channel.id, format: 'json'}
response.should be_successful
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":1}" )
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":1,\"field1\":\"10\"}" )
end
it "should get last feed" do
get :show, {id: 'last', channel_id: @channel.id, format: 'json'}
response.should be_successful
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":7}" )
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":7,\"field1\":\"4\"}" )
end
it "should get last feed (html)" do
get :show, {id: 'last', channel_id: @channel.id, field_id: 1}
response.should be_successful
response.body.should eq("4" )
end
it "should get last feed (html), no field_id specified" do
get :show, {id: 'last', channel_id: @channel.id}
response.should be_successful
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":7,\"field1\":\"4\"}" )
end
it "should get feed last_average" do