Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

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