alchemy_cms 2.2.rc11 → 2.2.rc13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.travis.yml +4 -1
  2. data/Gemfile +10 -9
  3. data/alchemy_cms.gemspec +8 -4
  4. data/app/assets/javascripts/alchemy/alchemy.base.js +0 -13
  5. data/app/assets/javascripts/alchemy/alchemy.dirty.js +6 -4
  6. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js +2 -2
  7. data/app/assets/stylesheets/alchemy/elements.css.scss +4 -7
  8. data/app/controllers/alchemy/admin/base_controller.rb +2 -3
  9. data/app/controllers/alchemy/admin/clipboard_controller.rb +10 -10
  10. data/app/controllers/alchemy/admin/elements_controller.rb +4 -4
  11. data/app/controllers/alchemy/admin/pages_controller.rb +1 -2
  12. data/app/controllers/alchemy/base_controller.rb +1 -15
  13. data/app/helpers/alchemy/admin/base_helper.rb +15 -21
  14. data/app/helpers/alchemy/admin/contents_helper.rb +0 -6
  15. data/app/helpers/alchemy/admin/pages_helper.rb +62 -27
  16. data/app/helpers/alchemy/base_helper.rb +0 -9
  17. data/app/models/alchemy/clipboard.rb +74 -0
  18. data/app/models/alchemy/clipboard_spec.rb +0 -0
  19. data/app/models/alchemy/content.rb +19 -0
  20. data/app/views/alchemy/admin/contents/create.js.erb +1 -1
  21. data/app/views/alchemy/admin/elements/_element.html.erb +0 -1
  22. data/app/views/alchemy/admin/elements/_element_head.html.erb +4 -5
  23. data/app/views/alchemy/admin/essence_pictures/assign.js.erb +3 -2
  24. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +3 -4
  25. data/app/views/alchemy/admin/essence_pictures/edit.html.erb +1 -1
  26. data/app/views/alchemy/admin/essence_pictures/update.js.erb +1 -10
  27. data/app/views/alchemy/admin/pages/_contactform_links.html.erb +3 -9
  28. data/app/views/alchemy/admin/pages/_external_link.html.erb +3 -12
  29. data/app/views/alchemy/admin/pages/_file_link.html.erb +3 -12
  30. data/app/views/alchemy/admin/pages/_internal_link.html.erb +5 -14
  31. data/app/views/alchemy/admin/pages/_page_for_links.html.erb +3 -9
  32. data/app/views/alchemy/admin/pages/edit.html.erb +16 -17
  33. data/app/views/alchemy/admin/pictures/_picture.html.erb +3 -2
  34. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -0
  35. data/app/views/alchemy/essences/_essence_picture_tools.html.erb +6 -8
  36. data/app/views/alchemy/essences/_essence_richtext_editor.html.erb +9 -3
  37. data/lib/alchemy/authentication_helpers.rb +26 -0
  38. data/lib/alchemy/engine.rb +4 -0
  39. data/lib/alchemy/tinymce.rb +4 -0
  40. data/lib/alchemy/version.rb +1 -1
  41. data/spec/controllers/admin/clipboard_controller_spec.rb +35 -35
  42. data/spec/controllers/admin/elements_controller_spec.rb +71 -14
  43. data/spec/controllers/admin/pages_controller_spec.rb +79 -33
  44. data/spec/models/clipboard_spec.rb +100 -0
  45. data/spec/models/element_spec.rb +17 -7
  46. metadata +77 -8
@@ -1,11 +1,17 @@
1
- <%- cache(content) do -%>
1
+ <% cache(content) do -%>
2
2
  <div class="content_editor content_rtf_editor" id="<%= content_dom_id(content) %>">
3
3
  <label><%= render_content_name(content) %></label>
4
4
  <div style="position: relative">
5
+ <% if content.has_custom_tinymce_config? && content.settings[:tinymce] -%>
5
6
  <div class="essence_richtext_loader">
6
7
  <%= image_tag('alchemy/ajax_loader.gif') %>
7
8
  </div>
8
- <%= tinymce_tag(content.form_field_name, content.ingredient) %>
9
+ <% end -%>
10
+ <%= text_area_tag(
11
+ content.form_field_name,
12
+ content.ingredient || '',
13
+ :class => content.tinymce_class_name
14
+ ) %>
9
15
  </div>
10
16
  </div>
11
- <%- end -%>
17
+ <% end -%>
@@ -0,0 +1,26 @@
1
+ module Alchemy
2
+ module AuthenticationHelpers
3
+
4
+ def self.included(base)
5
+ base.send :helper_method, :current_user
6
+ base.send :alias_method, :current_alchemy_user, :current_user
7
+ end
8
+
9
+ def current_user
10
+ return @current_user if defined?(@current_user)
11
+ @current_user = current_user_session && current_user_session.record
12
+ end
13
+
14
+ def current_user_session
15
+ return @current_user_session if defined?(@current_user_session)
16
+ @current_user_session = UserSession.find
17
+ end
18
+
19
+ def logged_in?
20
+ !current_user.blank?
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ ApplicationController.send :include, Alchemy::AuthenticationHelpers
@@ -41,5 +41,9 @@ module Alchemy
41
41
  Alchemy::AuthEngine.get_instance.load(File.join(File.dirname(__FILE__), '../..', 'config/authorization_rules.rb'))
42
42
  end
43
43
 
44
+ initializer 'alchemy.include_authentication_helpers' do
45
+ require File.join(File.dirname(__FILE__), 'authentication_helpers')
46
+ end
47
+
44
48
  end
45
49
  end
@@ -47,5 +47,9 @@ module Alchemy
47
47
  @@init
48
48
  end
49
49
 
50
+ def self.custom_config_contents
51
+ @@custom_config_contents ||= Content.descriptions.select { |c| c['settings'] && !c['settings']['tinymce'].nil? }
52
+ end
53
+
50
54
  end
51
55
  end
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
2
 
3
- VERSION = "2.2.rc11"
3
+ VERSION = "2.2.rc13"
4
4
 
5
5
  end
@@ -1,49 +1,49 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Admin::ClipboardController do
3
+ module Alchemy
4
+ describe Admin::ClipboardController do
4
5
 
5
- before(:each) do
6
- activate_authlogic
7
- Alchemy::UserSession.create(FactoryGirl.create(:admin_user))
8
- end
9
-
10
- context "clipboard" do
6
+ let(:page) { FactoryGirl.create(:public_page) }
7
+ let(:element) { FactoryGirl.create(:element, :page => page) }
8
+ let(:another_element) { FactoryGirl.create(:element, :page => page) }
11
9
 
12
- it "should hold element ids" do
13
- @page = FactoryGirl.create(:page, :parent_id => Alchemy::Page.rootpage.id)
14
- @element = FactoryGirl.create(:element, :page => @page)
15
- @another_element = FactoryGirl.create(:element, :page => @page)
16
- session['clipboard'] = {'elements' => [{:id => @element.id, :action => 'copy'}]}
17
- post(:insert, {:remarkable_type => 'element', :remarkable_id => @another_element.id, :format => :js})
18
- session['clipboard']['elements'].should == [{:id => @element.id, :action => 'copy'}, {:id => @another_element.id.to_s, :action => 'copy'}]
10
+ before(:each) do
11
+ activate_authlogic
12
+ UserSession.create(FactoryGirl.create(:admin_user))
13
+ session[:clipboard] = Clipboard.new
19
14
  end
20
15
 
21
- it "should not have the same element twice" do
22
- @page = FactoryGirl.create(:page, :parent_id => Alchemy::Page.rootpage.id)
23
- @element = FactoryGirl.create(:element, :page => @page)
24
- session['clipboard'] = {'elements' => [{:id => @element.id, :action => 'copy'}]}
25
- post(:insert, {:remarkable_type => 'element', :remarkable_id => @element.id, :format => :js})
26
- session['clipboard']['elements'].should == [{:id => @element.id, :action => 'copy'}]
16
+ describe "#insert" do
17
+
18
+ it "should hold element ids" do
19
+ post(:insert, {:remarkable_type => :elements, :remarkable_id => element.id, :format => :js})
20
+ session[:clipboard][:elements].should == [{:id => element.id, :action => 'copy'}]
21
+ end
22
+
23
+ it "should not have the same element twice" do
24
+ session[:clipboard][:elements] = {:id => element.id, :action => 'copy'}
25
+ post(:insert, {:remarkable_type => :elements, :remarkable_id => element.id, :format => :js})
26
+ session[:clipboard][:elements].collect { |e| e[:id] }.should_not == [element.id, element.id]
27
+ end
28
+
27
29
  end
28
30
 
29
- it "should remove element ids" do
30
- @page = FactoryGirl.create(:page, :parent_id => Alchemy::Page.rootpage.id)
31
- @element = FactoryGirl.create(:element, :page => @page)
32
- @another_element = FactoryGirl.create(:element, :page => @page)
33
- session['clipboard'] = {'elements' => [{:id => @element.id, :action => 'copy'}, {:id => @another_element.id, :action => 'copy'}]}
34
- delete(:remove, {:remarkable_type => 'element', :remarkable_id => @another_element.id, :format => :js})
35
- session['clipboard']['elements'].should == [{:id => @element.id, :action => 'copy'}]
31
+ describe "#delete" do
32
+ it "should remove element ids from clipboard" do
33
+ session[:clipboard][:elements] = {:id => element.id, :action => 'copy'}
34
+ session[:clipboard][:elements] << {:id => another_element.id, :action => 'copy'}
35
+ delete(:remove, {:remarkable_type => :elements, :remarkable_id => another_element.id, :format => :js})
36
+ session[:clipboard][:elements].should == [{:id => element.id, :action => 'copy'}]
37
+ end
36
38
  end
37
39
 
38
- it "should be clearable" do
39
- @page = FactoryGirl.create(:page, :parent_id => Alchemy::Page.rootpage.id)
40
- @element = FactoryGirl.create(:element, :page => @page)
41
- @another_element = FactoryGirl.create(:element, :page => @page)
42
- session['clipboard'] = {'elements' => [@element.id, @another_element.id]}
43
- delete(:clear, :format => :js)
44
- session['clipboard'].should == {}
40
+ describe "#clear" do
41
+ it "should be clearable" do
42
+ session[:clipboard][:elements] = {:id => element.id}
43
+ delete(:clear, :format => :js)
44
+ session[:clipboard].should be_empty
45
+ end
45
46
  end
46
47
 
47
48
  end
48
-
49
49
  end
@@ -1,22 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Admin::ElementsController do
3
+ module Alchemy
4
+ describe Admin::ElementsController do
4
5
 
5
- render_views
6
+ before(:each) do
7
+ activate_authlogic
8
+ Alchemy::UserSession.create FactoryGirl.create(:admin_user)
9
+ end
6
10
 
7
- before(:each) do
8
- activate_authlogic
9
- Alchemy::UserSession.create FactoryGirl.create(:admin_user)
10
- end
11
+ let(:page) { mock_model('Page', {:id => 1, :urlname => 'lulu'}) }
12
+ let(:element) { mock_model('Element', {:id => 1, :page_id => page.id, :public => true, :display_name_with_preview_text => 'lalaa', :dom_id => 1}) }
11
13
 
12
- let(:page) { mock_model('Page', {:id => 1, :urlname => 'lulu'}) }
13
- let(:element) { mock_model('Element', {:id => 1, :page_id => page.id, :public => true, :display_name_with_preview_text => 'lalaa', :dom_id => 1}) }
14
+ describe '#list' do
14
15
 
15
- it "should return a select tag with elements" do
16
- Alchemy::Page.should_receive(:find_by_urlname_and_language_id).and_return(page)
17
- Alchemy::Element.should_receive(:find_all_by_page_id_and_public).and_return([element])
18
- get :list, {:page_urlname => page.urlname, :format => :js}
19
- response.body.should match(/select(.*)elements_from_page_selector(.*)option/)
20
- end
16
+ render_views
17
+
18
+ it "should return a select tag with elements" do
19
+ Alchemy::Page.should_receive(:find_by_urlname_and_language_id).and_return(page)
20
+ Alchemy::Element.should_receive(:find_all_by_page_id_and_public).and_return([element])
21
+ get :list, {:page_urlname => page.urlname, :format => :js}
22
+ response.body.should match(/select(.*)elements_from_page_selector(.*)option/)
23
+ end
24
+
25
+ end
26
+
27
+ describe '#new' do
28
+
29
+ context "elements in clipboard" do
30
+
31
+ let(:clipboard) { session[:clipboard] = Clipboard.new }
32
+
33
+ before(:each) do
34
+ clipboard[:elements] = [{:id => element.id, :action => 'copy'}]
35
+ end
36
+
37
+ it "should load all elements from clipboard" do
38
+ get :new, {:page_id => page.id, :format => :js}
39
+ assigns(:clipboard_items).should be_kind_of(Array)
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe '#create' do
21
47
 
48
+ render_views
49
+
50
+ context "with paste_from_clipboard in parameters" do
51
+
52
+ let(:clipboard) { session[:clipboard] = Clipboard.new }
53
+ let(:element_in_clipboard) { @element ||= FactoryGirl.create(:element, :page_id => page.id) }
54
+
55
+ before(:each) do
56
+ clipboard[:elements] = [{:id => element_in_clipboard.id, :action => 'cut'}]
57
+ end
58
+
59
+ it "should create an element from clipboard" do
60
+ post :create, {:paste_from_clipboard => element_in_clipboard.id, :element => {:page_id => page.id}, :format => :js}
61
+ response.status.should == 200
62
+ response.body.should match(/Succesfully added new element/)
63
+ end
64
+
65
+ context "and with cut as action parameter" do
66
+
67
+ it "should also remove the element id from clipboard" do
68
+ post :create, {:paste_from_clipboard => element_in_clipboard.id, :element => {:page_id => page.id}, :format => :js}
69
+ session[:clipboard].contains?(:elements, element_in_clipboard.id).should_not be_true
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end
22
79
  end
@@ -1,51 +1,97 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Admin::PagesController do
3
+ module Alchemy
4
+ describe Admin::PagesController do
4
5
 
5
- before(:each) do
6
- activate_authlogic
7
- Alchemy::UserSession.create FactoryGirl.create(:admin_user)
8
- end
6
+ before(:each) do
7
+ activate_authlogic
8
+ Alchemy::UserSession.create FactoryGirl.create(:admin_user)
9
+ end
9
10
 
10
- describe "#flush" do
11
+ describe "#flush" do
12
+
13
+ it "should remove the cache of all pages" do
14
+ post :flush, {:format => :js}
15
+ response.status.should == 200
16
+ end
11
17
 
12
- it "should remove the cache of all pages" do
13
- post :flush, {:format => :js}
14
- response.status.should == 200
15
18
  end
16
19
 
17
- end
20
+ describe '#new' do
18
21
 
19
- describe '#copy_language_tree' do
22
+ context "pages in clipboard" do
20
23
 
21
- before(:each) do
22
- @language = Alchemy::Language.get_default
23
- @language_root = FactoryGirl.create(:language_root_page, :language => @language, :name => 'Intro')
24
- @level_1 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @language_root.id, :visible => true, :name => 'Level 1')
25
- @level_2 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_1.id, :visible => true, :name => 'Level 2')
26
- @level_3 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_2.id, :visible => true, :name => 'Level 3')
27
- @level_4 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_3.id, :visible => true, :name => 'Level 4')
28
- @new_language = FactoryGirl.create(:language)
29
- session[:language_code] = @new_language.code
30
- session[:language_id] = @new_language.id
31
- post :copy_language_tree, {:languages => {:new_lang_id => @new_language.id, :old_lang_id => @language.id}}
32
- @new_lang_root = Alchemy::Page.language_root_for(@new_language.id)
33
- end
24
+ let(:clipboard) { session[:clipboard] = Clipboard.new }
25
+ let(:page) { mock_model('Page', {:id => 10, :name => 'Foobar', :parent_id => 1}) }
26
+
27
+ before(:each) do
28
+ clipboard[:pages] = [{:id => page.id, :action => 'copy'}]
29
+ end
30
+
31
+ it "should load all pages from clipboard" do
32
+ get :new, {:page_id => page.id, :format => :js}
33
+ assigns(:clipboard_items).should be_kind_of(Array)
34
+ end
35
+
36
+ end
34
37
 
35
- it "should copy all pages" do
36
- @new_lang_root.should_not be_nil
37
- @new_lang_root.descendants.count.should == 4
38
- @new_lang_root.descendants.collect(&:name).should == ["Level 1 (Copy)", "Level 2 (Copy)", "Level 3 (Copy)", "Level 4 (Copy)"]
39
38
  end
40
39
 
41
- it "should not set layoutpage attribute to nil" do
42
- @new_lang_root.layoutpage.should_not be_nil
40
+ describe '#create' do
41
+
42
+ render_views
43
+
44
+ context "with paste_from_clipboard in parameters" do
45
+
46
+ let(:clipboard) { session[:clipboard] = Clipboard.new }
47
+ let(:page_in_clipboard) { @page ||= FactoryGirl.create(:public_page) }
48
+ let(:parent) { @page ||= FactoryGirl.create(:public_page) }
49
+
50
+ before(:each) do
51
+ clipboard[:pages] = [{:id => page_in_clipboard.id, :action => 'cut'}]
52
+ end
53
+
54
+ it "should create a page from clipboard" do
55
+ post :create, {:paste_from_clipboard => page_in_clipboard.id, :page => {:parent_id => parent.id}, :format => :js}
56
+ response.status.should == 200
57
+ response.body.should match /window.location.*admin.*pages/
58
+ end
59
+
60
+ end
61
+
43
62
  end
44
63
 
45
- it "should not set layoutpage attribute to true" do
46
- @new_lang_root.layoutpage.should_not be_true
64
+ describe '#copy_language_tree' do
65
+
66
+ before(:each) do
67
+ @language = Alchemy::Language.get_default
68
+ @language_root = FactoryGirl.create(:language_root_page, :language => @language, :name => 'Intro')
69
+ @level_1 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @language_root.id, :visible => true, :name => 'Level 1')
70
+ @level_2 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_1.id, :visible => true, :name => 'Level 2')
71
+ @level_3 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_2.id, :visible => true, :name => 'Level 3')
72
+ @level_4 = FactoryGirl.create(:public_page, :language => @language, :parent_id => @level_3.id, :visible => true, :name => 'Level 4')
73
+ @new_language = FactoryGirl.create(:language)
74
+ session[:language_code] = @new_language.code
75
+ session[:language_id] = @new_language.id
76
+ post :copy_language_tree, {:languages => {:new_lang_id => @new_language.id, :old_lang_id => @language.id}}
77
+ @new_lang_root = Alchemy::Page.language_root_for(@new_language.id)
78
+ end
79
+
80
+ it "should copy all pages" do
81
+ @new_lang_root.should_not be_nil
82
+ @new_lang_root.descendants.count.should == 4
83
+ @new_lang_root.descendants.collect(&:name).should == ["Level 1 (Copy)", "Level 2 (Copy)", "Level 3 (Copy)", "Level 4 (Copy)"]
84
+ end
85
+
86
+ it "should not set layoutpage attribute to nil" do
87
+ @new_lang_root.layoutpage.should_not be_nil
88
+ end
89
+
90
+ it "should not set layoutpage attribute to true" do
91
+ @new_lang_root.layoutpage.should_not be_true
92
+ end
93
+
47
94
  end
48
95
 
49
96
  end
50
-
51
97
  end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ module Alchemy
4
+ describe Clipboard do
5
+
6
+ let(:clipboard) { Clipboard.new }
7
+
8
+ describe "#new" do
9
+ it "should be a hash with empty elements and pages collections" do
10
+ clipboard[:elements].should == []
11
+ clipboard[:pages].should == []
12
+ end
13
+ end
14
+
15
+ describe '#push' do
16
+ it "should add item to clipboard category" do
17
+ clipboard.push :elements, {:id => 1}
18
+ clipboard[:elements].should == [{:id => 1}]
19
+ end
20
+ end
21
+
22
+ describe '#replace' do
23
+
24
+ it "should replace the category items with new item" do
25
+ clipboard.replace(:elements, {:id => 1})
26
+ clipboard[:elements].should == [{:id => 1}]
27
+ end
28
+
29
+ it "should replace the category items with new item collection" do
30
+ clipboard.replace(:elements, [{:id => 1}])
31
+ clipboard[:elements].should == [{:id => 1}]
32
+ end
33
+
34
+ it "should be aliased with []= " do
35
+ clipboard[:elements] = [{:id => 1}]
36
+ clipboard[:elements].should == [{:id => 1}]
37
+ end
38
+
39
+ end
40
+
41
+ describe '#empty?' do
42
+ it "should return true if clipboard is empty" do
43
+ clipboard.empty?.should be_true
44
+ end
45
+ end
46
+
47
+ context "full clipboard" do
48
+
49
+ before(:all) do
50
+ clipboard[:elements] = [{:id => 1}, {:id => 2}]
51
+ clipboard[:pages] = [{:id => 2}, {:id => 3}]
52
+ end
53
+
54
+ describe "#all" do
55
+
56
+ context "with :elements as parameter" do
57
+ it "should return all element items in clipboard" do
58
+ clipboard[:elements].should == [{:id => 1}, {:id => 2}]
59
+ end
60
+ end
61
+
62
+ context "with :pages as parameter" do
63
+ it "should return all page items in clipboard" do
64
+ clipboard[:pages].should == [{:id => 2}, {:id => 3}]
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ describe '#contains?' do
71
+ it "should return true if elements id is in collection" do
72
+ clipboard.contains?(:elements, 1).should be_true
73
+ end
74
+ end
75
+
76
+ describe '#remove' do
77
+ it "should remove item from category collection" do
78
+ clipboard.remove(:elements, 1)
79
+ clipboard[:elements].should == [{:id => 2}]
80
+ end
81
+ end
82
+
83
+ describe '#clear' do
84
+ it "should clear complete category collection" do
85
+ clipboard.clear(:elements)
86
+ clipboard[:elements].should be_empty
87
+ end
88
+ end
89
+
90
+ describe '#get' do
91
+ it "should return element from collection" do
92
+ clipboard[:elements] = [{:id => 1}]
93
+ clipboard.get(:elements, 1).should == {:id => 1}
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+ end