update with changes from Production branch
This commit is contained in:
		
							
								
								
									
										5
									
								
								spec/controllers/apps_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/controllers/apps_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe AppsController do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										113
									
								
								spec/controllers/channels_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								spec/controllers/channels_controller_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								spec/controllers/comments_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/controllers/comments_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe CommentsController do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								spec/controllers/maps_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/controllers/maps_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe MapsController do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										5
									
								
								spec/controllers/pipes_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/controllers/pipes_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe PipesController do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										20
									
								
								spec/controllers/plugins_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								spec/controllers/plugins_controller_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										5
									
								
								spec/controllers/tags_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/controllers/tags_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe TagsController do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										44
									
								
								spec/controllers/user_sessions_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								spec/controllers/user_sessions_controller_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										80
									
								
								spec/controllers/users_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								spec/controllers/users_controller_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										136
									
								
								spec/controllers/windows_controller_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								spec/controllers/windows_controller_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								spec/factories/api_key.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								spec/factories/api_key.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :api_key do
 | 
			
		||||
    api_key "0S5G2O7FAB5K0J6Z"
 | 
			
		||||
    write_flag true
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										11
									
								
								spec/factories/channel.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								spec/factories/channel.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :channel do
 | 
			
		||||
    name "Channel name"
 | 
			
		||||
    user_id 1
 | 
			
		||||
    last_entry_id 1
 | 
			
		||||
    video_type "youtube"
 | 
			
		||||
    video_id = "123345"
 | 
			
		||||
    # association :user
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								spec/factories/chart_window.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								spec/factories/chart_window.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
# Read about factories at http://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :chart_window do
 | 
			
		||||
    channel_id 1
 | 
			
		||||
    position 1
 | 
			
		||||
    html "<iframe src=\"/\"/>"
 | 
			
		||||
    col 0
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										20
									
								
								spec/factories/chart_window_details.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								spec/factories/chart_window_details.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: chart_window_details
 | 
			
		||||
#
 | 
			
		||||
#  id              :integer          not null, primary key
 | 
			
		||||
#  chart_window_id :integer
 | 
			
		||||
#  field_number    :integer
 | 
			
		||||
#  created_at      :datetime
 | 
			
		||||
#  updated_at      :datetime
 | 
			
		||||
#  options         :string(255)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Read about factories at http://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :chart_window_detail do
 | 
			
		||||
    chart_window_id 1
 | 
			
		||||
    field_number 1
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										12
									
								
								spec/factories/feed.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								spec/factories/feed.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :feed do
 | 
			
		||||
    field1 "foo"
 | 
			
		||||
    field2 "10"
 | 
			
		||||
    entry_id 1
 | 
			
		||||
    latitude "51.477222"
 | 
			
		||||
    longitude "0.0"
 | 
			
		||||
    created_at (Time.now - 20.minutes)
 | 
			
		||||
    updated_at (Time.now - 20.minutes)
 | 
			
		||||
    sequence(:status) {|n| "foo#{n}" }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										11
									
								
								spec/factories/plugin.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								spec/factories/plugin.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :plugin do
 | 
			
		||||
    name "Plugin Name"
 | 
			
		||||
    user_id 1
 | 
			
		||||
    html = "<html/>"
 | 
			
		||||
    css = "<style/>"
 | 
			
		||||
    js = "<script/>"
 | 
			
		||||
    private_flag = true
 | 
			
		||||
    # association :user
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										11
									
								
								spec/factories/plugin_window.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								spec/factories/plugin_window.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
# Read about factories at http://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :plugin_window do
 | 
			
		||||
    channel_id 1
 | 
			
		||||
    position 1
 | 
			
		||||
    html "<iframe ::OPTIONS::></iframe>"
 | 
			
		||||
    
 | 
			
		||||
    col 0
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										19
									
								
								spec/factories/plugin_window_details.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								spec/factories/plugin_window_details.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: plugin_window_details
 | 
			
		||||
#
 | 
			
		||||
#  id               :integer          not null, primary key
 | 
			
		||||
#  plugin_id        :integer
 | 
			
		||||
#  plugin_window_id :integer
 | 
			
		||||
#  created_at       :datetime
 | 
			
		||||
#  updated_at       :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Read about factories at https://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :plugin_window_detail do
 | 
			
		||||
    plugin_id 1
 | 
			
		||||
    plugin_window_id 1
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										17
									
								
								spec/factories/portlet_window_details.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								spec/factories/portlet_window_details.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: portlet_window_details
 | 
			
		||||
#
 | 
			
		||||
#  id                :integer          not null, primary key
 | 
			
		||||
#  portlet_window_id :integer
 | 
			
		||||
#  created_at        :datetime
 | 
			
		||||
#  updated_at        :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Read about factories at http://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :portlet_window_detail do
 | 
			
		||||
    portlet_window_id 1
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										5
									
								
								spec/factories/tag.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								spec/factories/tag.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :tag do
 | 
			
		||||
    name "Tag name"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										13
									
								
								spec/factories/user.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								spec/factories/user.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :user do
 | 
			
		||||
    sequence(:login) {|n| "name#{n}" }
 | 
			
		||||
    sequence(:email) {|n| "email#{n}@example.com" }
 | 
			
		||||
    password "foobar"
 | 
			
		||||
    password_confirmation {|u| u.password}
 | 
			
		||||
    bio ""
 | 
			
		||||
    website ""
 | 
			
		||||
    time_zone "London"
 | 
			
		||||
    api_key 'ED1HVHNEH2BZD0AB'
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								spec/factories/user_sessions.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								spec/factories/user_sessions.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :user_session do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										29
									
								
								spec/factories/windows.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								spec/factories/windows.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: windows
 | 
			
		||||
#
 | 
			
		||||
#  id           :integer          not null, primary key
 | 
			
		||||
#  channel_id   :integer
 | 
			
		||||
#  position     :integer
 | 
			
		||||
#  created_at   :datetime
 | 
			
		||||
#  updated_at   :datetime
 | 
			
		||||
#  html         :text
 | 
			
		||||
#  col          :integer
 | 
			
		||||
#  title        :string(255)
 | 
			
		||||
#  wtype        :string(255)
 | 
			
		||||
#  name         :string(255)
 | 
			
		||||
#  type         :string(255)
 | 
			
		||||
#  private_flag :boolean          default(FALSE)
 | 
			
		||||
#  show_flag    :boolean          default(TRUE)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Read about factories at http://github.com/thoughtbot/factory_girl
 | 
			
		||||
 | 
			
		||||
FactoryGirl.define do
 | 
			
		||||
  factory :window do
 | 
			
		||||
    channel_id 1
 | 
			
		||||
    position 1
 | 
			
		||||
    html "<iframe ::OPTIONS::></iframe>"
 | 
			
		||||
    col 0
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,15 +1,106 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
# Specs in this file have access to a helper object that includes
 | 
			
		||||
# the FeedHelper. For example:
 | 
			
		||||
#
 | 
			
		||||
# describe FeedHelper do
 | 
			
		||||
#   describe "string concat" do
 | 
			
		||||
#     it "concats two strings with spaces" do
 | 
			
		||||
#       helper.concat_strings("this","that").should == "this that"
 | 
			
		||||
#     end
 | 
			
		||||
#   end
 | 
			
		||||
# end
 | 
			
		||||
describe FeedHelper do
 | 
			
		||||
  pending "add some examples to (or delete) #{__FILE__}"
 | 
			
		||||
  describe "feed_select_data" do
 | 
			
		||||
    before :each do
 | 
			
		||||
      @channel = FactoryGirl.create(:channel)
 | 
			
		||||
    end
 | 
			
		||||
    it "extracts selection criteria from the request parameters with no time params" do
 | 
			
		||||
      #params = {:average => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
      only = Feed.select_options(@channel, params)
 | 
			
		||||
      only.should include(:created_at, :entry_id)
 | 
			
		||||
    end
 | 
			
		||||
    it "extracts selection criteria from the request parameters " do
 | 
			
		||||
      params = {:average => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
      only = Feed.select_options(@channel, params)
 | 
			
		||||
      only.should include(:created_at)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  describe "feeds_into_averages" do
 | 
			
		||||
    before :each do
 | 
			
		||||
      userAttr = FactoryGirl.attributes_for(:user)
 | 
			
		||||
      @user = User.create!(userAttr)
 | 
			
		||||
 | 
			
		||||
      @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
      now = Time.utc(2013,1,1)
 | 
			
		||||
      feed1 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now)
 | 
			
		||||
      feed2 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 5.minutes)
 | 
			
		||||
      feed3 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 8.minutes)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "averages feed values based on a timeslice" do
 | 
			
		||||
      feeds = Feed.find(:all, :order => :created_at)
 | 
			
		||||
      params = {:average => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
 | 
			
		||||
      timeslices = helper.feeds_into_averages(feeds, params)
 | 
			
		||||
      timeslices.size.should eq(2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  describe "feeds_into_median" do
 | 
			
		||||
    before :each do
 | 
			
		||||
      userAttr = FactoryGirl.attributes_for(:user)
 | 
			
		||||
      @user = User.create!(userAttr)
 | 
			
		||||
 | 
			
		||||
      @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
      now = Time.utc(2013,1,1)
 | 
			
		||||
      feed1 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now)
 | 
			
		||||
      feed2 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 5.minutes)
 | 
			
		||||
      feed3 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 8.minutes)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "median feed values based on a timeslice" do
 | 
			
		||||
      feeds = Feed.find(:all, :order => :created_at)
 | 
			
		||||
      params = {:median => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
 | 
			
		||||
      timeslices = helper.feeds_into_medians(feeds, params)
 | 
			
		||||
      timeslices.size.should eq(2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  describe "feeds_into_sums" do
 | 
			
		||||
    before :each do
 | 
			
		||||
      userAttr = FactoryGirl.attributes_for(:user)
 | 
			
		||||
      @user = User.create!(userAttr)
 | 
			
		||||
 | 
			
		||||
      @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
      now = Time.utc(2013,1,1)
 | 
			
		||||
      feed1 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now)
 | 
			
		||||
      feed2 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 5.minutes)
 | 
			
		||||
      feed3 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 8.minutes)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "sum feed values based on a timeslice" do
 | 
			
		||||
      feeds = Feed.find(:all, :order => :created_at)
 | 
			
		||||
      params = {:sum => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
 | 
			
		||||
      timeslices = helper.feeds_into_sums(feeds, params)
 | 
			
		||||
      timeslices.size.should eq(2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  describe "feeds_into_timescales" do
 | 
			
		||||
    before :each do
 | 
			
		||||
      userAttr = FactoryGirl.attributes_for(:user)
 | 
			
		||||
      @user = User.create!(userAttr)
 | 
			
		||||
 | 
			
		||||
      @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
      now = Time.utc(2013,1,1)
 | 
			
		||||
      feed1 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now)
 | 
			
		||||
      feed2 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 5.minutes)
 | 
			
		||||
      feed3 = FactoryGirl.create(:feed, :channel => @channel, :created_at => now - 8.minutes)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "timescale feed values based on a timeslice" do
 | 
			
		||||
      feeds = Feed.find(:all, :order => :created_at)
 | 
			
		||||
      params = {:timescale => 10}
 | 
			
		||||
      helper.stub(:params).and_return(params)
 | 
			
		||||
 | 
			
		||||
      timeslices = helper.feeds_into_timescales(feeds, params)
 | 
			
		||||
      timeslices.size.should eq(2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +1,23 @@
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe ApiKey do
 | 
			
		||||
  pending "add some examples to (or delete) #{__FILE__}"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: api_keys
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer(4)      not null, primary key
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  api_key    :string(16)
 | 
			
		||||
#  channel_id :integer(4)
 | 
			
		||||
#  user_id    :integer(4)
 | 
			
		||||
#  write_flag :boolean(1)      default(FALSE)
 | 
			
		||||
#  channel_id :integer
 | 
			
		||||
#  user_id    :integer
 | 
			
		||||
#  write_flag :boolean          default(FALSE)
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#  note       :string(255)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe ApiKey do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										127
									
								
								spec/models/channel_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								spec/models/channel_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,127 @@
 | 
			
		||||
# encoding: UTF-8
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: channels
 | 
			
		||||
#
 | 
			
		||||
#  id            :integer          not null, primary key
 | 
			
		||||
#  user_id       :integer
 | 
			
		||||
#  name          :string(255)
 | 
			
		||||
#  description   :string(255)
 | 
			
		||||
#  latitude      :decimal(15, 10)
 | 
			
		||||
#  longitude     :decimal(15, 10)
 | 
			
		||||
#  field1        :string(255)
 | 
			
		||||
#  field2        :string(255)
 | 
			
		||||
#  field3        :string(255)
 | 
			
		||||
#  field4        :string(255)
 | 
			
		||||
#  field5        :string(255)
 | 
			
		||||
#  field6        :string(255)
 | 
			
		||||
#  field7        :string(255)
 | 
			
		||||
#  field8        :string(255)
 | 
			
		||||
#  scale1        :integer
 | 
			
		||||
#  scale2        :integer
 | 
			
		||||
#  scale3        :integer
 | 
			
		||||
#  scale4        :integer
 | 
			
		||||
#  scale5        :integer
 | 
			
		||||
#  scale6        :integer
 | 
			
		||||
#  scale7        :integer
 | 
			
		||||
#  scale8        :integer
 | 
			
		||||
#  created_at    :datetime
 | 
			
		||||
#  updated_at    :datetime
 | 
			
		||||
#  elevation     :string(255)
 | 
			
		||||
#  last_entry_id :integer
 | 
			
		||||
#  public_flag   :boolean          default(FALSE)
 | 
			
		||||
#  options1      :string(255)
 | 
			
		||||
#  options2      :string(255)
 | 
			
		||||
#  options3      :string(255)
 | 
			
		||||
#  options4      :string(255)
 | 
			
		||||
#  options5      :string(255)
 | 
			
		||||
#  options6      :string(255)
 | 
			
		||||
#  options7      :string(255)
 | 
			
		||||
#  options8      :string(255)
 | 
			
		||||
#  social        :boolean          default(FALSE)
 | 
			
		||||
#  slug          :string(255)
 | 
			
		||||
#  status        :string(255)
 | 
			
		||||
#  url           :string(255)
 | 
			
		||||
#  video_id      :string(255)
 | 
			
		||||
#  video_type    :string(255)
 | 
			
		||||
#  clearing      :boolean          default(FALSE), not null
 | 
			
		||||
#  ranking       :integer
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Channel do
 | 
			
		||||
  it "should be valid" do
 | 
			
		||||
    channel = Channel.new
 | 
			
		||||
    channel.should be_valid
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should accept utf8" do
 | 
			
		||||
    channel = Channel.create(:name => "ǎ")
 | 
			
		||||
    channel.reload
 | 
			
		||||
    channel.name.should == "ǎ"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should have no plugins when created" do
 | 
			
		||||
    channel = Channel.create
 | 
			
		||||
    channel.set_windows
 | 
			
		||||
    channel.save
 | 
			
		||||
    channel.name.should == "Channel #{channel.id}"
 | 
			
		||||
    channel.windows.size.should == 2
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should have video iframe after updated" do
 | 
			
		||||
    channel = Channel.create!
 | 
			
		||||
    video_id = "xxxxxx"
 | 
			
		||||
    channel.assign_attributes({:video_id => video_id, :video_type => "youtube"})
 | 
			
		||||
    channel.set_windows
 | 
			
		||||
    channel.save
 | 
			
		||||
    window = channel.windows.where({:wtype => :video })
 | 
			
		||||
    window[0].html.should == "<iframe class=\"youtube-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"https://www.youtube.com/embed/xxxxxx?wmode=transparent\" frameborder=\"0\" wmode=\"Opaque\" ></iframe>"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should have private windows" do
 | 
			
		||||
    channel = Channel.create!
 | 
			
		||||
    channel.assign_attributes({:field1 => "Test"})
 | 
			
		||||
    channel.set_windows
 | 
			
		||||
    channel.save
 | 
			
		||||
    showFlag = true
 | 
			
		||||
    channel.private_windows(showFlag).count.should == 2 #2 private windows - 1 field and 1 status
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # this is necessary so that the existing API is not broken
 | 
			
		||||
  # https://thingspeak.com/channels/9/feed.json?results=10 should have 'channel' as the first key
 | 
			
		||||
  it "should include root in json by default" do
 | 
			
		||||
    channel = Channel.create
 | 
			
		||||
    channel.as_json.keys.include?('channel').should be_true
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should not include root using public_options" do
 | 
			
		||||
    channel = Channel.create
 | 
			
		||||
    channel.as_json(Channel.public_options).keys.include?('channel').should be_false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'testing scopes' do
 | 
			
		||||
    before :each do
 | 
			
		||||
      @public_channel = FactoryGirl.create(:channel, :public_flag => true, :last_entry_id => 10)
 | 
			
		||||
      @private_channel = FactoryGirl.create(:channel, :public_flag => false, :last_entry_id => 10)
 | 
			
		||||
    end
 | 
			
		||||
    it 'should show public channels' do
 | 
			
		||||
      channels = Channel.public_viewable
 | 
			
		||||
      channels.count.should == 1
 | 
			
		||||
    end
 | 
			
		||||
    it 'should show active channels' do
 | 
			
		||||
      channels = Channel.active
 | 
			
		||||
      channels.count.should == 2
 | 
			
		||||
    end
 | 
			
		||||
    it 'should show selected channels' do
 | 
			
		||||
      channels = Channel.by_array([@public_channel.id, @private_channel.id])
 | 
			
		||||
      channels.count.should == 2
 | 
			
		||||
    end
 | 
			
		||||
    it 'should show tagged channels' do
 | 
			
		||||
      @public_channel.save_tags('sensor')
 | 
			
		||||
      channels = Channel.with_tag('sensor')
 | 
			
		||||
      channels.count.should == 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										21
									
								
								spec/models/comment_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								spec/models/comment_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: comments
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  parent_id  :integer
 | 
			
		||||
#  body       :text
 | 
			
		||||
#  flags      :integer
 | 
			
		||||
#  user_id    :integer
 | 
			
		||||
#  ip_address :string(255)
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#  channel_id :integer
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Comment do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								spec/models/failedlogin_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								spec/models/failedlogin_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: failedlogins
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  login      :string(255)
 | 
			
		||||
#  password   :string(255)
 | 
			
		||||
#  ip_address :string(255)
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Failedlogin do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										18
									
								
								spec/models/header_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								spec/models/header_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: headers
 | 
			
		||||
#
 | 
			
		||||
#  id           :integer          not null, primary key
 | 
			
		||||
#  name         :string(255)
 | 
			
		||||
#  value        :string(255)
 | 
			
		||||
#  created_at   :datetime
 | 
			
		||||
#  updated_at   :datetime
 | 
			
		||||
#  thinghttp_id :integer
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Header do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								spec/models/pipe_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								spec/models/pipe_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: pipes
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  name       :string(255)      not null
 | 
			
		||||
#  url        :string(255)      not null
 | 
			
		||||
#  slug       :string(255)      not null
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#  parse      :string(255)
 | 
			
		||||
#  cache      :integer
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Pipe do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										134
									
								
								spec/models/plugin_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								spec/models/plugin_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: plugins
 | 
			
		||||
#
 | 
			
		||||
#  id           :integer          not null, primary key
 | 
			
		||||
#  name         :string(255)
 | 
			
		||||
#  user_id      :integer
 | 
			
		||||
#  html         :text
 | 
			
		||||
#  css          :text
 | 
			
		||||
#  js           :text
 | 
			
		||||
#  created_at   :datetime
 | 
			
		||||
#  updated_at   :datetime
 | 
			
		||||
#  private_flag :boolean          default(TRUE)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Plugin do
 | 
			
		||||
 | 
			
		||||
  before :each do
 | 
			
		||||
    @user = FactoryGirl.create(:user)
 | 
			
		||||
    @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
    @window = FactoryGirl.create(:plugin_window, :channel => @channel)
 | 
			
		||||
    
 | 
			
		||||
  end
 | 
			
		||||
  it "should be valid" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.should be_valid
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should confirm has_[public\private]_windows" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
 | 
			
		||||
    window = PluginWindow.new
 | 
			
		||||
    window.private_flag = true
 | 
			
		||||
    window.channel_id = 1
 | 
			
		||||
    plugin.windows << window
 | 
			
		||||
 | 
			
		||||
    plugin.has_private_windows(1).should be_true
 | 
			
		||||
    plugin.has_public_windows(1).should be_false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "new, public plugin should get 2 plugin windows" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private plugins have one window..
 | 
			
		||||
    #Public plugins have a private window and a public window
 | 
			
		||||
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
    
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "new, private window should not be showing" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.public?.should be_false
 | 
			
		||||
    #Private plugins have one window..
 | 
			
		||||
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(1)
 | 
			
		||||
    window = plugin.windows[0]
 | 
			
		||||
    window.show_flag.should be_false
 | 
			
		||||
    
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should destroy public windows when changing plugin from public to private" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.public?.should be_false
 | 
			
		||||
    #Private plugins have one window..
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(1)
 | 
			
		||||
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.save
 | 
			
		||||
    
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
 | 
			
		||||
    plugin.private_flag = true
 | 
			
		||||
    plugin.save
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should allow only private_windows to be retrieved" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private window has private_dashboard_visibility only
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
    plugin.private_dashboard_windows(@channel.id).size.should eq(1)
 | 
			
		||||
  end
 | 
			
		||||
  it "should allow only public_windows to be retrieved" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.private_flag = false
 | 
			
		||||
    plugin.public?.should be_true
 | 
			
		||||
    #Private window has private_dashboard_visibility only
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
    plugin.public_dashboard_windows(@channel.id).size.should eq(1)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should cascade delete to Window" do
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
 | 
			
		||||
    window_id = plugin.windows[0].id
 | 
			
		||||
 | 
			
		||||
    plugin.destroy
 | 
			
		||||
 | 
			
		||||
    windows = Window.find_all_by_id(window_id)
 | 
			
		||||
 | 
			
		||||
    windows.size.should eq(0)
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  it "should have windows associated with separate channels" do
 | 
			
		||||
    channel2 = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
    plugin = Plugin.new
 | 
			
		||||
    plugin.make_windows @channel.id, "localhost"
 | 
			
		||||
    plugin.make_windows channel2.id, "localhost"
 | 
			
		||||
    plugin.windows.size.should eq(2)
 | 
			
		||||
    plugin.private_dashboard_windows(@channel.id).size.should eq(1)
 | 
			
		||||
    plugin.private_dashboard_windows(channel2.id).size.should eq(1)
 | 
			
		||||
    
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										54
									
								
								spec/models/plugin_window_detail_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								spec/models/plugin_window_detail_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: plugin_window_details
 | 
			
		||||
#
 | 
			
		||||
#  id               :integer          not null, primary key
 | 
			
		||||
#  plugin_id        :integer
 | 
			
		||||
#  plugin_window_id :integer
 | 
			
		||||
#  created_at       :datetime
 | 
			
		||||
#  updated_at       :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe PluginWindowDetail do
 | 
			
		||||
  before :each do
 | 
			
		||||
    @channel = FactoryGirl.create(:channel)      
 | 
			
		||||
    @plugin = FactoryGirl.create(:plugin)      
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "should be valid" do
 | 
			
		||||
    winDetail = PluginWindowDetail.new
 | 
			
		||||
    winDetail.should be_valid
 | 
			
		||||
  end
 | 
			
		||||
  it "should allow windows plugin association" do
 | 
			
		||||
    window = Window.new_from @plugin, @channel.id, :private, "localhost"
 | 
			
		||||
    @plugin.windows << window
 | 
			
		||||
    @plugin.save
 | 
			
		||||
    window.should be_valid
 | 
			
		||||
 | 
			
		||||
    window.window_detail.should_not be_nil
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe PluginWindowDetail do
 | 
			
		||||
  before :each do
 | 
			
		||||
    @user = FactoryGirl.create(:user)
 | 
			
		||||
    @channel = FactoryGirl.create(:channel, :user => @user)
 | 
			
		||||
    @plugin = FactoryGirl.create(:plugin, :user => @user) 
 | 
			
		||||
  end
 | 
			
		||||
  it "should differentiate between public plugin_window and private plugin_window" do
 | 
			
		||||
 | 
			
		||||
    window = Window.new_from @plugin, @channel.id, true, "localhost"
 | 
			
		||||
    @plugin.windows << window
 | 
			
		||||
    @plugin.save
 | 
			
		||||
    plugin = PluginWindowDetail.find_all_by_plugin_id(@plugin.id)
 | 
			
		||||
    plugin.length.should == 1
 | 
			
		||||
 | 
			
		||||
    window = Window.new_from @plugin, @channel.id, false, "localhost"
 | 
			
		||||
    @plugin.windows << window
 | 
			
		||||
    @plugin.save
 | 
			
		||||
    plugin = PluginWindowDetail.find_all_by_plugin_id(@plugin.id)
 | 
			
		||||
    plugin.length.should == 2
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										15
									
								
								spec/models/tag_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								spec/models/tag_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: tags
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  name       :string(255)
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Tag do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										16
									
								
								spec/models/tagging_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								spec/models/tagging_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: taggings
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  tag_id     :integer
 | 
			
		||||
#  channel_id :integer
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Tagging do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										22
									
								
								spec/models/twitter_account_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								spec/models/twitter_account_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: twitter_accounts
 | 
			
		||||
#
 | 
			
		||||
#  id          :integer          not null, primary key
 | 
			
		||||
#  screen_name :string(255)
 | 
			
		||||
#  user_id     :integer
 | 
			
		||||
#  twitter_id  :integer
 | 
			
		||||
#  token       :string(255)
 | 
			
		||||
#  secret      :string(255)
 | 
			
		||||
#  created_at  :datetime
 | 
			
		||||
#  updated_at  :datetime
 | 
			
		||||
#  api_key     :string(17)       not null
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe TwitterAccount do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								spec/models/watching_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								spec/models/watching_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: watchings
 | 
			
		||||
#
 | 
			
		||||
#  id         :integer          not null, primary key
 | 
			
		||||
#  user_id    :integer
 | 
			
		||||
#  channel_id :integer
 | 
			
		||||
#  created_at :datetime
 | 
			
		||||
#  updated_at :datetime
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Watching do
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										29
									
								
								spec/models/window_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								spec/models/window_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
# == Schema Information
 | 
			
		||||
#
 | 
			
		||||
# Table name: windows
 | 
			
		||||
#
 | 
			
		||||
#  id           :integer          not null, primary key
 | 
			
		||||
#  channel_id   :integer
 | 
			
		||||
#  position     :integer
 | 
			
		||||
#  created_at   :datetime
 | 
			
		||||
#  updated_at   :datetime
 | 
			
		||||
#  html         :text
 | 
			
		||||
#  col          :integer
 | 
			
		||||
#  title        :string(255)
 | 
			
		||||
#  wtype        :string(255)
 | 
			
		||||
#  name         :string(255)
 | 
			
		||||
#  type         :string(255)
 | 
			
		||||
#  private_flag :boolean          default(FALSE)
 | 
			
		||||
#  show_flag    :boolean          default(TRUE)
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe Window do
 | 
			
		||||
  it "should be valid" do
 | 
			
		||||
    window = Window.new
 | 
			
		||||
    window.should be_valid
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								spec/routing/routing_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								spec/routing/routing_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
require "spec_helper"
 | 
			
		||||
 | 
			
		||||
describe "routes for Widgets" do
 | 
			
		||||
  it "routes / to the pages controller" do
 | 
			
		||||
    { :get => "/" }.should route_to(:controller => "pages", :action => "home")
 | 
			
		||||
  end
 | 
			
		||||
  it "routes /channels/:id to the channels controller" do
 | 
			
		||||
    { :get => "/channels/1" }.should route_to(:controller => "channels", :action => "show", :id => "1")
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										61
									
								
								spec/spec_helper.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								spec/spec_helper.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
 | 
			
		||||
ENV["RAILS_ENV"] ||= 'test'
 | 
			
		||||
require File.expand_path("../../config/environment", __FILE__)
 | 
			
		||||
require 'rspec/rails'
 | 
			
		||||
require 'authlogic/test_case'
 | 
			
		||||
 | 
			
		||||
include Authlogic::TestCase
 | 
			
		||||
 | 
			
		||||
# Requires supporting ruby files with custom matchers and macros, etc,
 | 
			
		||||
# in spec/support/ and its subdirectories.
 | 
			
		||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
 | 
			
		||||
 | 
			
		||||
RSpec.configure do |config|
 | 
			
		||||
  # == Mock Framework
 | 
			
		||||
  #
 | 
			
		||||
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
 | 
			
		||||
  #
 | 
			
		||||
  # config.mock_with :mocha
 | 
			
		||||
  # config.mock_with :flexmock
 | 
			
		||||
  # config.mock_with :rr
 | 
			
		||||
  config.mock_with :rspec
 | 
			
		||||
 | 
			
		||||
  # Use color in STDOUT
 | 
			
		||||
  config.color_enabled = true
 | 
			
		||||
 | 
			
		||||
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
 | 
			
		||||
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
 | 
			
		||||
 | 
			
		||||
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
 | 
			
		||||
  # examples within a transaction, remove the following line or assign false
 | 
			
		||||
  # instead of true.
 | 
			
		||||
  config.use_transactional_fixtures = false
 | 
			
		||||
  config.before(:suite) do
 | 
			
		||||
    DatabaseCleaner.strategy = :truncation
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  config.before(:each) do
 | 
			
		||||
    DatabaseCleaner.start
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  config.after(:each) do
 | 
			
		||||
    DatabaseCleaner.clean
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def ppp(obj)
 | 
			
		||||
  puts ERB::Util.html_escape(obj.pretty_inspect).gsub(" ", ' '*2).gsub("\t", ' '*4).gsub("\n", "<br />\n")
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def without_timestamping_of(*klasses)
 | 
			
		||||
    if block_given?
 | 
			
		||||
      klasses.delete_if { |klass| !klass.record_timestamps }
 | 
			
		||||
      klasses.each { |klass| klass.record_timestamps = false }
 | 
			
		||||
      begin
 | 
			
		||||
        yield
 | 
			
		||||
      ensure
 | 
			
		||||
        klasses.each { |klass| klass.record_timestamps = true  }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								spec/support/matchers/simple_matcher.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								spec/support/matchers/simple_matcher.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
RSpec::Matchers.define :be_even do
 | 
			
		||||
 match do |given|
 | 
			
		||||
   given % 2 == 0
 | 
			
		||||
 end
 | 
			
		||||
 
 | 
			
		||||
 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
RSpec::Matchers.define :have_ids_of do |objects|
 | 
			
		||||
 match do |given|
 | 
			
		||||
   (given.map &:id).sort.should == (objects.map &:id).sort
 | 
			
		||||
 end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# def should_have_ids_of(objcts)
 | 
			
		||||
#   simple_matcher("should have id of"){|given | (given.map &:id).sort.should == (objects.map &:id).sort}
 | 
			
		||||
# end
 | 
			
		||||
# 
 | 
			
		||||
# def be_even
 | 
			
		||||
#   simple_matcher("an even number") { |given| given % 2 == 0 }
 | 
			
		||||
# end
 | 
			
		||||
		Reference in New Issue
	
	Block a user