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

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