Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin can edit video content on the home page
- Loading branch information
Showing
12 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Admin::SiteOptionsController < ApplicationController | ||
resources_controller_for :site_options | ||
layout false | ||
|
||
response_for :update do |format| | ||
format.html do | ||
redirect_to :back | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Admin::SiteOptionsHelper | ||
def video_content | ||
SiteOption.for(:video_content) | ||
end | ||
|
||
def change_site_option(key) | ||
if current_user && current_user.admin? | ||
site_option = SiteOption.find_or_initialize_by_key(key) | ||
link_to "Edit #{key.to_s.humanize}", edit_admin_site_option_path(site_option), :rel => 'facebox' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class SiteOption < ActiveRecord::Base | ||
include Sanitizy | ||
|
||
validates_presence_of :key | ||
validates_presence_of :value | ||
|
||
cleanse_columns(:value) do |sanitizer| | ||
sanitizer.allowed_tags.replace(%w(object param embed a img)) | ||
sanitizer.allowed_attributes.replace(%w(width height name src value allowFullScreen type href allowScriptAccess style wmode pluginspage classid codebase data quality)) | ||
end | ||
|
||
def self.for(key) | ||
site_option = find_by_key(key) | ||
site_option && site_option.value | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- form_for([:admin, @site_option]) do |f| | ||
= f.label :value | ||
= f.text_area :value | ||
%br/ | ||
= f.submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateSiteOptions < ActiveRecord::Migration | ||
def self.up | ||
create_table :site_options do |t| | ||
t.string :key | ||
t.text :value | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :site_options | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class LoadSiteOptions < ActiveRecord::Migration | ||
def self.up | ||
SiteOption.create!(:key => :video_content, :value => "<object width=\"400\" height=\"225\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=2041615&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=&fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=2041615&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=&fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"400\" height=\"225\"></embed></object>") | ||
end | ||
|
||
def self.down | ||
if site_option = SiteOption.find_by_key(:video_content) | ||
site_option.destroy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
describe Admin::SiteOptionsController do | ||
|
||
it "should use resources_controller" do | ||
# no test for this | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
describe Admin::SiteOptionsHelper do | ||
include Admin::SiteOptionsHelper | ||
|
||
describe "video_content" do | ||
it "should ask SiteOption for the value" do | ||
SiteOption.should_receive(:for).with(:video_content).and_return('a value') | ||
video_content.should == 'a value' | ||
end | ||
end | ||
|
||
describe "change_site_option" do | ||
it "should load or initialize a site option" do | ||
stub!(:current_user).and_return(Factory(:admin)) | ||
site_option = SiteOption.create!(:key => :key, :value => 'a value') | ||
SiteOption.should_receive(:find_or_initialize_by_key).with(:key).and_return(site_option) | ||
change_site_option(:key) | ||
end | ||
|
||
it "should give an edit link if the user is an admin" do | ||
site_option = SiteOption.create!(:key => :key, :value => 'a value') | ||
SiteOption.stub!(:find_or_initialize_by_key).and_return(site_option) | ||
stub!(:current_user).and_return(Factory(:admin)) | ||
change_site_option(:key).should have_tag('a[href=?]', edit_admin_site_option_path(site_option)) | ||
end | ||
|
||
it "should return nil if the user is not an admin" do | ||
stub!(:current_user).and_return(Factory(:citizen)) | ||
change_site_option(:key).should be_nil | ||
end | ||
|
||
it "should return nil if there is no current_user" do | ||
stub!(:current_user).and_return(nil) | ||
change_site_option(:key).should be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe SiteOption do | ||
|
||
requires_presence_of SiteOption, :key | ||
requires_presence_of SiteOption, :value | ||
|
||
it "should have a for class method" do | ||
SiteOption.should respond_to(:for) | ||
end | ||
|
||
it "should return a value based on a key" do | ||
SiteOption.create!(:key => :key, :value => 'value') | ||
SiteOption.for(:key).should == 'value' | ||
end | ||
end |