pulitzer 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/pulitzer/versions_controller.rb +8 -2
  3. data/app/interactions/pulitzer/update_version_status.rb +23 -16
  4. data/lib/pulitzer/version.rb +1 -1
  5. data/spec/controllers/pulitzer/versions_controller_spec.rb +39 -0
  6. data/spec/dummy/db/development.sqlite3 +0 -0
  7. data/spec/dummy/db/migrate/20150618224344_create_pulitzer_post_types.rb +9 -0
  8. data/spec/dummy/db/migrate/20150618225402_create_pulitzer_content_element_types.rb +9 -0
  9. data/spec/dummy/db/migrate/20150619204615_create_pulitzer_posts.rb +11 -0
  10. data/spec/dummy/db/migrate/20150619204708_create_pulitzer_content_elements.rb +15 -0
  11. data/spec/dummy/db/migrate/20150619213436_create_pulitzer_tags.rb +9 -0
  12. data/spec/dummy/db/migrate/20150619213457_create_pulitzer_post_tags.rb +11 -0
  13. data/spec/dummy/db/migrate/20150619215914_create_pulitzer_post_type_content_element_types.rb +13 -0
  14. data/spec/dummy/db/migrate/20150629195832_add_plural_and_template_to_pulitzer_post_types.rb +6 -0
  15. data/spec/dummy/db/migrate/20150702150819_add_pulitzer_content_element_types.rb +13 -0
  16. data/spec/dummy/db/migrate/20150724150230_add_slug_to_pulitzer_posts.rb +6 -0
  17. data/spec/dummy/db/migrate/20150902212741_change_label_type_from_pulitzer_post_tags.rb +5 -0
  18. data/spec/dummy/db/migrate/20151026180630_add_text_editor_to_pulitzer_post_type_content_element_types.rb +10 -0
  19. data/spec/dummy/db/migrate/20151029194354_create_pulitzer_versions.rb +10 -0
  20. data/spec/dummy/db/migrate/20151029220558_change_post_elements_to_versions.rb +20 -0
  21. data/spec/dummy/db/migrate/20151113183344_add_post_type_content_element_attributes_to_content_elements.rb +21 -0
  22. data/spec/dummy/db/migrate/20151116162508_change_template_to_pulitzer_post_types.rb +11 -0
  23. data/spec/dummy/db/migrate/20151118031237_add_kind_to_pulitzer_content_elements.rb +5 -0
  24. data/spec/dummy/db/migrate/20160122204201_add_errors_to_version.rb +5 -0
  25. data/spec/dummy/db/migrate/20160511192041_create_partials.rb +9 -0
  26. data/spec/dummy/db/migrate/20160511201527_add_parent_id_to_pulitzer_tag.rb +7 -0
  27. data/spec/dummy/db/migrate/20160512214545_add_partial_to_content_element.rb +5 -0
  28. data/spec/dummy/db/migrate/20160513153209_create_free_form_section_type.rb +8 -0
  29. data/spec/dummy/db/migrate/20160513153214_create_free_form_section.rb +9 -0
  30. data/spec/dummy/db/migrate/20160516150237_fix_post_type_kinds.rb +7 -0
  31. data/spec/dummy/db/migrate/20160517181706_create_layouts.rb +8 -0
  32. data/spec/dummy/db/migrate/20160517182500_add_layout_to_partial.rb +5 -0
  33. data/spec/dummy/db/migrate/20160519181030_add_label_to_partial.rb +5 -0
  34. data/spec/dummy/db/migrate/20160609214139_remove_title_from_content_elements.rb +5 -0
  35. data/spec/dummy/db/migrate/20160927160910_add_required_to_pulitzer_post_type_content_element_type.rb +5 -0
  36. data/spec/dummy/db/test.sqlite3 +0 -0
  37. data/spec/dummy/log/development.log +103 -0
  38. data/spec/dummy/log/test.log +7132 -0
  39. data/spec/dummy/public/uploads/tmp/1481137841-25126-0001-1732/cms_sam_and_snow.jpg +0 -0
  40. data/spec/dummy/public/uploads/tmp/1481137841-25126-0001-1732/sam_and_snow.jpg +0 -0
  41. data/spec/dummy/public/uploads/tmp/1481137841-25126-0001-1732/thumb_sam_and_snow.jpg +0 -0
  42. data/spec/dummy/public/uploads/tmp/1481139929-27725-0001-9237/cms_sam_and_snow.jpg +0 -0
  43. data/spec/dummy/public/uploads/tmp/1481139929-27725-0001-9237/sam_and_snow.jpg +0 -0
  44. data/spec/dummy/public/uploads/tmp/1481139929-27725-0001-9237/thumb_sam_and_snow.jpg +0 -0
  45. data/spec/spec_helper.rb +2 -0
  46. metadata +94 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 439b5ac81e2a0888a034c86a10e484889940a97f
4
- data.tar.gz: a27c70139d2212a1d71e9123b580ae5596af976f
3
+ metadata.gz: 0f63ebe9b07ab0474e255a16a33374d0eb001506
4
+ data.tar.gz: 3f9f50630a0bceae4deb42bee8b7069f282a59c6
5
5
  SHA512:
6
- metadata.gz: f22be4df663f12dec01aa6322a6caaef3d0eb1a93c87404dff52725ee7fac5e806444af2d150e857473af5fd7f6a6e0461a93adf5671e46ae2354b1ab9e9e31e
7
- data.tar.gz: e3c05afd18b57d204f6549c666f57f5c6007a8ba14bef5332731d768910a5d760120e8fd9964e84989f49a3e487777b37ee82ffc92bf6faab5733bae21d87dd7
6
+ metadata.gz: 9d6560fc2250800a2921293211d5244da76769920d975cd66804882083f080668604f6ca99b693020a1fbebb5b6eeb6b38927ba27cfb9df098cc1a2111541771
7
+ data.tar.gz: bd0215be4171c56bd682a95e43481b7ef67c160ba12bea05d7b4d2f3afd26a32c0b9d7eca222f49a6f7589f3b79044e78980d6bacf0d20ff4c426ac539176f95
@@ -14,12 +14,18 @@ class Pulitzer::VersionsController < Pulitzer::ApplicationController
14
14
  if status_updater.errors.any?
15
15
  processing_version = @version
16
16
  flash_message = processing_version.errors.first
17
+ status = :conflict
17
18
  else
18
19
  processing_version = status_updater.call
19
- flash_message = "The new version of #{@post.title} has been activated."
20
+ if processing_version.errors.empty?
21
+ status = :ok
22
+ flash_message = "The new version of #{@post.title} has been activated."
23
+ else
24
+ status = :conflict
25
+ end
20
26
  end
21
27
  render json: {html: render_to_string(partial: '/pulitzer/versions/edit', locals: {version: processing_version}),
22
- flash_message: flash_message}
28
+ flash_message: flash_message}, status: status
23
29
  end
24
30
 
25
31
  private
@@ -23,16 +23,17 @@ class Pulitzer::UpdateVersionStatus
23
23
  def make_version_active
24
24
  @new_active_version = @transitional_version
25
25
  @old_active_version = @new_active_version.post.active_version
26
- begin
27
- @new_active_version.update!(status: :active)
28
- rescue ActiveRecord::RecordInvalid => invalid
29
- Rails.logger.error(invalid.record.errors.messages.to_s)
26
+ @new_active_version.update(status: :active)
27
+ if @new_active_version.errors.any?
28
+ @new_active_version.update(status: :processing_failed, cloning_errors: @new_active_version.errors.full_messages)
29
+ @processing_version = @new_active_version
30
+ else
31
+ @new_active_version.tags.each &:touch
32
+ @old_active_version.update(status: :archived) if @old_active_version
33
+ @processing_version = @post.create_processing_version
34
+ Pulitzer::CloneVersionJob.perform_later(@new_active_version)
35
+ instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
30
36
  end
31
- @new_active_version.tags.each &:touch
32
- @old_active_version.update(status: :archived) if @old_active_version
33
- @processing_version = @post.create_processing_version
34
- Pulitzer::CloneVersionJob.perform_later(@new_active_version)
35
- instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
36
37
  @post.reload
37
38
  @processing_version.reload
38
39
  end
@@ -40,14 +41,20 @@ class Pulitzer::UpdateVersionStatus
40
41
  def make_version_abandoned
41
42
  @active_version = @transitional_version.post.active_version
42
43
  @transitional_version.update(status: :abandoned)
43
- if @active_version == @transitional_version
44
- @transitional_version.post.preview_version
45
- instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
46
- else
47
- @processing_version = @post.create_processing_version
48
- Pulitzer::CloneVersionJob.perform_later(@active_version)
49
- @processing_version
44
+ @transitional_version.tags.each &:touch
45
+ if @active_version.is_a? Pulitzer::Version
46
+ if @active_version == @transitional_version
47
+ @processing_version = @transitional_version.post.preview_version
48
+ instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
49
+ else
50
+ @processing_version = @post.create_processing_version
51
+ Pulitzer::CloneVersionJob.perform_later(@active_version)
52
+ @processing_version
53
+ end
54
+ else # There is no active version, we never published this one
55
+ @processing_version = @transitional_version
50
56
  end
57
+ @transitional_version
51
58
  end
52
59
 
53
60
  end
@@ -1,3 +1,3 @@
1
1
  module Pulitzer
2
- VERSION = '0.5.4'
2
+ VERSION = '0.5.5'
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'rails_helper'
2
+
3
+ describe Pulitzer::VersionsController do
4
+ routes { Pulitzer::Engine.routes }
5
+ render_views
6
+
7
+ let(:version) {create(:version, :with_content_elements)}
8
+
9
+ describe "updating versions" do
10
+ it "abandons a post that was never published" do
11
+ patch :update, id: version.id, status: 'abandoned'
12
+ expect(response.status).to eq 200
13
+ expect(version.reload.status).to eq 'abandoned'
14
+ end
15
+
16
+ it "abandons a post that was published" do
17
+ Pulitzer::UpdateVersionStatus.new(version, 'active').call
18
+ expect(version.status).to eq 'active'
19
+ expect(version.post.active_version).not_to be_nil
20
+ patch :update, id: version.id, status: 'abandoned'
21
+ expect(response.status).to eq 200
22
+ expect(version.reload.status).to eq 'abandoned'
23
+ expect(version.post.active_version).to be_nil
24
+ end
25
+
26
+ it "abandons changes" do
27
+ Pulitzer::UpdateVersionStatus.new(version, 'active').call
28
+ active_version = version
29
+ expect(active_version.status).to eq 'active'
30
+ old_preview = version.post.preview_version
31
+ patch :update, id: old_preview.id, status: 'abandoned'
32
+ expect(response.status).to eq 200
33
+ expect(active_version.reload.status).to eq 'active'
34
+ expect(old_preview.reload.status).to eq 'abandoned'
35
+ expect(active_version.post.preview_version.status).to eq 'preview'
36
+ expect(version.post.preview_version.id).not_to eq old_preview.id
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePulitzerPostTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_post_types do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePulitzerContentElementTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_content_element_types do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePulitzerPosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_posts do |t|
4
+ t.string :title
5
+ t.integer :post_type_id
6
+ t.string :status, default: 'unpublished'
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePulitzerContentElements < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_content_elements do |t|
4
+ t.string :label
5
+ t.string :title
6
+ t.text :body
7
+ t.string :image
8
+ t.integer :post_id
9
+ t.integer :post_type_content_element_type_id
10
+ t.integer :content_element_type_id
11
+
12
+ t.timestamps null: false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePulitzerTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_tags do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePulitzerPostTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_post_tags do |t|
4
+ t.integer :post_id
5
+ t.integer :label_id
6
+ t.integer :label_type
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePulitzerPostTypeContentElementTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_post_type_content_element_types do |t|
4
+ t.integer :post_type_id
5
+ t.integer :content_element_type_id
6
+ t.string :label
7
+ t.integer :height, default: 100
8
+ t.integer :width, default: 100
9
+
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class AddPluralAndTemplateToPulitzerPostTypes < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_post_types, :plural, :boolean
4
+ add_column :pulitzer_post_types, :template, :boolean
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ class AddPulitzerContentElementTypes < ActiveRecord::Migration
2
+ ELEMENT_TYPES = %w(Text Image Video)
3
+
4
+ def up
5
+ ELEMENT_TYPES.each do |type|
6
+ Pulitzer::ContentElementType.create(name: type)
7
+ end
8
+ end
9
+
10
+ def down
11
+ Pulitzer::ContentElementType.where(name: ELEMENT_TYPES).destroy_all
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class AddSlugToPulitzerPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_posts, :slug, :string
4
+ add_index :pulitzer_posts, :slug, unique: true
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeLabelTypeFromPulitzerPostTags < ActiveRecord::Migration
2
+ def change
3
+ change_column :pulitzer_post_tags, :label_type, :string
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class AddTextEditorToPulitzerPostTypeContentElementTypes < ActiveRecord::Migration
2
+ def up
3
+ add_column :pulitzer_post_type_content_element_types, :text_editor, :string
4
+ Pulitzer::PostTypeContentElementType.update_all(text_editor: 'None')
5
+ end
6
+
7
+ def down
8
+ remove_column :pulitzer_post_type_content_element_types, :text_editor
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePulitzerVersions < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_versions do |t|
4
+ t.integer :status, default: 0
5
+ t.integer :post_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ class ChangePostElementsToVersions < ActiveRecord::Migration
2
+ def up
3
+ rename_column :pulitzer_content_elements, :post_id, :version_id
4
+ rename_column :pulitzer_post_tags, :post_id, :version_id
5
+ Pulitzer::ContentElement.reset_column_information
6
+ Pulitzer::PostTag.reset_column_information
7
+
8
+ # Clone post content elements and clone tags, and assign them to the new version
9
+ Pulitzer::Post.find_each do |post|
10
+ version = post.create_preview_version
11
+ Pulitzer::ContentElement.where(version_id: post.id).update_all(version_id: version.id)
12
+ Pulitzer::PostTag.where(version_id: post.id).update_all(version_id: version.id)
13
+ end
14
+ end
15
+
16
+ def down
17
+ rename_column :pulitzer_content_elements, :version_id, :post_id
18
+ rename_column :pulitzer_post_tags, :version_id, :post_id
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ class AddPostTypeContentElementAttributesToContentElements < ActiveRecord::Migration
2
+ def up
3
+ add_column :pulitzer_content_elements, :text_editor, :string
4
+ add_column :pulitzer_content_elements, :height, :integer, default: 100
5
+ add_column :pulitzer_content_elements, :width, :integer, default: 100
6
+ add_column :pulitzer_content_elements, :sort_order, :integer
7
+ Pulitzer::ContentElement.reset_column_information
8
+ Pulitzer::ContentElement.find_each do |ce|
9
+ if ptce = ce.post_type_content_element_type
10
+ ce.update(text_editor: ptce.text_editor, height: ptce.height, width: ptce.width)
11
+ end
12
+ end
13
+ end
14
+
15
+ def down
16
+ remove_column :pulitzer_content_elements, :text_editor
17
+ remove_column :pulitzer_content_elements, :height
18
+ remove_column :pulitzer_content_elements, :width
19
+ remove_column :pulitzer_content_elements, :sort_order
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ class ChangeTemplateToPulitzerPostTypes < ActiveRecord::Migration
2
+ def up
3
+ remove_column :pulitzer_post_types, :template
4
+ add_column :pulitzer_post_types, :kind, :integer, default: 0
5
+ end
6
+
7
+ def down
8
+ remove_column :pulitzer_post_types, :kind
9
+ add_column :pulitzer_post_types, :template, :boolean
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddKindToPulitzerContentElements < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_content_elements, :kind, :integer, default: 0
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddErrorsToVersion < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_versions, :cloning_errors, :jsonb
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePartials < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_partials do |t|
4
+ t.integer :post_type_id
5
+ t.integer :free_form_section_id
6
+ t.integer :sort_order
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class AddParentIdToPulitzerTag < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_tags, :parent_id, :integer
4
+ add_column :pulitzer_tags, :hierarchical, :boolean, null: false, default: false
5
+ add_index :pulitzer_tags, :hierarchical
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddPartialToContentElement < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_content_elements, :partial_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ class CreateFreeFormSectionType < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_free_form_section_types do |t|
4
+ t.integer :post_type_id
5
+ t.string :name
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateFreeFormSection < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_free_form_sections do |t|
4
+ t.integer :version_id
5
+ t.integer :free_form_section_type_id
6
+ t.string :name
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class FixPostTypeKinds < ActiveRecord::Migration
2
+ def change
3
+ Pulitzer::PostType.where(kind: [1,2]).each do |pt|
4
+ pt.update_columns(kind: 0)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class CreateLayouts < ActiveRecord::Migration
2
+ def change
3
+ create_table :pulitzer_layouts do |t|
4
+ t.integer :post_type_id
5
+ t.string :name
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddLayoutToPartial < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_partials, :layout_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddLabelToPartial < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_partials, :label, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveTitleFromContentElements < ActiveRecord::Migration
2
+ def change
3
+ remove_column :pulitzer_content_elements, :title
4
+ end
5
+ end