alchemy_cms 3.1.0.beta1 → 3.1.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -2
  4. data/README.md +9 -1
  5. data/alchemy_cms.gemspec +24 -13
  6. data/app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee +1 -1
  7. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +1 -1
  8. data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +9 -0
  9. data/app/assets/javascripts/alchemy/alchemy.js +4 -0
  10. data/app/assets/javascripts/alchemy/alchemy.preview.js.coffee +3 -2
  11. data/app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee +2 -0
  12. data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +43 -1
  13. data/app/assets/stylesheets/alchemy/_mixins.scss +1 -2
  14. data/app/assets/stylesheets/alchemy/archive.scss +1 -1
  15. data/app/assets/stylesheets/alchemy/base.scss +18 -1
  16. data/app/assets/stylesheets/alchemy/buttons.scss +5 -0
  17. data/app/assets/stylesheets/alchemy/dialogs.scss +0 -1
  18. data/app/assets/stylesheets/alchemy/frame.scss +17 -10
  19. data/app/assets/stylesheets/alchemy/menubar.css.scss +3 -0
  20. data/app/assets/stylesheets/alchemy/tables.scss +30 -8
  21. data/app/controllers/alchemy/admin/attachments_controller.rb +9 -1
  22. data/app/controllers/alchemy/admin/essence_files_controller.rb +3 -4
  23. data/app/controllers/alchemy/pages_controller.rb +20 -2
  24. data/app/models/alchemy/content.rb +2 -1
  25. data/app/models/alchemy/element.rb +1 -1
  26. data/app/views/alchemy/admin/attachments/_files_list.html.erb +22 -18
  27. data/app/views/alchemy/admin/attachments/index.html.erb +1 -1
  28. data/app/views/alchemy/admin/languages/_table.html.erb +29 -25
  29. data/app/views/alchemy/admin/languages/index.html.erb +1 -1
  30. data/app/views/alchemy/admin/pictures/info.html.erb +3 -2
  31. data/app/views/alchemy/admin/resources/_table.html.erb +17 -13
  32. data/app/views/alchemy/admin/resources/index.html.erb +1 -1
  33. data/app/views/alchemy/admin/sites/index.html.erb +1 -1
  34. data/app/views/alchemy/admin/tags/edit.html.erb +1 -1
  35. data/app/views/alchemy/admin/tags/index.html.erb +14 -10
  36. data/app/views/alchemy/essences/_essence_file_editor.html.erb +20 -24
  37. data/app/views/alchemy/messages/contact_form_mail.es.text.erb +12 -0
  38. data/app/views/layouts/alchemy/admin.html.erb +2 -0
  39. data/bin/alchemy +58 -26
  40. data/config/locales/alchemy.en.yml +2 -1
  41. data/config/locales/alchemy.es.yml +958 -0
  42. data/config/locales/alchemy.fr.yml +1 -1
  43. data/config/locales/alchemy.ru.yml +837 -0
  44. data/config/locales/simple_form.es.yml +6 -0
  45. data/config/locales/simple_form.ru.yml +25 -0
  46. data/lib/alchemy/engine.rb +11 -0
  47. data/lib/alchemy/essence.rb +12 -1
  48. data/lib/alchemy/resources_helper.rb +3 -1
  49. data/lib/alchemy/test_support/essence_shared_examples.rb +37 -0
  50. data/lib/alchemy/test_support/factories.rb +2 -0
  51. data/lib/alchemy/version.rb +1 -1
  52. data/lib/rails/generators/alchemy/module/templates/module_config.rb.tt +4 -2
  53. data/lib/rails/generators/alchemy/scaffold/files/alchemy.es.yml +31 -0
  54. data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +1 -0
  55. data/lib/rails/templates/alchemy.rb +2 -0
  56. data/lib/tasks/alchemy/install.rake +11 -7
  57. data/spec/controllers/admin/attachments_controller_spec.rb +21 -0
  58. data/spec/controllers/admin/essence_files_controller_spec.rb +13 -12
  59. data/spec/controllers/alchemy/api/contents_controller_spec.rb +4 -4
  60. data/spec/controllers/attachments_controller_spec.rb +18 -0
  61. data/spec/controllers/pages_controller_spec.rb +20 -3
  62. data/spec/dummy/db/migrate/20121026104128_create_events.rb +2 -0
  63. data/spec/dummy/db/schema.rb +5 -3
  64. data/spec/features/admin/resources_integration_spec.rb +5 -0
  65. data/spec/features/page_feature_spec.rb +20 -0
  66. data/spec/models/content_spec.rb +24 -2
  67. data/spec/models/element_spec.rb +11 -0
  68. data/spec/views/essences/essence_file_editor_spec.rb +61 -0
  69. data/vendor/assets/javascripts/jquery_plugins/jquery.floatThead.min.js +3 -0
  70. data/vendor/assets/javascripts/tinymce/langs/es.js +197 -0
  71. data/vendor/assets/javascripts/tinymce/langs/ru.js +197 -0
  72. metadata +53 -38
@@ -0,0 +1,6 @@
1
+ es:
2
+ simple_form:
3
+ labels:
4
+ user:
5
+ login: Usuario
6
+ password: Contraseña
@@ -0,0 +1,25 @@
1
+ ru:
2
+ simple_form:
3
+ "yes": 'Да'
4
+ "no": 'Нет'
5
+ required:
6
+ text: 'обязательные поля'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Пожалуйста, исправьте эти ошибки:"
13
+ # Labels and hints examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
@@ -83,6 +83,17 @@ module Alchemy
83
83
  NonStupidDigestAssets.whitelist += [/^tinymce\//]
84
84
  end
85
85
 
86
+ # We need to require each essence class in development mode,
87
+ # so it can register itself as essence relation on Page and Element models
88
+ # @see lib/alchemy/essence.rb:71
89
+ initializer 'alchemy.load_essence_classes' do |app|
90
+ unless Rails.application.config.cache_classes
91
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/models/alchemy/essence_*.rb')).each do |essence|
92
+ require essence
93
+ end
94
+ end
95
+ end
96
+
86
97
  config.after_initialize do
87
98
  require_relative './userstamp'
88
99
  # In order to have Alchemy's helpers and basic controller methods
@@ -24,6 +24,8 @@ module Alchemy #:nodoc:
24
24
  # Specify the column for the preview_text method.
25
25
  #
26
26
  def acts_as_essence(options={})
27
+ register_as_essence_association!
28
+
27
29
  configuration = {
28
30
  ingredient_column: 'body'
29
31
  }.update(options)
@@ -41,7 +43,9 @@ module Alchemy #:nodoc:
41
43
  scope :available, -> { joins(:element).merge(Element.available) }
42
44
  scope :from_element, ->(name) { joins(:element).where(alchemy_elements: { name: name }) }
43
45
 
44
- delegate :public?, to: :element
46
+ delegate :restricted?, to: :page, allow_nil: true
47
+ delegate :trashed?, to: :element, allow_nil: true
48
+ delegate :public?, to: :element, allow_nil: true
45
49
 
46
50
  after_update :touch_content
47
51
 
@@ -63,6 +67,13 @@ module Alchemy #:nodoc:
63
67
  EOV
64
68
  end
65
69
 
70
+ # Register the current class as has_many association on +Alchemy::Page+ and +Alchemy::Element+ models
71
+ def register_as_essence_association!
72
+ klass_name = self.model_name.to_s
73
+ arguments = [:has_many, klass_name.demodulize.tableize.to_sym, through: :contents,
74
+ source: :essence, source_type: klass_name]
75
+ %w(Page Element).each { |k| "Alchemy::#{k}".constantize.send(*arguments) }
76
+ end
66
77
  end
67
78
 
68
79
  module InstanceMethods
@@ -95,6 +95,8 @@ module Alchemy
95
95
  type: 'date',
96
96
  value: l(resource_instance_variable.send(attribute[:name]) || Time.now, format: :datepicker)
97
97
  }
98
+ when 'time'
99
+ options.merge(as: 'time')
98
100
  when 'text'
99
101
  options.merge(as: 'text', input_html: {rows: 4})
100
102
  else
@@ -104,7 +106,7 @@ module Alchemy
104
106
 
105
107
  # Renders the human model name with a count as h1 header
106
108
  def resources_header
107
- content_tag :h1, "#{resources_instance_variable.total_count} #{resource_model.model_name.human(:count => resources_instance_variable.total_count)}"
109
+ content_tag :h1, "#{resources_instance_variable.total_count} #{resource_model.model_name.human(count: resources_instance_variable.total_count)}", class: 'resources-header'
108
110
  end
109
111
 
110
112
  # Returns true if the resource contains any relations
@@ -153,4 +153,41 @@ shared_examples_for "an essence" do
153
153
  end
154
154
  end
155
155
  end
156
+
157
+ context 'delegations' do
158
+ let(:page) { create(:restricted_page) }
159
+ let(:element) { create(:element, name: 'headline', create_contents_after_create: true, page: page) }
160
+ let(:content) { element.contents.find_by(essence_type: 'Alchemy::EssenceText') }
161
+ let(:essence) { content.essence }
162
+
163
+ it "delegates restricted? to page" do
164
+ expect(page.restricted?).to be(true)
165
+ expect(essence.restricted?).to be(true)
166
+ end
167
+
168
+ it "delegates trashed? to element" do
169
+ element.update!(position: nil)
170
+ expect(element.trashed?).to be true
171
+ expect(essence.trashed?).to be true
172
+ end
173
+
174
+ it "delegates public? to element" do
175
+ element.update!(public: false)
176
+ expect(element.public?).to be false
177
+ expect(essence.public?).to be false
178
+ end
179
+ end
180
+
181
+ describe 'essence relations' do
182
+ let(:page) { create(:restricted_page) }
183
+ let(:element) { create(:element) }
184
+
185
+ it "registers itself on page as essence relation" do
186
+ expect(page.respond_to?(essence.class.model_name.route_key)).to be(true)
187
+ end
188
+
189
+ it "registers itself on element as essence relation" do
190
+ expect(element.respond_to?(essence.class.model_name.route_key)).to be(true)
191
+ end
192
+ end
156
193
  end
@@ -134,6 +134,8 @@ FactoryGirl.define do
134
134
  hidden_name 'not shown'
135
135
  starts_at DateTime.new(2012, 03, 02, 8, 15)
136
136
  ends_at DateTime.new(2012, 03, 02, 19, 30)
137
+ lunch_starts_at DateTime.new(2012, 03, 02, 12, 15)
138
+ lunch_ends_at DateTime.new(2012, 03, 02, 13, 45)
137
139
  description "something\nfancy"
138
140
  published false
139
141
  entrance_fee 12.3
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
- VERSION = "3.1.0.beta1"
2
+ VERSION = "3.1.0.beta2"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -5,11 +5,13 @@ Alchemy::Modules.register_module({
5
5
  name: 'modules.<%= @module_name %>',
6
6
  controller: '/admin/<%= @module_name %>',
7
7
  action: 'index',
8
- image: '/assets/<%= @module_name %>.png',
8
+ image: 'alchemy/<%= @module_name %>_module.png',
9
9
  sub_navigation: [{
10
10
  name: 'modules.<%= @module_name %>',
11
11
  controller: '/admin/<%= @module_name %>',
12
12
  action: 'index'
13
13
  }]
14
14
  }
15
- })
15
+ })
16
+
17
+ Alchemy.register_ability(<%= @class_name %>Ability)
@@ -0,0 +1,31 @@
1
+ es:
2
+ alchemy:
3
+
4
+ # Translations for page layout names
5
+ page_layout_names:
6
+ index: Inicio
7
+
8
+ # Translations for element names
9
+ element_names:
10
+ article: Artículo
11
+
12
+ # Translations for content names
13
+ content_names:
14
+ headline: Titular
15
+ text: Texto
16
+ picture: Imagen
17
+
18
+ # Default texts for new contents created
19
+ default_content_texts:
20
+ article_headline: "Bienvenido a tu primera página de Alchemy CMS"
21
+ article_text: '<p><strong>Como empezar.</strong></p><p>Lo primero de todo deberías leer sobre Alchemy y su arquitectura en las <a class="external" href="http://guides.alchemy-cms.com/edge/alchemy_approach.html" target="_blank" data-link-target="blank">guías</a>.</p><p>Las cosas más importantes que debes saber sobre Alchemy son elementos (<i>elements</i>) y disposiciones de página (<i>page layouts</i>).</p><p><span style="text-decoration: underline;"><strong>Elementos:</strong></span></p><p>Con Alchemy puedes dividir las páginas en partes de contenido, elementos. Estos elementos se pueden definir mediante varios tipos de contenido básicos: esencias (<i>essences</i>). Las esencias básicas son:</p><ul><li>EssenceText - <em>Un única línea de texto</em></li><li>EssenceRichtext - <em>Un bloque de texto formateado mediante TinyMCE</em></li><li>EssencePicture - <em>Una referencia a una imagen</em></li><li>EssenceHtml - <em>Código HTML empotrado</em></li><li>EssenceSelect - <em>Una selección de valores</em></li><li>EssenceBoolean - <em>Una casilla de verificación</em></li></ul><p>Los elementos se definen en el fichero YAML <strong>config/alchemy/elements.yml</strong></p><p><a class="external" href="http://guides.alchemy-cms.com/edge/elements.html" target="_blank" data-link-target="blank">Lee más sobre elementos y cómo definirlos en las guías.</a></p><p><span style="text-decoration: underline;"><strong>Tipos de página:</strong></span></p><p>Puedes definir varios tipos de páginas, llamados disposiciones de páginas (<i>page layouts</i>). Puedes asignar elementos a las disposiciones de páginas y controlar cómo se comportan los elementos y una página con una disposición concreta.</p><p>Las disposiciones de páginas se definen en el fichero YAML <strong>config/alchemy/page_layouts.yml</strong></p><p><a class="external" href="http://guides.alchemy-cms.com/edge/page_layouts.html" target="_blank" data-link-target="blank">Lee más sobre definir disposiciones de páginas en las guías.</a></p>'
22
+
23
+ # Hint texts for elements
24
+ element_hints:
25
+ article: "Este es el texto de ayuda del elemento artículo. Puedes cambiar este texto en `config/locales/alchemy.en.yml`. Siéntete libre de cambiarlo a tu gusto, es tuyo."
26
+
27
+ # Hint texts for contents
28
+ content_hints:
29
+ headline: "Esta es una sencilla linea de texto sin formato"
30
+ picture: "Las imágenes se almacenan en la librería. Puedes asignar una imagen varias veces en tu sitio. Alchemy tiene una herramienta de recorte de imagen integrada."
31
+ text: "Este es un bloque de texto enriquecido mediante el editor TinyMCE. Puedes cambiar la configuración del editor. Ver http://guides.alchemy-cms.com/edge/customize_tinymce.html"
@@ -32,6 +32,7 @@ module Alchemy
32
32
  template "page_layouts.yml.tt", "#{Rails.root}/config/alchemy/page_layouts.yml"
33
33
  copy_file "#{current_path}/files/alchemy.en.yml", "#{Rails.root}/config/locales/alchemy.en.yml"
34
34
  copy_file "#{current_path}/files/alchemy.de.yml", "#{Rails.root}/config/locales/alchemy.de.yml"
35
+ copy_file "#{current_path}/files/alchemy.es.yml", "#{Rails.root}/config/locales/alchemy.es.yml"
35
36
  copy_file "#{current_path}/files/application.html.erb", "#{Rails.root}/app/views/layouts/application.html.erb"
36
37
  copy_file "#{current_path}/files/_standard.html.erb", "#{Rails.root}/app/views/alchemy/page_layouts/_standard.html.erb"
37
38
  copy_file "#{current_path}/files/_article_view.html.erb", "#{Rails.root}/app/views/alchemy/elements/_article_view.html.erb"
@@ -4,3 +4,5 @@ require File.expand_path('../../../alchemy/version', __FILE__)
4
4
  gem 'alchemy_cms', github: 'magiclabs/alchemy_cms', branch: 'master'
5
5
  gem 'alchemy-devise', github: 'magiclabs/alchemy-devise', branch: 'master'
6
6
  gem 'capistrano', '~> 2.15.5', group: 'development'
7
+
8
+ run 'bundle install'
@@ -28,19 +28,23 @@ namespace :alchemy do
28
28
 
29
29
  desc "Installs Alchemy CMS into your app."
30
30
  task :install do
31
- puts "\nAlchemy Installer"
32
- puts "-----------------"
31
+ unless ENV['from_binary']
32
+ puts "\nAlchemy Installer"
33
+ puts "-----------------"
34
+ end
33
35
  Rake::Task["alchemy:mount"].invoke
34
- system('rails g alchemy:scaffold') || exit!(1)
36
+ system("rails g alchemy:scaffold#{ ENV['from_binary'] ? ' --force' : '' }") || exit!(1)
35
37
  Alchemy::InstallTask.new.set_primary_language
36
38
  Rake::Task["db:create"].invoke
37
39
  Rake::Task["alchemy:install:migrations"].invoke
38
40
  Rake::Task["db:migrate"].invoke
39
41
  Rake::Task["alchemy:db:seed"].invoke
40
- puts "\nAlchemy successfully installed."
41
- puts "\nNow start the server with:"
42
- puts "\n$ bin/rails server"
43
- puts "\nand point your browser to http://localhost:3000/admin and follow the onscreen instructions to finalize the installation."
42
+ unless ENV['from_binary']
43
+ puts "\nAlchemy successfully installed."
44
+ puts "\nNow start the server with:"
45
+ puts "\n$ bin/rails server"
46
+ puts "\nand point your browser to http://localhost:3000/admin and follow the onscreen instructions to finalize the installation."
47
+ end
44
48
  end
45
49
 
46
50
  desc "Mounts Alchemy into your routes."
@@ -40,6 +40,27 @@ module Alchemy
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ describe 'only and expect options' do
45
+ let!(:png) { create(:attachment) }
46
+ let!(:jpg) { create(:attachment, file: File.new(File.expand_path('../../../../spec/fixtures/image3.jpeg', __FILE__))) }
47
+
48
+ context 'with params[:only]' do
49
+ it 'only loads attachments with matching content type' do
50
+ get :index, only: 'jpeg'
51
+ expect(assigns(:attachments).to_a).to eq([jpg])
52
+ expect(assigns(:attachments).to_a).to_not eq([png])
53
+ end
54
+ end
55
+
56
+ context 'with params[:except]' do
57
+ it 'does not load attachments with matching content type' do
58
+ get :index, except: 'jpeg'
59
+ expect(assigns(:attachments).to_a).to eq([png])
60
+ expect(assigns(:attachments).to_a).to_not eq([jpg])
61
+ end
62
+ end
63
+ end
43
64
  end
44
65
 
45
66
  describe '#show' do
@@ -6,23 +6,25 @@ module Alchemy
6
6
  sign_in(admin_user)
7
7
  end
8
8
 
9
- let(:content) { mock_model('Content', essence: essence_file) }
10
- let(:essence_file) { mock_model('EssenceFile', :attachment= => nil) }
9
+ let(:essence_file) { mock_model('EssenceFile', :attachment= => nil, content: content) }
10
+ let(:content) { mock_model('Content') }
11
11
  let(:attachment) { mock_model('Attachment') }
12
12
 
13
13
  describe '#edit' do
14
14
  before do
15
- expect(Content).to receive(:find).and_return(content)
15
+ expect(EssenceFile).to receive(:find)
16
+ .with(essence_file.id.to_s)
17
+ .and_return(essence_file)
16
18
  end
17
19
 
18
- it "should assign @content with the Content found by id" do
19
- get :edit, content_id: content.id
20
- expect(assigns(:content)).to eq(content)
20
+ it "assigns @essence_file with the EssenceFile found by id" do
21
+ get :edit, id: essence_file.id
22
+ expect(assigns(:essence_file)).to eq(essence_file)
21
23
  end
22
24
 
23
- it "should assign @essence_file with content's essence" do
24
- get :edit, content_id: content.id
25
- expect(assigns(:essence_file)).to eq(content.essence)
25
+ it "should assign @content with essence_file's content" do
26
+ get :edit, id: essence_file.id
27
+ expect(assigns(:content)).to eq(content)
26
28
  end
27
29
  end
28
30
 
@@ -32,7 +34,7 @@ module Alchemy
32
34
  end
33
35
 
34
36
  it "should update the attributes of essence_file" do
35
- expect(essence_file).to receive(:update_attributes).and_return(true)
37
+ expect(essence_file).to receive(:update).and_return(true)
36
38
  xhr :put, :update, id: essence_file.id
37
39
  end
38
40
  end
@@ -41,6 +43,7 @@ module Alchemy
41
43
  before do
42
44
  expect(Content).to receive(:find_by).and_return(content)
43
45
  expect(Attachment).to receive(:find_by).and_return(attachment)
46
+ allow(content).to receive(:essence).and_return(essence_file)
44
47
  end
45
48
 
46
49
  it "should assign @attachment with the Attachment found by attachment_id" do
@@ -52,8 +55,6 @@ module Alchemy
52
55
  expect(content.essence).to receive(:attachment=).with(attachment)
53
56
  xhr :put, :assign, content_id: content.id, attachment_id: attachment.id
54
57
  end
55
-
56
58
  end
57
-
58
59
  end
59
60
  end
@@ -30,9 +30,9 @@ module Alchemy
30
30
 
31
31
  describe '#show' do
32
32
  context 'with no other params given' do
33
- let(:page) { build_stubbed(:page) }
34
- let(:element) { build_stubbed(:element, page: page, position: 1) }
35
- let(:content) { build_stubbed(:content, element: element) }
33
+ let(:page) { create(:page) }
34
+ let(:element) { create(:element, page: page) }
35
+ let(:content) { create(:content, element: element) }
36
36
 
37
37
  before do
38
38
  expect(Content).to receive(:find).and_return(content)
@@ -45,7 +45,7 @@ module Alchemy
45
45
  end
46
46
 
47
47
  context 'requesting an restricted content' do
48
- let(:page) { build_stubbed(:page, restricted: true) }
48
+ let(:page) { create(:page, restricted: true) }
49
49
 
50
50
  it "responds with 403" do
51
51
  get :show, id: content.id, format: :json
@@ -8,6 +8,24 @@ module Alchemy
8
8
  expect { get :download, id: 0 }.to raise_error(ActiveRecord::RecordNotFound)
9
9
  end
10
10
 
11
+ context 'with public attachment' do
12
+ before do
13
+ allow(Attachment).to receive(:find).and_return(attachment)
14
+ end
15
+
16
+ it "sends download as attachment." do
17
+ get :download, :id => attachment.id
18
+ expect(response.status).to eq(200)
19
+ expect(response.headers['Content-Disposition']).to match(/attachment/)
20
+ end
21
+
22
+ it "sends download inline." do
23
+ get :show, :id => attachment.id
24
+ expect(response.status).to eq(200)
25
+ expect(response.headers['Content-Disposition']).to match(/inline/)
26
+ end
27
+ end
28
+
11
29
  context 'with restricted attachment' do
12
30
  before do
13
31
  allow(attachment).to receive(:restricted?).and_return(true)
@@ -143,11 +143,20 @@ module Alchemy
143
143
  let!(:legacy_url) { LegacyPageUrl.create(urlname: 'legacy-url', page: page) }
144
144
  let(:legacy_url2) { LegacyPageUrl.create(urlname: 'legacy-url', page: second_page) }
145
145
  let(:legacy_url3) { LegacyPageUrl.create(urlname: 'index.php?id=2', page: second_page) }
146
+ let(:legacy_url4) { LegacyPageUrl.create(urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', page: second_page) }
147
+ let(:legacy_url5) { LegacyPageUrl.create(urlname: 'nested/legacy/url', page: second_page) }
146
148
 
147
- it "should redirect permanently to page that belongs to legacy page url." do
148
- get :show, urlname: legacy_url.urlname
149
+ it "should redirect permanently to page that belongs to legacy page url even if url has an unknown format & get parameters" do
150
+ expect(request).to receive(:fullpath).at_least(:once).and_return(legacy_url4.urlname)
151
+ get :show, urlname: "index.php"
149
152
  expect(response.status).to eq(301)
150
- expect(response).to redirect_to("/#{page.urlname}")
153
+ expect(response).to redirect_to("/#{second_page.urlname}")
154
+ end
155
+
156
+ it "should not pass query string for legacy routes" do
157
+ expect(request).to receive(:fullpath).at_least(:once).and_return(legacy_url3.urlname)
158
+ get :show, urlname: "index.php"
159
+ expect(URI.parse(response["Location"]).query).to be_nil
151
160
  end
152
161
 
153
162
  it "should only redirect to legacy url if no page was found for urlname" do
@@ -157,14 +166,22 @@ module Alchemy
157
166
  end
158
167
 
159
168
  it "should redirect to last page that has that legacy url" do
169
+ expect(request).to receive(:fullpath).at_least(:once).and_return(legacy_url2.urlname)
160
170
  get :show, urlname: legacy_url2.urlname
161
171
  expect(response).to redirect_to("/#{second_page.urlname}")
162
172
  end
163
173
 
164
174
  it "should redirect even if the url has get parameters" do
175
+ expect(request).to receive(:fullpath).at_least(:once).and_return(legacy_url3.urlname)
165
176
  get :show, urlname: legacy_url3.urlname
166
177
  expect(response).to redirect_to("/#{second_page.urlname}")
167
178
  end
179
+
180
+ it "should redirect even if the url has nested urlname" do
181
+ expect(request).to receive(:fullpath).at_least(:once).and_return(legacy_url5.urlname)
182
+ get :show, urlname: legacy_url5.urlname
183
+ expect(response).to redirect_to("/#{second_page.urlname}")
184
+ end
168
185
  end
169
186
  end
170
187
 
@@ -6,6 +6,8 @@ class CreateEvents < ActiveRecord::Migration
6
6
  t.string "hidden_name"
7
7
  t.datetime "starts_at"
8
8
  t.datetime "ends_at"
9
+ t.time "lunch_starts_at"
10
+ t.time "lunch_ends_at"
9
11
  t.text "description"
10
12
  t.decimal "entrance_fee", :precision => 6, :scale => 2
11
13
  t.boolean "published"