Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Refactor admin settings controller and re-enable commented request specs... #72

Merged
merged 1 commit into from about 2 years ago

2 participants

Uģis Ozols Philip Arndt
Uģis Ozols
Owner

.... Should fix #69.

Uģis Ozols
Owner
Philip Arndt
Owner

Ok so this removes crudify?

Uģis Ozols
Owner

Yeah... We don't need all the goodies that crudify is offering.

Philip Arndt
Owner
Philip Arndt parndt merged commit 17da729 into from
Philip Arndt parndt closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 20, 2012
Uģis Ozols Refactor admin settings controller and re-enable commented request sp…
…ecs. Should fix #69.
fa5c965
This page is out of date. Refresh to see the latest.
60  app/controllers/refinery/inquiries/admin/settings_controller.rb
... ...
@@ -1,53 +1,43 @@
1 1
 module Refinery
2 2
   module Inquiries
3 3
     module Admin
4  
-      class SettingsController < ::Refinery::AdminController
  4
+      class SettingsController < Refinery::AdminController
5 5
 
6  
-        crudify :'refinery/setting',
7  
-                :title_attribute => "name",
8  
-                :order => 'name ASC',
9  
-                :redirect_to_url => 'refinery.inquiries_admin_inquiries_path'
  6
+        before_filter :check_setting, :only => [:edit, :update]
  7
+        after_filter :save_subject_for_confirmation, :save_message_for_confirmation, :only => :update
10 8
 
11  
-        before_filter :set_url_override?, :only => [:edit, :update]
12  
-        after_filter :save_subject_for_confirmation?, :only => :update
13  
-        after_filter :save_message_for_confirmation?, :only => :update
14  
-        around_filter :rewrite_flash?, :only => :update
  9
+        def edit
  10
+          @setting = Refinery::Setting.find(params[:id])
  11
+        end
15 12
 
16  
-        protected
  13
+        def update
  14
+          @setting = Refinery::Setting.find(params[:id])
17 15
 
18  
-        def rewrite_flash?
19  
-          yield
  16
+          if @setting.update_attributes(params[:setting])
  17
+            flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("inquiry_", "").titleize)
20 18
 
21  
-          flash[:notice] = flash[:notice].to_s.gsub(/(\'.*\')/) {|m| m.titleize}.gsub('Inquiry ', '')
  19
+            unless request.xhr? or from_dialog?
  20
+              redirect_back_or_default(refinery.inquiries_admin_inquiries_path)
  21
+            else
  22
+              render :text => "<script type='text/javascript'>parent.window.location = '#{refinery.inquiries_admin_inquiries_path}';</script>"
  23
+            end
  24
+          end
22 25
         end
23 26
 
24  
-        def save_subject_for_confirmation?
25  
-          Refinery::Inquiries::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
26  
-        end
  27
+      protected
27 28
 
28  
-        def save_message_for_confirmation?
29  
-          Refinery::Inquiries::Setting.confirmation_message = params[:message] if params.keys.include?('message')
30  
-        end
  29
+        def check_setting
  30
+          setting = params[:id].gsub("inquiry_", "")
31 31
 
32  
-        def set_url_override?
33  
-          @url_override = refinery.inquiries_admin_setting_path(@setting, :dialog => from_dialog?)
  32
+          Refinery::Inquiries::Setting.send(setting) if Refinery::Inquiries::Setting.respond_to?(setting)
34 33
         end
35 34
 
36  
-        def find_setting
37  
-          # ensure that we're dealing with the name of the setting, not the id.
38  
-          begin
39  
-            if params[:id].to_i.to_s == params[:id]
40  
-              params[:id] = Refinery::Setting.find(params[:id]).name.to_s
41  
-            end
42  
-          rescue
43  
-          end
44  
-
45  
-          # prime the setting first, if it's valid.
46  
-          if Refinery::Inquiries::Setting.methods.map(&:to_sym).include?(params[:id].to_s.gsub('inquiry_', '').to_sym)
47  
-            Refinery::Inquiries::Setting.send(params[:id].to_s.gsub('inquiry_', '').to_sym)
48  
-          end
  35
+        def save_subject_for_confirmation
  36
+          Refinery::Inquiries::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
  37
+        end
49 38
 
50  
-          @setting = Refinery::Setting.find_by_name(params[:id])
  39
+        def save_message_for_confirmation
  40
+          Refinery::Inquiries::Setting.confirmation_message = params[:message] if params.keys.include?('message')
51 41
         end
52 42
 
53 43
       end
2  app/views/refinery/inquiries/admin/settings/_confirmation_email_form.html.erb
... ...
@@ -1,4 +1,4 @@
1  
-<%= form_for @setting, :url => (@url_override || @url) do |f| %>
  1
+<%= form_for @setting, :url => refinery.inquiries_admin_setting_path(@setting) do |f| %>
2 2
 
3 3
   <p>
4 4
     <%= t('.explanation') %>
2  app/views/refinery/inquiries/admin/settings/_notification_recipients_form.html.erb
... ...
@@ -1,4 +1,4 @@
1  
-<%= form_for @setting, :url => (@url_override || @url) do |f| %>
  1
+<%= form_for @setting, :url => refinery.inquiries_admin_setting_path(@setting) do |f| %>
2 2
 
3 3
   <div class='field'>
4 4
     <span class='label_with_help'>
54  spec/requests/refinery/inquiries/admin/inquiries_spec.rb
@@ -101,37 +101,47 @@ module Admin
101 101
           end
102 102
         end
103 103
 
104  
-=begin
105  
-      describe "update who gets notified" do
106  
-        it "sets receiver", :js => true do
107  
-          visit refinery.inquiries_admin_inquiries_path
  104
+        describe "update who gets notified" do
  105
+          before do
  106
+            Rails.cache.clear
  107
+            Refinery::Inquiries::Setting.notification_recipients
  108
+          end
  109
+
  110
+          it "sets receiver", :js => true do
  111
+            visit refinery.inquiries_admin_inquiries_path
108 112
 
109  
-          click_link "Update who gets notified"
  113
+            click_link "Update who gets notified"
110 114
 
111  
-          within_frame "dialog_iframe" do
112  
-            fill_in "Send notifications to", :with => "phil@refinerycms.com"
113  
-            click_button "Save"
114  
-          end
  115
+            within_frame "dialog_iframe" do
  116
+              fill_in "setting_value", :with => "phil@refinerycms.com"
  117
+              click_button "submit_button"
  118
+            end
115 119
 
116  
-          page.should have_content("'Notification Recipients' was successfully updated.")
  120
+            page.should have_content("Notification Recipients was successfully updated.")
  121
+          end
117 122
         end
118  
-      end
119 123
 
120  
-      describe "updating confirmation email copy" do
121  
-        it "sets message", :js => true do
122  
-          visit refinery.inquiries_admin_inquiries_path
  124
+        describe "updating confirmation email copy" do
  125
+          before do
  126
+            Rails.cache.clear
  127
+            Refinery::Inquiries::Setting.confirmation_body
  128
+          end
123 129
 
124  
-          click_link "Edit confirmation email"
  130
+          it "sets message", :js => true do
  131
+            visit refinery.inquiries_admin_inquiries_path
125 132
 
126  
-          within_frame "dialog_iframe" do
127  
-            fill_in "Message", :with => "Thanks %name%! We'll never get back to you!"
128  
-            click_button "Save"
129  
-          end
  133
+            click_link "Edit confirmation email"
  134
+
  135
+            within_frame "dialog_iframe" do
  136
+              fill_in "subject__en", :with => "subject"
  137
+              fill_in "message__en", :with => "message"
  138
+              click_button "Save"
  139
+            end
130 140
 
131  
-          page.should have_content("'Confirmation Body' was successfully updated.")
  141
+            page.should have_content("Confirmation Body was successfully updated.")
  142
+          end
132 143
         end
133  
-      end
134  
-=end
  144
+
135 145
       end
136 146
     end
137 147
   end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.