big refactor of windows models

This commit is contained in:
Lee Lawlor
2014-07-22 19:13:11 -04:00
parent 0739b17989
commit 0c5097803b
43 changed files with 211 additions and 411 deletions

View File

@ -3,7 +3,7 @@ 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)
@ -20,7 +20,7 @@ describe WindowsController do
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}]}"
@ -56,9 +56,7 @@ 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
@window = FactoryGirl.create(:window, html: "<iframe src=\"/\"/>")
@channel.windows << @window
end
@ -69,7 +67,7 @@ describe WindowsController do
end
end
describe "When getting " do
it "should render json" do
get 'index', :channel_id => @channel.id, :format => :json
@ -130,7 +128,3 @@ describe WindowsController do
end

View File

@ -1,10 +0,0 @@
# 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

View File

@ -1,20 +0,0 @@
# == 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

View File

@ -1,11 +0,0 @@
# 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

View File

@ -1,19 +0,0 @@
# == 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

View File

@ -1,17 +0,0 @@
# == 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

View File

@ -10,11 +10,12 @@
# html :text
# col :integer
# title :string(255)
# wtype :string(255)
# window_type :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
# content_id :integer
# options :text
#
# Read about factories at http://github.com/thoughtbot/factory_girl
@ -25,5 +26,7 @@ FactoryGirl.define do
position 1
html "<iframe ::OPTIONS::></iframe>"
col 0
content_id 1
end
end

View File

@ -79,7 +79,7 @@ describe Channel do
channel.assign_attributes({:video_id => video_id, :video_type => "youtube"})
channel.set_windows
channel.save
window = channel.windows.where({:wtype => :video })
window = channel.windows.where({:window_type => :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

View File

@ -20,8 +20,8 @@ describe Plugin do
before :each do
@user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel, :user => @user)
@window = FactoryGirl.create(:plugin_window, :channel => @channel)
@window = FactoryGirl.create(:window, :channel => @channel, :html => "<iframe ::OPTIONS::></iframe>")
end
it "should be valid" do
plugin = Plugin.new
@ -31,7 +31,7 @@ describe Plugin do
it "should confirm has_[public\private]_windows" do
plugin = Plugin.new
window = PluginWindow.new
window = Window.new
window.private_flag = true
window.channel_id = 1
plugin.windows << window
@ -49,7 +49,7 @@ describe Plugin do
plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(2)
end
it "new, private window should not be showing" do
@ -62,7 +62,7 @@ describe Plugin do
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
@ -75,7 +75,7 @@ describe Plugin do
plugin.private_flag = false
plugin.save
plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(2)
@ -83,8 +83,6 @@ describe Plugin do
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
@ -96,6 +94,7 @@ describe Plugin do
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
@ -108,19 +107,12 @@ describe Plugin do
it "should cascade delete to Window" do
plugin = Plugin.new
plugin.make_windows @channel.id, "localhost"
window_id = plugin.windows[0].id
plugin_id = plugin.id
plugin.destroy
windows = Window.find_all_by_id(window_id)
windows.size.should eq(0)
Window.where(window_type: 'plugin', content_id: plugin_id).count.should eq(0)
end
it "should have windows associated with separate channels" do
channel2 = FactoryGirl.create(:channel, :user => @user)
plugin = Plugin.new
@ -129,6 +121,7 @@ describe Plugin do
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

View File

@ -1,54 +0,0 @@
# == 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

View File

@ -10,11 +10,12 @@
# html :text
# col :integer
# title :string(255)
# wtype :string(255)
# window_type :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
# content_id :integer
# options :text
#
require 'spec_helper'
@ -24,6 +25,46 @@ describe Window do
window = Window.new
window.should be_valid
end
describe "plugin window" do
before :each do
@channel = FactoryGirl.create(:channel)
@plugin = FactoryGirl.create(:plugin)
end
it "should be valid" do
window = Window.new
window.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.should_not be_nil
end
end
describe "plugin window with user" 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.windows.length.should == 1
window = Window.new_from @plugin, @channel.id, false, "localhost"
@plugin.windows << window
@plugin.save
@plugin.windows.length.should == 2
end
end
end