Commit a26c1d6863f320757722f681af9c4cf58e2e9f81
1 parent
73c0b43f
Exists in
master
and in
29 other branches
AntiSpam plugin administrative interface
ActionItem2306
Showing
5 changed files
with
101 additions
and
0 deletions
Show diff stats
plugins/anti_spam/controllers/anti_spam_plugin_admin_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +class AntiSpamPluginAdminController < AdminController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
3 | + | |
4 | + def index | |
5 | + @settings = AntiSpamPlugin::Settings.new(environment, params[:settings]) | |
6 | + if request.post? | |
7 | + @settings.save! | |
8 | + redirect_to :action => 'index' | |
9 | + end | |
10 | + end | |
11 | + | |
12 | +end | ... | ... |
... | ... | @@ -0,0 +1,35 @@ |
1 | +class AntiSpamPlugin::Settings | |
2 | + | |
3 | + def initialize(environment, attributes = nil) | |
4 | + @environment = environment | |
5 | + attributes ||= {} | |
6 | + attributes.each do |k,v| | |
7 | + self.send("#{k}=", v) | |
8 | + end | |
9 | + end | |
10 | + | |
11 | + def settings | |
12 | + @environment.settings[:anti_spam_plugin] ||= {} | |
13 | + end | |
14 | + | |
15 | + def host | |
16 | + settings[:host] ||= 'api.antispam.typepad.com' | |
17 | + end | |
18 | + | |
19 | + def host=(value) | |
20 | + settings[:host] = value | |
21 | + end | |
22 | + | |
23 | + def api_key | |
24 | + settings[:api_key] | |
25 | + end | |
26 | + | |
27 | + def api_key=(value) | |
28 | + settings[:api_key] = value | |
29 | + end | |
30 | + | |
31 | + def save! | |
32 | + @environment.save! | |
33 | + end | |
34 | + | |
35 | +end | ... | ... |
plugins/anti_spam/test/unit/anti_spam_plugin/settings_test.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class AntiSpamSettingsTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @environment = Environment.new | |
7 | + @settings = AntiSpamPlugin::Settings.new(@environment) | |
8 | + end | |
9 | + | |
10 | + should 'store setttings in environment' do | |
11 | + @settings.host = 'foo.com' | |
12 | + @settings.api_key = '1234567890' | |
13 | + assert_equal 'foo.com', @environment.settings[:anti_spam_plugin][:host] | |
14 | + assert_equal '1234567890', @environment.settings[:anti_spam_plugin][:api_key] | |
15 | + assert_equal 'foo.com', @settings.host | |
16 | + assert_equal '1234567890', @settings.api_key | |
17 | + end | |
18 | + | |
19 | + should 'save environment on save' do | |
20 | + @environment.expects(:save!) | |
21 | + @settings.save! | |
22 | + end | |
23 | + | |
24 | + should 'use TypePad AntiSpam by default' do | |
25 | + assert_equal 'api.antispam.typepad.com', @settings.host | |
26 | + end | |
27 | + | |
28 | + | |
29 | +end | ... | ... |
plugins/anti_spam/views/anti_spam_plugin_admin/index.rhtml
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +<h1><%= _('AntiSpam settings')%></h1> | |
2 | + | |
3 | +<% form_for(:settings) do |f| %> | |
4 | + | |
5 | + <%= labelled_form_field _('Host'), f.text_field(:host) %> | |
6 | + | |
7 | + <%= labelled_form_field _('API key'), f.text_field (:api_key) %> | |
8 | + | |
9 | + <% button_bar do %> | |
10 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
11 | + <% end %> | |
12 | + | |
13 | +<% end %> | |
14 | + | ... | ... |