update with changes from Production branch

This commit is contained in:
Lee Lawlor
2014-02-17 12:05:39 -05:00
parent 5b640cf9d8
commit a4937fb2e5
384 changed files with 14690 additions and 2242 deletions

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe AppsController do
end

View File

@ -0,0 +1,113 @@
require 'spec_helper'
describe ChannelsController do
describe "Logged In" do
before :each do
@user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel)
@user.channels.push @channel
@tag = FactoryGirl.create(:tag)
@apikey = FactoryGirl.create(:api_key)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
end
it "should show the channels private page" do
get :show, :id => @channel.id
response.should render_template(:private_show)
end
it "should allow a new channel to be created" do
post :create
response.should be_redirect
channel_id = Channel.find(:all).last.id
response.should redirect_to( channel_path(channel_id, :anchor => "channelsettings"))
end
it "should allow a channel to be edited" do
@channel.public_flag = true
put :update, id: @channel, channel: {name: 'new name'}, tags: FactoryGirl.attributes_for(:tag)
@channel.reload
@channel.name.should eq('new name')
response.should redirect_to channel_path(@channel.id)
end
it "should allow a channel to be deleted " do
delete :destroy, :id => @channel.id
response.should redirect_to channels_path
@channel_no_more = Channel.find_by_id(@channel.id)
@channel_no_more.should be_nil
end
end
describe "Not Logged In" do
before :each do
without_timestamping_of Channel do
@channel = FactoryGirl.create(:channel, :updated_at => Time.now - RATE_LIMIT_FREQUENCY.to_i.seconds, :public_flag => false)
end
@apikey = FactoryGirl.create(:api_key, :channel => @channel)
end
it "should only display public channels" do
get :public
response.should render_template('public')
end
it "should show paginated list of public channels as json" do
get :public, :format => :json
JSON.parse(response.body).keys.include?('pagination').should be_true
end
it "should show the channels public page" do
get :show, :id => @channel.id
response.should render_template(:public_show)
end
it "should redirect to login when creating a new channel" do
post :create
response.should be_redirect
response.should redirect_to(login_path)
response.status.should == 302
end
it "should be allowed to send data via get to update channel" do
get :post_data, {:key => "0S5G2O7FAB5K0J6Z", :field1 => "0", :status => "ThisIsATest"}
response.body.to_i.should > 0
response.should be_successful
end
if defined?(React)
describe "updates a channel and executes a TalkBack command" do
before :each do
@talkback = FactoryGirl.create(:talkback)
@command = FactoryGirl.create(:command)
@command2 = FactoryGirl.create(:command, :position => nil, :command_string => 'quote"test')
end
it 'returns the command string' do
post :post_data, {:key => '0S5G2O7FAB5K0J6Z', :field1 => '70', :talkback_key => @talkback.api_key}
response.body.should eq("MyString")
end
it 'returns JSON' do
post :post_data, {:key => '0S5G2O7FAB5K0J6Z', :field1 => '70', :talkback_key => @talkback.api_key, :format => 'json'}
JSON.parse(response.body)['command_string'].should eq("MyString")
JSON.parse(response.body)['position'].should eq(nil)
JSON.parse(response.body)['executed_at'].should_not eq(nil)
end
it 'returns XML' do
post :post_data, {:key => '0S5G2O7FAB5K0J6Z', :field1 => '70', :talkback_key => @talkback.api_key, :format => 'xml'}
Nokogiri::XML(response.body).css('command-string').text.should eq("MyString")
Nokogiri::XML(response.body).css('position').text.should eq('')
Nokogiri::XML(response.body).css('executed-at').text.should_not eq('')
end
end
end
end
end

View File

@ -1,5 +1,24 @@
require 'spec_helper'
describe ChartsController do
before :each do
@user = FactoryGirl.create(:user)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
@channel = FactoryGirl.create(:channel, :user => @user)
end
describe "responding to a GET index" do
render_views
it "has a 'select' selector for 'dynamic'" do
get :index, :channel_id => @channel.id
response.should be_successful
response.should have_selector("select#dynamic_0")
end
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe CommentsController do
end

View File

@ -1,5 +1,64 @@
require 'spec_helper'
describe FeedController do
before :each do
@user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel)
now = Time.utc(2013,1,1)
@feed1 = FactoryGirl.create(:feed, :field1 => 10, :channel => @channel, :created_at => now, :entry_id => 1)
@feed = FactoryGirl.create(:feed, :field1 => 10, :channel => @channel, :created_at => now, :entry_id => 2)
@feed = FactoryGirl.create(:feed, :field1 => 9, :channel => @channel, :created_at => now, :entry_id => 3)
@feed = FactoryGirl.create(:feed, :field1 => 7, :channel => @channel, :created_at => now, :entry_id => 4)
@feed = FactoryGirl.create(:feed, :field1 => 6, :channel => @channel, :created_at => now, :entry_id => 5)
@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.save
@user.channels.push @channel
@tag = FactoryGirl.create(:tag)
@apikey = FactoryGirl.create(:api_key)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
end
it "should get feeds" do
get :show, {id: @feed1.id, channel_id: @channel.id}
response.should be_successful
response.body.should eq("{\"created_at\":\"2013-01-01T00:00:00+00:00\",\"entry_id\":1}" )
end
it "should get last feed" 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}" )
end
it "should get feed last_average" do
get :last_average, {channel_id: @channel.id, average: 10}
response.should be_successful
jsonResponse = JSON.parse(response.body)
jsonResponse["field1"].should eq("7.285714285714286")
end
it "should get last_median" do
get :last_median, {channel_id: @channel.id, median: 10}
response.should be_successful
jsonResponse = JSON.parse(response.body)
jsonResponse["field1"].should eq("7.0")
end
it "should get last_sum" do
get :last_sum, {channel_id: @channel.id, sum: 10}
response.should be_successful
jsonResponse = JSON.parse(response.body)
jsonResponse["field1"].should eq("51.0")
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe MapsController do
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PipesController do
end

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe PluginsController do
before :each do
@user = FactoryGirl.create(:user)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
@plugin = FactoryGirl.create(:plugin, :user => @user)
@channel = FactoryGirl.create(:channel, :user => @user)
end
describe "GET 'private_plugins' for plugin" do
it "should return plugin windows" do
get 'private_plugins', :channel_id => @channel.id
response.should be_successful
end
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe TagsController do
end

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
require 'spec_helper'
describe UserSessionsController do
before :each do
@user = FactoryGirl.create(:user)
activate_authlogic
@user_session = UserSession.create(@user)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(@user_session)
end
describe "for logged in user" do
it "should logout the user" do
get 'destroy'
response.should redirect_to(root_path)
end
end
end
describe UserSessionsController do
before :each do
@user = FactoryGirl.create(:user)
activate_authlogic
# @user_session = UserSession.create(@user)
# controller.stub(:current_user).and_return(@user)
# controller.stub(:current_user_session).and_return(@user_session)
end
it "should allow a new user to login" do
get 'new'
response.should be_success
response.should render_template('new')
end
it "should create user session" do
post 'create' , {:userlogin => "", :user_session=>{"remember_me"=>"false", "login"=>@user.login, "password"=>"foobar", "remember_id"=>"1"}, "commit" => "Sign In"}
user_session = UserSession.find
user_session.should_not be_nil
user_session.user.should == @user
response.should redirect_to ('/channels')
end
end

View File

@ -0,0 +1,80 @@
require 'spec_helper'
describe UsersController do
before :each do
@user = FactoryGirl.create(:user)
# controller.stub(:current_user).and_return(@user)
# controller.stub(:current_user_session).and_return(true)
# @channel = FactoryGirl.create(:channel)
end
# create a valid authlogic session
#def create_valid_session
# activate_authlogic
# UserSession.create(@user, true) #create an authlogic session
#end
# get the curent_user
#def current_user; @current_user ||= @user; end
describe "api" do
render_views
it "should show login in public json info" do
get :profile, :glob => @user.login, :format => 'json'
JSON.parse(response.body)['login'].should eq(@user.login)
end
it "should not show email in public json info" do
get :profile, :glob => @user.login, :format => 'json'
JSON.parse(response.body)['email'].should eq(nil)
end
it "should show email in private json info" do
get :profile, :glob => @user.login, :format => 'json', :key => @user.api_key
JSON.parse(response.body)['email'].should eq(@user.email)
end
end
#describe "existing account" do
#render_views
#it "has a current_user" do
# create_valid_session
# current_user.should_not be_false
#end
#it "generates a new api_key" do
# create_valid_session
# old_key = @user.set_new_api_key!
# post :new_api_key
# response.should be_successful
# assigns[:user].api_key.should != old_key
#end
#end
describe "new account" do
render_views
it "assigns new user" do
get :new
response.should be_successful
response.should have_selector("#user_submit")
assigns[:user].should_not be_nil
end
it "should create a new user if user parameters are complete" do
post :create, :user => {"login"=>"xxx", "email"=>"xxx@insomnia-consulting.org", "time_zone"=>"Eastern Time (US & Canada)", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}
response.code.should == "302"
response.should redirect_to(channels_path)
end
it "should have a valid api_key" do
post :create, :user => {"login"=>"xxx", "email"=>"xxx@insomnia-consulting.org", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}
assigns[:user].api_key.length.should eq(16)
end
end
end

View File

@ -0,0 +1,136 @@
require 'spec_helper'
describe WindowsController do
before :each do
@user = FactoryGirl.create(:user)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
@channel = FactoryGirl.create(:channel, :user => @user)
@window = FactoryGirl.create(:window)
@channel.windows << @window
end
describe "PUT 'hide' for window" do
it "should update the show_flag on that window" do
put 'hide', :channel_id => @channel.id, :id => @window.id
response.should be_successful
end
end
describe "POST 'update'" do
it "should allow an update" do
post 'update', :channel_id => @channel.id, :page => "{\"col\":0,\"positions\":[#{@window.id}]}"
response.should be_success
end
end
describe "POST 'update' with invalid position" do
it "should fail" do
post 'update', :channel_id => @channel.id, :page => "{\"col\":0,\"positions\":[999]}"
response.should be_success
end
end
describe "When getting " do
it "should render private_windows json" do
get 'private_windows', :channel_id => @channel.id, :format => :json
response.should be_successful
end
it "should render show_flag = false" do
@channel.windows[0].show_flag = false
@channel.save
get 'hidden_windows', {:channel_id => @channel.id, :visibility_flag => "private" }, :format => :json
response.status.should == 200
end
end
end
describe WindowsController do
render_views
before :each do
@channel = FactoryGirl.create(:channel)
@window = FactoryGirl.create(:chart_window)
@window_detail = FactoryGirl.create(:chart_window_detail)
@window.window_detail = @window_detail
@channel.windows << @window
end
describe "POST 'update'" do
it "should fail with no current user" do
post 'update', :channel_id => @channel.id, :page => "{\"col\":0,\"positions\":[" + @window.id.to_s + "]}"
response.status.should == 302
end
end
describe "When getting " do
it "should render json" do
get 'index', :channel_id => @channel.id, :format => :json
response.status.should == 200
response.body == @channel.windows.to_json
end
it "should not render show_flag = false" do
@channel.windows.each do |window|
window.show_flag = false
end
saved = @channel.save
saved.should be_true
get 'index', :channel_id => @channel.id, :format => :json
response.status.should == 200
result = JSON.parse(response.body)
result.size.should == 0
end
end
describe "GET 'iframe' for window" do
it "should return html with gsub for iframe" do
get 'iframe', :channel_id => @channel.id, :id => @window.id
response.should be_success
response.body.should == "<iframe src=\"http://test.host/\"/>"
end
it "should render json" do
@channel.windows[0].show_flag = false
@channel.save
get 'index', :channel_id => @channel.id, :format => :json
response.status.should == 200
response.body == @channel.windows.to_json
end
end
describe "GET 'html' for window" do
it "should return html" do
get 'html', :channel_id => @channel.id, :id => @window.id
response.should be_success
response.body.should == "<iframe src=\"/\"/>"
end
end
describe "PUT 'hide' for window" do
it "should return a redirect to login_path for no current_user" do
put 'hide', :channel_id => @channel.id, :id => @window.id
response.should redirect_to(login_path)
end
end
end