spud_core 0.8.15 → 0.8.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,6 @@ Spud = (typeof(Spud) == 'undefined') ? {} : Spud;
11
11
  Spud.Admin = (typeof(Spud.Admin) == 'undefined') ? {} : Spud.Admin;
12
12
 
13
13
  $(document).ready(function() {
14
- console.log("HELLO!");
15
14
  $('#user_table').dataTable({
16
15
  "bJQueryUI": true,
17
16
  "sPaginationType": "full_numbers"
@@ -134,15 +133,16 @@ function highdpi_init() {
134
133
  }
135
134
 
136
135
  if(hiDpiSrc) {
137
- $.ajax({
138
- type: 'HEAD',
139
- async: true,
140
- element: els[i],
141
- url: hiDpiSrc,
142
- success: function(message) {
143
- this.element.src = this.url;
144
- }
145
- });
136
+ els[i].src = hiDpiSrc;
137
+ // $.ajax({
138
+ // type: 'HEAD',
139
+ // async: true,
140
+ // element: els[i],
141
+ // url: hiDpiSrc,
142
+ // success: function(message) {
143
+ // this.element.src = this.url;
144
+ // }
145
+ // });
146
146
  }
147
147
 
148
148
 
@@ -1,5 +1,5 @@
1
1
  class Spud::Admin::DashboardController < Spud::Admin::ApplicationController
2
-
2
+
3
3
  def index
4
4
  permission_set = current_user_permissions.collect{|p| p.name}
5
5
  @unsorted_applications = Spud::Core.admin_applications.select{|app| @current_user.super_admin || permission_set.include?(app[:name])}.sort_by{|obj| obj[:order]}
@@ -19,17 +19,16 @@ class Spud::Admin::DashboardController < Spud::Admin::ApplicationController
19
19
  end
20
20
  end
21
21
 
22
- def switch
23
- if params[:multisite_select].blank?
24
- # flash[:error] = "Site variable does not exist."
25
- session[:admin_site] = nil
26
- redirect_to request.referer and return
27
- end
28
- if Spud::Core.multisite_config.select{|p| p[:site_id].to_i == params[:multisite_select].to_i}.blank? == false
29
- session[:admin_site] = params[:multisite_select].to_i
30
- else
31
- flash[:error] = "Site does not exist."
32
- end
33
- redirect_to request.referer and return
34
- end
35
- end
22
+ def switch
23
+ if !params[:multisite_select].blank?
24
+ if Spud::Core.multisite_config.select{|p| p[:site_id].to_i == params[:multisite_select].to_i}.blank? == false
25
+ session[:admin_site] = params[:multisite_select].to_i
26
+ else
27
+ flash[:error] = "Site does not exist."
28
+ end
29
+ else
30
+ session[:admin_site] = nil
31
+ end
32
+ redirect_to(back_or_default(!request.referer.blank? ? request.referer : spud_admin_root_path)) and return
33
+ end
34
+ end
@@ -61,8 +61,13 @@ class Spud::ApplicationController < ActionController::Base
61
61
  end
62
62
 
63
63
  def redirect_back_or_default(default)
64
- redirect_to(session[:return_to] || default)
64
+ redirect_to(back_or_default(default))
65
+ end
66
+
67
+ def back_or_default(default)
68
+ result = !session[:return_to].blank? ? session[:return_to] : default
65
69
  session[:return_to] = nil
70
+ return result
66
71
  end
67
72
 
68
73
  def set_time_zone
@@ -2,7 +2,9 @@ module Spud::Admin::ApplicationHelper
2
2
 
3
3
  def hidpi_asset(path)
4
4
  begin
5
- return asset_path(path.gsub(/\.png/,"@2x.png"))
5
+ return nil if Rails.application.assets.find_asset(path.gsub(/\.png/,"@2x.png")).nil?
6
+ asset_path = asset_path(path.gsub(/\.png/,"@2x.png"))
7
+ return asset_path
6
8
  rescue
7
9
  return nil
8
10
  end
@@ -5,7 +5,7 @@
5
5
  </span>
6
6
  <h2>
7
7
  <%if @page_thumbnail%>
8
- <span class="thumb_wrapper"><%=image_tag(@page_thumbnail,:hidpi_src => asset_path(@page_thumbnail.gsub(/\.png/,"@2x.png")))%></span>
8
+ <span class="thumb_wrapper"><%=image_tag(@page_thumbnail,:hidpi_src => hidpi_asset(@page_thumbnail))%></span>
9
9
  <%end%>
10
10
  <%=@page_name%>
11
11
  </h2>
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Core
3
- VERSION = "0.8.15"
3
+ VERSION = "0.8.16"
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ describe Spud::Admin::DashboardController do
6
6
  config.admin_applications = [
7
7
  {name: "Blog", thumbnail: "/url/to/image", url: "/url/to/app", order: 0},
8
8
  {name: "Settings", thumbnail: "/url/to/image", url: "/url/to/app", order: 0},
9
- {name: "Pages", thumbnail: "/url/to/image", url: "/url/to/app", order: 0},
9
+ {name: "Pages", thumbnail: "/url/to/image", url: "/url/to/app", order: 0}
10
10
  ]
11
11
  end
12
12
  end
@@ -16,7 +16,7 @@ describe Spud::Admin::DashboardController do
16
16
  @user = FactoryGirl.create(:spud_user)
17
17
  SpudUserSession.create(@user)
18
18
  end
19
-
19
+
20
20
  describe :index do
21
21
  it "should display applications the current user has access to given that the current user is not a super admin" do
22
22
  @user.super_admin = false
@@ -27,7 +27,7 @@ describe Spud::Admin::DashboardController do
27
27
 
28
28
  assigns(:admin_applications).collect{|app| app[:name] }.should =~ @user.spud_admin_permissions.collect{|permission| permission.name }
29
29
  end
30
-
30
+
31
31
  it "should not display applications the current user does not have access to given that the current user is not a super admin" do
32
32
  @user.super_admin = false
33
33
  @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
@@ -37,7 +37,7 @@ describe Spud::Admin::DashboardController do
37
37
 
38
38
  assigns(:admin_applications).collect{|app| app[:name] }.should_not include(:settings)
39
39
  end
40
-
40
+
41
41
  it "should display all the applications despite the users permissions given the current user is a super admin" do
42
42
  @user.super_admin = true
43
43
  @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
@@ -53,8 +53,62 @@ describe Spud::Admin::DashboardController do
53
53
  @user.spud_user_settings.create(:key => "app_order",:value => "Pages,Settings")
54
54
  get :index
55
55
 
56
- assigns(:admin_applications).collect{|app| app[:name] }.should =~ ["Pages","Settings","Blog"]
56
+ assigns(:admin_applications).collect{|app| app[:name] }.should =~ ["Pages","Settings","Blog"]
57
+
58
+ end
59
+ end
60
+
61
+ describe :switch do
62
+ before(:each) do
63
+ @user.super_admin = true
64
+ @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
65
+ @user.save
66
+ end
67
+
68
+ context "when multisite select is not set" do
69
+ it "should clear the session admin site" do
70
+ get :switch, :multisite_select => nil
71
+ session[:admin_site].should be_blank
72
+ end
73
+
74
+ it "should redirect to the referer" do
75
+ get :switch, :multisite_select => nil
76
+ response.should be_redirect
77
+ end
78
+ end
79
+
80
+ context "when multisite select is set" do
81
+ context "and the selected site is configured" do
82
+ before(:each) do
83
+ Spud::Core.stubs(:multisite_config).returns([{:site_id => 1}])
84
+ end
85
+
86
+ it "should set the session's admin site" do
87
+ get :switch, :multisite_select => 1
88
+ session[:admin_site].should == 1
89
+ end
90
+
91
+ it "should redirect" do
92
+ get :switch, :multisite_select => 1
93
+ response.should be_redirect
94
+ end
95
+ end
96
+
97
+ context "and the selected site is not configured" do
98
+ before(:each) do
99
+ Spud::Core.stubs(:multisite_config).returns([{:site_id => 2}])
100
+ end
101
+
102
+ it "should set a flash error" do
103
+ get :switch, :multisite_select => 1
104
+ flash[:error].should_not be_blank
105
+ end
57
106
 
107
+ it "should redirect" do
108
+ get :switch, :multisite_select => 1
109
+ response.should be_redirect
110
+ end
111
+ end
58
112
  end
59
113
  end
60
- end
114
+ end
@@ -8,7 +8,7 @@ describe Spud::UserSessionsController do
8
8
  describe :new do
9
9
  it "should redirect to setup url if no users exist" do
10
10
  get :new
11
- response.should redirect_to(spud_setup_url)
11
+ response.should redirect_to(spud_setup_url)
12
12
  end
13
13
 
14
14
  it "should render login form if users do exist" do
@@ -21,16 +21,16 @@ describe Spud::UserSessionsController do
21
21
 
22
22
  describe :create do
23
23
  it "should rerender form when login is invalid" do
24
- post :create
25
- response.should be_success
26
- end
27
- it "should redirect to root url if login is valid" do
28
- u = FactoryGirl.create(:spud_user,:login => "testuser")
29
- u.save
30
- user_session = {:login => "testuser", :password => "password"}
31
- post :create,:spud_user_session => user_session
32
- response.should redirect_to(root_url)
33
- end
24
+ post :create
25
+ response.should be_success
26
+ end
27
+ it "should redirect to root url if login is valid" do
28
+ u = FactoryGirl.create(:spud_user,:login => "testuser")
29
+ u.save
30
+ user_session = {:login => "testuser", :password => "password"}
31
+ post :create,:spud_user_session => user_session
32
+ response.should redirect_to(root_url)
33
+ end
34
34
  end
35
35
 
36
36
  describe :destroy do
@@ -48,6 +48,4 @@ describe Spud::UserSessionsController do
48
48
  response.should redirect_to("/")
49
49
  end
50
50
  end
51
-
52
-
53
- end
51
+ end