alchemy_cms 2.3.2 → 2.4.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.gitignore +1 -2
  2. data/.travis.yml +1 -5
  3. data/Gemfile +4 -4
  4. data/README.md +22 -15
  5. data/alchemy_cms.gemspec +38 -38
  6. data/app/assets/javascripts/alchemy/alchemy.base.js +2 -2
  7. data/app/assets/javascripts/alchemy/alchemy.buttons.js.coffee +31 -0
  8. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js +1 -1
  9. data/app/assets/javascripts/alchemy/alchemy.elements_window.js +24 -15
  10. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +9 -3
  11. data/app/assets/javascripts/alchemy/alchemy.jquery_loader.js +2 -2
  12. data/app/assets/javascripts/alchemy/alchemy.js +1 -0
  13. data/app/assets/javascripts/alchemy/alchemy.menubar.js +4 -12
  14. data/app/assets/javascripts/alchemy/alchemy.onload.js.coffee +32 -0
  15. data/app/assets/javascripts/alchemy/alchemy.windows.js +4 -4
  16. data/app/assets/stylesheets/alchemy/_defaults.scss +0 -1
  17. data/app/assets/stylesheets/alchemy/alchemy.css +2 -1
  18. data/app/assets/stylesheets/alchemy/base.css.scss +2 -54
  19. data/app/assets/stylesheets/alchemy/elements.css.scss +8 -5
  20. data/app/assets/stylesheets/alchemy/errors.css.scss +51 -0
  21. data/app/assets/stylesheets/alchemy/flash.css.scss +0 -2
  22. data/app/assets/stylesheets/alchemy/form_elements.css.scss +31 -75
  23. data/app/assets/stylesheets/alchemy/icons.css.scss +5 -5
  24. data/app/assets/stylesheets/alchemy/menubar.css.scss +0 -2
  25. data/app/assets/stylesheets/alchemy/sitemap.css.scss +0 -1
  26. data/app/assets/stylesheets/alchemy/tables.css.scss +3 -1
  27. data/app/controllers/alchemy/admin/base_controller.rb +19 -12
  28. data/app/controllers/alchemy/admin/elements_controller.rb +52 -24
  29. data/app/controllers/alchemy/admin/pages_controller.rb +11 -5
  30. data/app/controllers/alchemy/admin/resources_controller.rb +3 -4
  31. data/app/controllers/alchemy/admin/users_controller.rb +1 -0
  32. data/app/controllers/alchemy/base_controller.rb +34 -8
  33. data/app/controllers/alchemy/pictures_controller.rb +16 -1
  34. data/app/controllers/alchemy/user_sessions_controller.rb +6 -1
  35. data/app/helpers/alchemy/base_helper.rb +14 -0
  36. data/app/helpers/alchemy/elements_helper.rb +10 -5
  37. data/app/helpers/alchemy/pages_helper.rb +1 -2
  38. data/app/helpers/alchemy/url_helper.rb +43 -24
  39. data/app/models/alchemy/element.rb +23 -16
  40. data/app/models/alchemy/page.rb +25 -14
  41. data/app/models/alchemy/picture.rb +24 -0
  42. data/app/views/alchemy/admin/contents/create.js.erb +1 -1
  43. data/app/views/alchemy/admin/elements/_new_element_form.html.erb +1 -1
  44. data/app/views/alchemy/admin/elements/create.js.erb +11 -3
  45. data/app/views/alchemy/admin/elements/fold.js.erb +1 -1
  46. data/app/views/alchemy/admin/elements/new.html.erb +1 -1
  47. data/app/views/alchemy/admin/elements/update.js.erb +1 -1
  48. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +1 -1
  49. data/app/views/alchemy/admin/languages/_form.html.erb +1 -1
  50. data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -1
  51. data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
  52. data/app/views/alchemy/admin/pages/configure.html.erb +10 -6
  53. data/app/views/alchemy/admin/pages/configure_external.html.erb +1 -1
  54. data/app/views/alchemy/admin/pages/edit.html.erb +1 -2
  55. data/app/views/alchemy/admin/pages/new.html.erb +2 -2
  56. data/app/views/alchemy/admin/pages/update.js.erb +10 -2
  57. data/app/views/alchemy/admin/partials/_sub_navigation_tab.html.erb +5 -5
  58. data/app/views/alchemy/admin/pictures/_filter_bar.html.erb +2 -1
  59. data/app/views/alchemy/admin/pictures/_picture.html.erb +2 -2
  60. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +2 -1
  61. data/app/views/alchemy/admin/pictures/show_in_window.html.erb +3 -2
  62. data/app/views/alchemy/admin/resources/_form.html.erb +1 -1
  63. data/app/views/alchemy/admin/users/_table.html.erb +4 -4
  64. data/app/views/alchemy/admin/users/edit.html.erb +1 -1
  65. data/app/views/alchemy/admin/users/new.html.erb +1 -1
  66. data/app/views/alchemy/base/error_notice.js.erb +1 -1
  67. data/app/views/alchemy/base/remote_errors.js.erb +2 -3
  68. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +10 -7
  69. data/app/views/alchemy/essences/_essence_picture_view.html.erb +24 -21
  70. data/app/views/layouts/alchemy/admin.html.erb +9 -31
  71. data/bin/alchemy +20 -24
  72. data/config/alchemy/config.yml +6 -0
  73. data/config/alchemy/page_layouts.yml +2 -0
  74. data/config/authorization_rules.rb +1 -1
  75. data/config/locales/alchemy.de.yml +3 -0
  76. data/config/locales/alchemy.en.yml +4 -1
  77. data/db/migrate/20121026100815_alchemy_two_point_three.rb +312 -0
  78. data/lib/alchemy/mount_point.rb +9 -3
  79. data/lib/alchemy/page_layout.rb +89 -73
  80. data/lib/alchemy/version.rb +1 -1
  81. data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +45 -12
  82. data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +3 -1
  83. data/lib/rails/generators/alchemy/essence/essence_generator.rb +51 -0
  84. data/lib/rails/generators/alchemy/essence/templates/editor.html.erb +18 -0
  85. data/lib/rails/generators/alchemy/essence/templates/view.html.erb +2 -0
  86. data/lib/rails/templates/alchemy.rb +1 -1
  87. data/lib/tasks/install.rake +57 -2
  88. data/spec/controllers/admin/elements_controller_spec.rb +170 -22
  89. data/spec/controllers/admin/trash_controller_spec.rb +1 -1
  90. data/spec/controllers/admin/users_controller_spec.rb +36 -0
  91. data/spec/controllers/base_controller_spec.rb +12 -1
  92. data/spec/controllers/elements_controller_spec.rb +17 -13
  93. data/spec/controllers/pictures_controller_spec.rb +4 -4
  94. data/spec/dummy/config/application.rb +1 -1
  95. data/spec/dummy/db/migrate/20121026100815_alchemy_two_point_three.rb +312 -0
  96. data/spec/dummy/db/migrate/20121026104128_create_events.rb +19 -0
  97. data/spec/dummy/db/schema.rb +1 -1
  98. data/spec/factories.rb +0 -1
  99. data/spec/helpers/base_helper_spec.rb +48 -0
  100. data/spec/helpers/elements_helper_spec.rb +14 -3
  101. data/spec/helpers/url_helper_spec.rb +8 -3
  102. data/spec/integration/picture_security_spec.rb +35 -0
  103. data/spec/integration/translation_integration_spec.rb +6 -5
  104. data/spec/models/element_spec.rb +5 -5
  105. data/spec/models/page_layout_spec.rb +10 -16
  106. data/spec/models/page_spec.rb +25 -2
  107. data/spec/models/picture_spec.rb +24 -2
  108. data/spec/routing_spec.rb +115 -115
  109. data/spec/support/alchemy/specs_helpers.rb +4 -4
  110. data/{app/assets/images/alchemy → vendor/assets/images}/Jcrop.gif +0 -0
  111. data/vendor/assets/javascripts/jquery_plugins/jquery.Jcrop.min.js +19 -243
  112. data/vendor/assets/javascripts/jquery_plugins/jquery.selectboxit.min.js +1 -0
  113. data/vendor/assets/javascripts/jquery_plugins/jquery.ui.tabspaging.js +6 -6
  114. data/vendor/assets/stylesheets/jquery.Jcrop.min.css +28 -0
  115. metadata +48 -82
  116. data/app/assets/javascripts/alchemy/alchemy.buttons.js +0 -50
  117. data/app/assets/stylesheets/alchemy/jquery.Jcrop.css.scss +0 -54
  118. data/app/helpers/alchemy/pictures_helper.rb +0 -19
  119. data/db/migrate/20100607143125_create_pages.rb +0 -34
  120. data/db/migrate/20100607144254_create_elements.rb +0 -20
  121. data/db/migrate/20100607145256_create_contents.rb +0 -18
  122. data/db/migrate/20100607145719_create_users.rb +0 -32
  123. data/db/migrate/20100607150611_create_pictures.rb +0 -16
  124. data/db/migrate/20100607150812_create_attachments.rb +0 -16
  125. data/db/migrate/20100607153647_create_folded_pages.rb +0 -13
  126. data/db/migrate/20100607161345_create_essence_texts.rb +0 -19
  127. data/db/migrate/20100607162339_create_elements_pages.rb +0 -12
  128. data/db/migrate/20100607193638_create_essence_pictures.rb +0 -23
  129. data/db/migrate/20100607193646_create_essence_richtexts.rb +0 -16
  130. data/db/migrate/20100607193653_create_essence_htmls.rb +0 -13
  131. data/db/migrate/20100609111653_create_essence_dates.rb +0 -13
  132. data/db/migrate/20100609111809_create_essence_files.rb +0 -15
  133. data/db/migrate/20100609111821_create_essence_flashes.rb +0 -16
  134. data/db/migrate/20100609111837_create_essence_videos.rb +0 -18
  135. data/db/migrate/20100616150753_create_essence_audios.rb +0 -17
  136. data/db/migrate/20100812085225_add_crop_from_and_crop_size_to_essence_pictures.rb +0 -11
  137. data/db/migrate/20100909140701_change_essence_htmls_source_column_type.rb +0 -9
  138. data/db/migrate/20101109150312_alter_pages_visible_column_default.rb +0 -9
  139. data/db/migrate/20101109151812_create_languages.rb +0 -19
  140. data/db/migrate/20101216151419_add_language_id_to_pages.rb +0 -27
  141. data/db/migrate/20101216155216_add_index_to_languages.rb +0 -9
  142. data/db/migrate/20101216173323_add_default_to_languages.rb +0 -9
  143. data/db/migrate/20101218130049_add_urlname_index_to_pages.rb +0 -9
  144. data/db/migrate/20110115123343_remove_css_class_default_from_essence_pictures.rb +0 -11
  145. data/db/migrate/20110224105120_change_pages_visible_default.rb +0 -11
  146. data/db/migrate/20110228182659_remove_default_page_layout_from_pages.rb +0 -11
  147. data/db/migrate/20110414163140_remove_display_name_from_elements.rb +0 -11
  148. data/db/migrate/20110511100516_rename_essence_texts_title_to_link_title.rb +0 -9
  149. data/db/migrate/20110529130429_create_cells.rb +0 -14
  150. data/db/migrate/20110529130500_add_cell_id_to_elements.rb +0 -11
  151. data/db/migrate/20110530102804_change_pages_page_layout_column.rb +0 -11
  152. data/db/migrate/20110707190728_add_render_size_to_essence_pictures.rb +0 -9
  153. data/db/migrate/20110711142057_change_open_link_in_new_window_to_link_target.rb +0 -19
  154. data/db/migrate/20110919110451_add_default_role_to_users.rb +0 -9
  155. data/db/migrate/20111116125112_namespace_alchemy_models.rb +0 -23
  156. data/db/migrate/20120216135355_add_country_code_to_languages.rb +0 -9
  157. data/db/migrate/20120608085509_create_alchemy_essence_selects.rb +0 -11
  158. data/db/migrate/20120611221734_create_alchemy_essence_booleans.rb +0 -11
  159. data/db/migrate/20120704181529_add_upload_hash_to_alchemy_picture.rb +0 -5
  160. data/db/migrate/20120705214247_acts_as_taggable_on_migration.rb +0 -28
  161. data/db/migrate/20120728185830_add_cached_tag_list_to_alchemy_pictures.rb +0 -5
  162. data/db/migrate/20120831135441_set_alchemy_languages_country_code_default_to_empty_string.rb +0 -9
  163. data/spec/helpers/pictures_helper_spec.rb +0 -14
  164. data/vendor/assets/javascripts/jquery_plugins/jquery.selectBoxIt.js +0 -1909
@@ -0,0 +1,19 @@
1
+ class CreateEvents < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table "events" do |t|
5
+ t.string "name"
6
+ t.string "hidden_name"
7
+ t.datetime "starts_at"
8
+ t.datetime "ends_at"
9
+ t.text "description"
10
+ t.decimal "entrance_fee", :precision => 6, :scale => 2
11
+ t.boolean "published"
12
+ t.integer "location_id"
13
+ t.integer "organizer_id"
14
+ t.datetime "created_at", :null => false
15
+ t.datetime "updated_at", :null => false
16
+ end
17
+ end
18
+
19
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120831135441) do
14
+ ActiveRecord::Schema.define(:version => 20121026104128) do
15
15
 
16
16
  create_table "alchemy_attachments", :force => true do |t|
17
17
  t.string "name"
@@ -5,7 +5,6 @@ FactoryGirl.define do
5
5
  login "jdoe"
6
6
  password 's3cr3t'
7
7
  password_confirmation 's3cr3t'
8
- language 'en'
9
8
 
10
9
  factory :admin_user do
11
10
  role "admin"
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module Alchemy
4
+ describe BaseHelper do
5
+
6
+ describe "#render_message" do
7
+
8
+ context "if no argument is passed" do
9
+ it "should render a div with an info icon and the given content" do
10
+ helper.render_message{ content_tag(:p, "my notice") }.should match(/<div class="info message"><span class="icon info"><\/span><p>my notice/)
11
+ end
12
+ end
13
+
14
+ context "if an argument is passed" do
15
+ it "should render the passed argument as the css classname for the icon container" do
16
+ helper.render_message(:error){ content_tag(:p, "my notice") }.should match(/<div class="error message"><span class="icon error">/)
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ describe "#configuration" do
23
+ it "should return certain configuration options" do
24
+ Config.stub!(:show).and_return({"some_option" => true})
25
+ helper.configuration(:some_option).should == true
26
+ end
27
+ end
28
+
29
+ describe "#multi_language?" do
30
+
31
+ context "if more than one published language exists" do
32
+ it "should return true" do
33
+ Alchemy::Language.stub_chain(:published, :count).and_return(2)
34
+ helper.multi_language?.should == true
35
+ end
36
+ end
37
+
38
+ context "if less than two published languages exists" do
39
+ it "should return false" do
40
+ Alchemy::Language.stub_chain(:published, :count).and_return(1)
41
+ helper.multi_language?.should == false
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -128,10 +128,21 @@ describe Alchemy::ElementsHelper do
128
128
  end
129
129
 
130
130
  context "with option fallback" do
131
+ before do
132
+ @another_page = FactoryGirl.create(:public_page, :name => 'Another Page', :page_layout => 'news')
133
+ @another_element_1 = FactoryGirl.create(:element, :page => @another_page, :name => 'news')
134
+ end
135
+
131
136
  it "should render the fallback element, when no element with the given name is found" do
132
- @page.elements.delete_all
133
- @another_element_1 = FactoryGirl.create(:element, :page => @page)
134
- helper.render_elements(:fallback => {:for => 'foo', :with => @another_element_1.name, :from => @page.page_layout}).should match(/id="#{@another_element_1.name}_#{@another_element_1.id}"/)
137
+ helper.render_elements(
138
+ :fallback => {:for => 'higgs', :with => 'news', :from => 'news'}
139
+ ).should match(/id="news_#{@another_element_1.id}"/)
140
+ end
141
+
142
+ it "should also take a page object as fallback from" do
143
+ helper.render_elements(
144
+ :fallback => {:for => 'higgs', :with => 'news', :from => @another_page}
145
+ ).should match(/id="news_#{@another_element_1.id}"/)
135
146
  end
136
147
  end
137
148
 
@@ -123,12 +123,12 @@ module Alchemy
123
123
 
124
124
  describe 'picture path helpers' do
125
125
 
126
- let(:picture) { mock_model(Picture, :urlname => 'cute_kitten', :id => 42) }
126
+ let(:picture) { stub_model(Picture, :urlname => 'cute_kitten', :id => 42) }
127
127
 
128
128
  describe '#show_alchemy_picture_path' do
129
129
 
130
130
  it "should return the correct relative path string" do
131
- helper.show_alchemy_picture_path(picture).should == "/alchemy/pictures/42/show/cute_kitten.jpg"
131
+ helper.show_alchemy_picture_path(picture).should =~ Regexp.new("/alchemy/pictures/42/show/cute_kitten.jpg")
132
132
  end
133
133
 
134
134
  end
@@ -136,7 +136,7 @@ module Alchemy
136
136
  describe '#show_alchemy_picture_url' do
137
137
 
138
138
  it "should return the correct url string" do
139
- helper.show_alchemy_picture_url(picture).should == "http://#{helper.request.host}/alchemy/pictures/42/show/cute_kitten.jpg"
139
+ helper.show_alchemy_picture_url(picture).should =~ Regexp.new("http://#{helper.request.host}/alchemy/pictures/42/show/cute_kitten.jpg")
140
140
  end
141
141
 
142
142
  end
@@ -147,6 +147,11 @@ module Alchemy
147
147
  helper.show_picture_path_params(picture).should include(:name => 'cute_kitten', :format => 'jpg')
148
148
  end
149
149
 
150
+ it "should include the secure hash parameter" do
151
+ helper.show_picture_path_params(picture).keys.should include(:sh)
152
+ helper.show_picture_path_params(picture)[:sh].should_not be_empty
153
+ end
154
+
150
155
  context "with additional params" do
151
156
 
152
157
  it "should include these params" do
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Picture renderung security', :js => true do
4
+
5
+ let(:picture) { Alchemy::Picture.create(:image_file => File.new(File.expand_path('../../support/image.png', __FILE__))) }
6
+
7
+ # Prevent the signup view from being rendered.
8
+ before { Alchemy::User.stub!(:count).and_return 1 }
9
+
10
+ context "passing no security token" do
11
+
12
+ it 'should return a bad request (400)' do
13
+ visit "/alchemy/pictures/#{picture.id}/show/image.png"
14
+ page.status_code.should == 400
15
+ end
16
+
17
+ end
18
+
19
+ context "passing correct security token" do
20
+
21
+ before do
22
+ visit "/alchemy/pictures/#{picture.id}/show/image.png?sh=#{picture.security_token}"
23
+ end
24
+
25
+ it 'should return image' do
26
+ page.body.should match(/img/)
27
+ end
28
+
29
+ it 'should return status ok (200)' do
30
+ page.status_code.should == 200
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -4,34 +4,33 @@ describe "Translation integration" do
4
4
 
5
5
  context "in admin backend" do
6
6
 
7
- it "should be possible to set the locale of the admin backend via params" do
7
+ before do
8
8
  authorize_as_admin
9
+ end
10
+
11
+ it "should be possible to set the locale of the admin backend via params" do
9
12
  visit admin_dashboard_path(:locale => :de)
10
13
  page.should have_content('Willkommen')
11
14
  end
12
15
 
13
16
  it "should store the current locale in the session" do
14
- authorize_as_admin
15
17
  visit admin_dashboard_path(:locale => :de)
16
18
  visit admin_dashboard_path
17
19
  page.should have_content('Willkommen')
18
20
  end
19
21
 
20
22
  it "should be possible to change the current locale in the session" do
21
- authorize_as_admin
22
23
  visit admin_dashboard_path(:locale => :de)
23
24
  visit admin_dashboard_path(:locale => :en)
24
25
  page.should have_content('Welcome')
25
26
  end
26
27
 
27
28
  it "should not be possible to switch the locale of the admin backend to an unknown locale" do
28
- authorize_as_admin
29
29
  visit admin_dashboard_path(:locale => :ko)
30
30
  page.should have_content('Welcome')
31
31
  end
32
32
 
33
33
  it "should use the current users language setting if no other parameter is given" do
34
- authorize_as_admin(locale = nil)
35
34
  Alchemy::User.first.update_attributes(:language => :de)
36
35
  visit admin_dashboard_path
37
36
  page.should have_content('Willkommen')
@@ -42,6 +41,8 @@ describe "Translation integration" do
42
41
  context "with translated header" do
43
42
 
44
43
  before do
44
+ # Hack my hack.... OMG
45
+ Rails.stub(:env).and_return('foo')
45
46
  Capybara.current_driver = :rack_test_translated_header
46
47
  end
47
48
 
@@ -6,26 +6,26 @@ module Alchemy
6
6
  describe '#new_from_scratch' do
7
7
 
8
8
  it "should initialize an element by name from scratch" do
9
- el = Element.new_from_scratch({'name' => 'article'})
9
+ el = Element.new_from_scratch({:name => 'article'})
10
10
  el.should be_valid
11
11
  end
12
12
 
13
13
  it "should raise an error if the given name is not defined in the elements.yml" do
14
- expect { Element.new_from_scratch({'name' => 'foobar'}) }.to raise_error
14
+ expect { Element.new_from_scratch({:name => 'foobar'}) }.to raise_error
15
15
  end
16
16
 
17
17
  it "should take the first part of an given name containing a hash (#)" do
18
- el = Element.new_from_scratch({'name' => 'article#header'})
18
+ el = Element.new_from_scratch({:name => 'article#header'})
19
19
  el.name.should == "article"
20
20
  end
21
21
 
22
22
  it "should merge given attributes into defined ones" do
23
- el = Element.new_from_scratch({'name' => 'article', 'page_id' => 1})
23
+ el = Element.new_from_scratch({:name => 'article', :page_id => 1})
24
24
  el.page_id.should == 1
25
25
  end
26
26
 
27
27
  it "should not have forbidden attributes from definition" do
28
- el = Element.new_from_scratch({'name' => 'article'})
28
+ el = Element.new_from_scratch({:name => 'article'})
29
29
  el.contents.should == []
30
30
  end
31
31
 
@@ -3,28 +3,22 @@ require 'spec_helper'
3
3
  module Alchemy
4
4
  describe PageLayout do
5
5
 
6
- context "method get_layouts" do
6
+ describe ".all" do
7
7
 
8
- it "should generally return page_layouts, nothing else!" do
9
- PageLayout.read_layouts_file.should be_instance_of(Array)
8
+ it "should return all page_layouts" do
9
+ layouts = PageLayout.all
10
+ layouts.should be_instance_of(Array)
11
+ layouts.collect { |l| l['name'] }.should include('standard')
10
12
  end
11
13
 
12
14
  end
13
15
 
14
- context "with custom page layouts" do
16
+ describe '.layouts_with_own_for_select' do
15
17
 
16
- it "should return the users page_layouts if exists in the application" do
17
- @config_path = Rails.root.join("config/alchemy")
18
- FileUtils.mv(File.join(@config_path, 'page_layouts.yml'), File.join(@config_path, 'page_layouts.bak'))
19
- layouts_file = File.join(@config_path, 'page_layouts.yml')
20
- File.open(layouts_file, 'w') do |page_layouts|
21
- page_layouts.puts "- name: testlayout\n elements:"
22
- end
23
- PageLayout.read_layouts_file.first.values.should include("testlayout")
24
- end
25
-
26
- after(:each) do
27
- FileUtils.mv(File.join(@config_path, 'page_layouts.bak'), File.join(@config_path, 'page_layouts.yml'))
18
+ it "should not hold a layout twice" do
19
+ layouts = PageLayout.layouts_with_own_for_select('standard', 1, false)
20
+ layouts = layouts.collect(&:last)
21
+ layouts.select { |l| l == "standard" }.length.should == 1
28
22
  end
29
23
 
30
24
  end
@@ -252,10 +252,10 @@ module Alchemy
252
252
  end
253
253
  end
254
254
 
255
- context ".accessible" do
255
+ context ".not_restricted" do
256
256
  it "should return 2 accessible pages" do
257
257
  FactoryGirl.create(:public_page, :name => 'First Public Child', :restricted => true, :parent_id => language_root.id, :language => language)
258
- Page.accessible.should have(2).pages
258
+ Page.not_restricted.should have(2).pages
259
259
  end
260
260
  end
261
261
 
@@ -445,6 +445,12 @@ module Alchemy
445
445
  @page.elements.should_not be_empty
446
446
  end
447
447
 
448
+ it "should not autogenerate elements that are already on the page" do
449
+ @page.elements << FactoryGirl.create(:element, :name => 'header')
450
+ @page.save
451
+ @page.elements.select { |e| e.name == 'header' }.length.should == 1
452
+ end
453
+
448
454
  context "with cells" do
449
455
 
450
456
  before do
@@ -531,6 +537,23 @@ module Alchemy
531
537
 
532
538
  end
533
539
 
540
+ context "after changing the page layout" do
541
+
542
+ let(:news_element) { FactoryGirl.create(:element, :name => 'news') }
543
+
544
+ it "all elements not allowed on this page should be trashed" do
545
+ news_page.elements << news_element
546
+ news_page.update_attributes :page_layout => 'standard'
547
+ news_page.elements.trashed.should include(news_element)
548
+ end
549
+
550
+ it "should autogenerate elements" do
551
+ news_page.update_attributes :page_layout => 'standard'
552
+ news_page.elements.available.collect(&:name).should include('header')
553
+ end
554
+
555
+ end
556
+
534
557
  end
535
558
 
536
559
  describe '#fold' do
@@ -61,7 +61,29 @@ module Alchemy
61
61
 
62
62
  end
63
63
 
64
- describe '#self.last_upload' do
64
+ describe '#security_token' do
65
+
66
+ before do
67
+ @pic = stub_model(Picture, :id => 1)
68
+ end
69
+
70
+ it "should return a sha1 hash" do
71
+ @pic.security_token.should match(/\b([a-f0-9]{16})\b/)
72
+ end
73
+
74
+ it "should return a 16 chars long hash" do
75
+ @pic.security_token.length == 16
76
+ end
77
+
78
+ it "should convert crop true value into string" do
79
+ p = [@pic.id, nil, 'crop', nil, nil, Rails.configuration.secret_token].join('-')
80
+ digest = Digest::SHA1.hexdigest(p)[0..15]
81
+ @pic.security_token(:crop => true).should == digest
82
+ end
83
+
84
+ end
85
+
86
+ describe '.last_upload' do
65
87
 
66
88
  it "should return all pictures that have the same upload-hash as the most recent picture" do
67
89
  other_upload = Picture.create!(:image_file => image_file, :upload_hash => '456')
@@ -77,7 +99,7 @@ module Alchemy
77
99
 
78
100
  end
79
101
 
80
- describe '#self.recent' do
102
+ describe '.recent' do
81
103
 
82
104
  before(:all) do
83
105
  now = Time.now
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "The Routing", :type => :routing do
4
4
 
5
- before { @routes = Alchemy::Engine.routes }
5
+ before(:each) { @routes = Alchemy::Engine.routes }
6
6
 
7
7
  context "for downloads" do
8
8
 
@@ -10,44 +10,44 @@ describe "The Routing", :type => :routing do
10
10
  {
11
11
  :get => "/attachment/32/download/Presseveranstaltung.pdf"
12
12
  }.should route_to(
13
- :controller => "alchemy/attachments",
14
- :action => "download",
15
- :id => "32",
16
- :name => "Presseveranstaltung",
17
- :format => "pdf"
18
- )
13
+ :controller => "alchemy/attachments",
14
+ :action => "download",
15
+ :id => "32",
16
+ :name => "Presseveranstaltung",
17
+ :format => "pdf"
18
+ )
19
19
  end
20
20
 
21
21
  it "should have a route for legacy Alchemy 1.x downloads" do
22
22
  {
23
23
  :get => "/attachment/32/download?name=Presseveranstaltung.pdf"
24
24
  }.should route_to(
25
- :controller => "alchemy/attachments",
26
- :action => "download",
27
- :id => "32"
28
- )
25
+ :controller => "alchemy/attachments",
26
+ :action => "download",
27
+ :id => "32"
28
+ )
29
29
  end
30
30
 
31
31
  it "should have a route for legacy washAPP downloads" do
32
32
  {
33
33
  :get => "/wa_files/download/11"
34
34
  }.should route_to(
35
- :controller => "alchemy/attachments",
36
- :action => "download",
37
- :id => "11"
38
- )
35
+ :controller => "alchemy/attachments",
36
+ :action => "download",
37
+ :id => "11"
38
+ )
39
39
  end
40
40
 
41
41
  it "should have a route for legacy WebMate downloads" do
42
42
  {
43
43
  :get => "/uploads/files/0000/0028/Pressetext.pdf"
44
44
  }.should route_to(
45
- :controller => "alchemy/attachments",
46
- :action => "download",
47
- :id => "0028",
48
- :name => "Pressetext",
49
- :suffix => "pdf"
50
- )
45
+ :controller => "alchemy/attachments",
46
+ :action => "download",
47
+ :id => "0028",
48
+ :name => "Pressetext",
49
+ :suffix => "pdf"
50
+ )
51
51
  end
52
52
 
53
53
  end
@@ -60,11 +60,11 @@ describe "The Routing", :type => :routing do
60
60
  {
61
61
  :get => "/products/my-product"
62
62
  }.should route_to(
63
- :controller => "alchemy/pages",
64
- :action => "show",
65
- :level1 => "products",
66
- :urlname => "my-product"
67
- )
63
+ :controller => "alchemy/pages",
64
+ :action => "show",
65
+ :level1 => "products",
66
+ :urlname => "my-product"
67
+ )
68
68
  end
69
69
 
70
70
  context "and language" do
@@ -73,12 +73,12 @@ describe "The Routing", :type => :routing do
73
73
  {
74
74
  :get => "/de/products/my-product"
75
75
  }.should route_to(
76
- :controller => "alchemy/pages",
77
- :action => "show",
78
- :level1 => "products",
79
- :urlname => "my-product",
80
- :lang => "de"
81
- )
76
+ :controller => "alchemy/pages",
77
+ :action => "show",
78
+ :level1 => "products",
79
+ :urlname => "my-product",
80
+ :lang => "de"
81
+ )
82
82
  end
83
83
 
84
84
  end
@@ -91,12 +91,12 @@ describe "The Routing", :type => :routing do
91
91
  {
92
92
  :get => "/catalog/products/my-product"
93
93
  }.should route_to(
94
- :controller => "alchemy/pages",
95
- :action => "show",
96
- :level1 => "catalog",
97
- :level2 => "products",
98
- :urlname => "my-product"
99
- )
94
+ :controller => "alchemy/pages",
95
+ :action => "show",
96
+ :level1 => "catalog",
97
+ :level2 => "products",
98
+ :urlname => "my-product"
99
+ )
100
100
  end
101
101
 
102
102
  context "and language" do
@@ -105,13 +105,13 @@ describe "The Routing", :type => :routing do
105
105
  {
106
106
  :get => "/de/catalog/products/my-product"
107
107
  }.should route_to(
108
- :controller => "alchemy/pages",
109
- :action => "show",
110
- :level1 => "catalog",
111
- :level2 => "products",
112
- :urlname => "my-product",
113
- :lang => "de"
114
- )
108
+ :controller => "alchemy/pages",
109
+ :action => "show",
110
+ :level1 => "catalog",
111
+ :level2 => "products",
112
+ :urlname => "my-product",
113
+ :lang => "de"
114
+ )
115
115
  end
116
116
 
117
117
  end
@@ -124,13 +124,13 @@ describe "The Routing", :type => :routing do
124
124
  {
125
125
  :get => "/2011/12/08/my-post"
126
126
  }.should route_to(
127
- :controller => "alchemy/pages",
128
- :action => "show",
129
- :level1 => "2011",
130
- :level2 => "12",
131
- :level3 => "08",
132
- :urlname => "my-post"
133
- )
127
+ :controller => "alchemy/pages",
128
+ :action => "show",
129
+ :level1 => "2011",
130
+ :level2 => "12",
131
+ :level3 => "08",
132
+ :urlname => "my-post"
133
+ )
134
134
  end
135
135
 
136
136
  context "and language" do
@@ -139,14 +139,14 @@ describe "The Routing", :type => :routing do
139
139
  {
140
140
  :get => "/de/2011/12/08/my-post"
141
141
  }.should route_to(
142
- :controller => "alchemy/pages",
143
- :action => "show",
144
- :level1 => "2011",
145
- :level2 => "12",
146
- :level3 => "08",
147
- :urlname => "my-post",
148
- :lang => "de"
149
- )
142
+ :controller => "alchemy/pages",
143
+ :action => "show",
144
+ :level1 => "2011",
145
+ :level2 => "12",
146
+ :level3 => "08",
147
+ :urlname => "my-post",
148
+ :lang => "de"
149
+ )
150
150
  end
151
151
 
152
152
  end
@@ -161,97 +161,97 @@ describe "The Routing", :type => :routing do
161
161
  {
162
162
  :get => "/pictures/3/show/900x300/kitten.jpg"
163
163
  }.should route_to(
164
- :controller => "alchemy/pictures",
165
- :action => "show",
166
- :id => "3",
167
- :size => "900x300",
168
- :name => "kitten",
169
- :format => "jpg"
170
- )
164
+ :controller => "alchemy/pictures",
165
+ :action => "show",
166
+ :id => "3",
167
+ :size => "900x300",
168
+ :name => "kitten",
169
+ :format => "jpg"
170
+ )
171
171
  end
172
172
 
173
173
  it "should route to cropped show action" do
174
174
  {
175
175
  :get => "/pictures/3/show/900x300/crop/kitten.jpg"
176
176
  }.should route_to(
177
- :controller => "alchemy/pictures",
178
- :action => "show",
179
- :id => "3",
180
- :size => "900x300",
181
- :crop => "crop",
182
- :name => "kitten",
183
- :format => "jpg"
184
- )
177
+ :controller => "alchemy/pictures",
178
+ :action => "show",
179
+ :id => "3",
180
+ :size => "900x300",
181
+ :crop => "crop",
182
+ :name => "kitten",
183
+ :format => "jpg"
184
+ )
185
185
  end
186
186
 
187
187
  it "should route to cropped mask show action" do
188
188
  get(
189
189
  "/pictures/3/show/300x300/crop/200x50/100x100/kitten.jpg"
190
190
  ).should route_to(
191
- :controller => "alchemy/pictures",
192
- :action => "show",
193
- :id => "3",
194
- :size => "300x300",
195
- :crop => "crop",
196
- :crop_from => "200x50",
197
- :crop_size => "100x100",
198
- :name => "kitten",
199
- :format => "jpg"
200
- )
191
+ :controller => "alchemy/pictures",
192
+ :action => "show",
193
+ :id => "3",
194
+ :size => "300x300",
195
+ :crop => "crop",
196
+ :crop_from => "200x50",
197
+ :crop_size => "100x100",
198
+ :name => "kitten",
199
+ :format => "jpg"
200
+ )
201
201
  end
202
202
 
203
203
  it "should route to thumbnail action" do
204
204
  get(
205
205
  "/pictures/3/thumbnails/small/kitten.jpg"
206
206
  ).should route_to(
207
- :controller => "alchemy/pictures",
208
- :action => "thumbnail",
209
- :id => "3",
210
- :size => "small",
211
- :name => "kitten",
212
- :format => "jpg"
213
- )
207
+ :controller => "alchemy/pictures",
208
+ :action => "thumbnail",
209
+ :id => "3",
210
+ :size => "small",
211
+ :name => "kitten",
212
+ :format => "jpg"
213
+ )
214
214
  end
215
215
 
216
216
  it "should route to cropped thumbnail action" do
217
217
  get(
218
218
  "/pictures/3/thumbnails/small/crop/kitten.jpg"
219
219
  ).should route_to(
220
- :controller => "alchemy/pictures",
221
- :action => "thumbnail",
222
- :id => "3",
223
- :crop => "crop",
224
- :size => "small",
225
- :name => "kitten",
226
- :format => "jpg"
227
- )
220
+ :controller => "alchemy/pictures",
221
+ :action => "thumbnail",
222
+ :id => "3",
223
+ :crop => "crop",
224
+ :size => "small",
225
+ :name => "kitten",
226
+ :format => "jpg"
227
+ )
228
228
  end
229
229
 
230
230
  it "should route to cropped and masked thumbnail" do
231
231
  get(
232
232
  "/pictures/3/thumbnails/small/0x0/200x200/kitten.jpg"
233
233
  ).should route_to(
234
- :controller => "alchemy/pictures",
235
- :action => "thumbnail",
236
- :id => "3",
237
- :crop_from => "0x0",
238
- :crop_size => "200x200",
239
- :size => "small",
240
- :name => "kitten",
241
- :format => "jpg"
242
- )
234
+ :controller => "alchemy/pictures",
235
+ :action => "thumbnail",
236
+ :id => "3",
237
+ :crop_from => "0x0",
238
+ :crop_size => "200x200",
239
+ :size => "small",
240
+ :name => "kitten",
241
+ :format => "jpg"
242
+ )
243
243
  end
244
244
 
245
245
  it "should route to zoomed picture" do
246
246
  get(
247
247
  "/pictures/3/zoom/kitten.jpg"
248
248
  ).should route_to(
249
- :controller => "alchemy/pictures",
250
- :action => "zoom",
251
- :id => "3",
252
- :name => "kitten",
253
- :format => "jpg"
254
- )
249
+ :controller => "alchemy/pictures",
250
+ :action => "zoom",
251
+ :id => "3",
252
+ :name => "kitten",
253
+ :format => "jpg"
254
+ )
255
255
  end
256
256
 
257
257
  end