Skip to content
Browse files

removed callback_proc and made the extension into a standalone gem fo…

…r testing.
  • Loading branch information...
1 parent 0d32c71 commit 8dc157315aa717b7809d1ff4370166f3ce092674 @parndt parndt committed Feb 24, 2012
View
3 .rspec
@@ -0,0 +1,3 @@
+--colour
+--drb
+--format Fuubar
View
14 app/controllers/refinery/admin/settings_controller.rb
@@ -10,7 +10,6 @@ class SettingsController < ::Refinery::AdminController
:xhr_paging => true
before_filter :sanitise_params, :only => [:create, :update]
- after_filter :fire_setting_callback, :only => [:update]
def new
form_value_type = ((current_refinery_user.has_role?(:superuser) && params[:form_value_type]) || 'text_area')
@@ -49,21 +48,8 @@ def redirect_to_where?
# this fires before an update or create to remove any attempts to pass sensitive arguments.
def sanitise_params
- params.delete(:callback_proc_as_string)
params.delete(:scoping)
end
-
- def fire_setting_callback
- begin
- @setting.callback_proc.call
- rescue
- logger.warn('Could not fire callback proc. Details:')
- logger.warn(@setting.inspect)
- logger.warn($!.message)
- logger.warn($!.backtrace)
- end unless @setting.callback_proc.nil?
- end
-
end
end
end
View
14 app/models/refinery/setting.rb
@@ -9,14 +9,12 @@ class Setting < Refinery::Core::BaseModel
validates :name, :presence => true
serialize :value # stores into YAML format
- serialize :callback_proc_as_string
# Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
acts_as_indexed :fields => [:name]
attr_accessible :name, :value, :destroyable,
- :scoping, :restricted, :callback_proc_as_string,
- :form_value_type
+ :scoping, :restricted, :form_value_type
has_friendly_id :name, :use_slug => true
@@ -90,8 +88,9 @@ def cache_key
def find_or_set(name, the_value, options={})
# Merge default options with supplied options.
options = {
- :scoping => nil, :restricted => false,
- :callback_proc_as_string => nil, :form_value_type => 'text_area'
+ :scoping => nil,
+ :restricted => false,
+ :form_value_type => 'text_area'
}.merge(options)
# try to find the setting first
@@ -127,7 +126,6 @@ def set(name, value)
# set the value last, so that the other attributes can transform it if required.
setting.form_value_type = value[:form_value_type] || 'text_area' if setting.respond_to?(:form_value_type)
setting.scoping = value[:scoping] if value.has_key?(:scoping)
- setting.callback_proc_as_string = value[:callback_proc_as_string] if value.has_key?(:callback_proc_as_string)
setting.destroyable = value[:destroyable] if value.has_key?(:destroyable)
setting.value = value[:value]
end
@@ -175,10 +173,6 @@ def value=(new_value)
super
end
- def callback_proc
- eval("Proc.new{#{callback_proc_as_string} }") if callback_proc_as_string.present?
- end
-
private
# Below is not very nice, but seems to be required. The problem is when Rails
# serialises a fields like booleans it doesn't retrieve it back out as a boolean
View
2 app/views/refinery/admin/settings/_actions.html.erb
@@ -3,6 +3,6 @@
<%= render '/refinery/admin/search', :url => refinery.admin_settings_path %>
</li>
<li>
- <%= link_to t('.new'), refinery.new_admin_setting_path, :class => "add_icon" %>
+ <%= link_to t('.new'), refinery.new_admin_setting_path(:dialog => true), :class => "add_icon" %>
</li>
</ul>
View
30 app/views/refinery/admin/settings/_records.html.erb
@@ -3,19 +3,19 @@
<%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %>
</h2>
<% end %>
-<% if @settings.any? %>
- <div class='pagination_container'>
+<div class='pagination_container'>
+ <% if @settings.any? %>
<%= render 'settings' %>
- </div>
-<% else %>
- <p>
- <% if searching? %>
- <%= t('no_results', :scope => 'refinery.admin.search') %>
- <% else %>
- <strong>
- <%= t('.empty_set') %>
- <%= t('.create_first', :link => t('new', :scope => 'refinery.admin.settings.actions')) %>
- </strong>
- <% end %>
- </p>
-<% end %>
+ <% else %>
+ <p>
+ <% if searching? %>
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
+ <% else %>
+ <strong>
+ <%= t('.empty_set') %>
+ <%= t('.create_first', :link => t('new', :scope => 'refinery.admin.settings.actions')) %>
+ </strong>
+ <% end %>
+ </p>
+ <% end %>
+</div>
View
2 app/views/refinery/admin/settings/_settings.html.erb
@@ -1,4 +1,4 @@
-<%= will_paginate @settings %>
+<%= will_paginate @settings if Refinery::Admin::SettingsController.pageable? %>
<ul class="<%= ['pagination_frame', pagination_css_class].compact.join(' ') %>">
<%= render :partial => 'setting', :collection => @settings %>
</ul>
View
1 db/migrate/20100913234710_create_refinerycms_settings_schema.rb
@@ -6,7 +6,6 @@ def change
t.boolean :destroyable, :default => true
t.string :scoping
t.boolean :restricted, :default => false
- t.string :callback_proc_as_string
t.string :form_value_type
t.timestamps
View
20 lib/refinery/generators/refinery/settings/settings_generator.rb
@@ -0,0 +1,20 @@
+module Refinery
+ class SettingsGenerator < Rails::Generators::Base
+
+ def rake_db
+ rake("refinery_settings:install:migrations")
+ end
+
+ def append_load_seed_data
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
+ append_file 'db/seeds.rb', :verbose => true do
+ <<-EOH
+
+# Added by Refinery CMS Settings engine
+Refinery::Settings::Engine.load_seed
+ EOH
+ end
+ end
+
+ end
+end
View
3 lib/refinery/settings.rb
@@ -1,7 +1,10 @@
require 'refinerycms-core'
module Refinery
+ autoload :SettingsGenerator, 'generators/refinery/settings/settings_generator'
+
module Settings
+
require 'refinery/settings/engine'
class << self
View
6 script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+ENGINE_PATH = File.expand_path('../..', __FILE__)
+load File.expand_path('../../spec/dummy/script/rails', __FILE__)
View
13 spec/requests/refinery/admin/settings_spec.rb
@@ -21,13 +21,18 @@ module Admin
end
context "new/create" do
- it "adds setting" do
+ it "adds setting", :js => true do
visit refinery.admin_settings_path
click_link "Add new setting"
- fill_in "Name", :with => "test setting"
- fill_in "Value", :with => "true"
- click_button "Save"
+ page.should have_selector('iframe#dialog_iframe')
+
+ page.within_frame('dialog_iframe') do
+ fill_in "Name", :with => "test setting"
+ fill_in "Value", :with => "true"
+
+ click_button "Save"
+ end
page.should have_content("'Test Setting' was successfully added.")
page.should have_content("Test Setting - true")

0 comments on commit 8dc1573

Please sign in to comment.
Something went wrong with that request. Please try again.