Skip to content

Commit

Permalink
Rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed May 5, 2020
1 parent b900263 commit d92aa0b
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 92 deletions.
19 changes: 4 additions & 15 deletions app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,10 @@ def allowed_filetypes

stampable stamper_class_name: Alchemy.user_class_name

scope :named, ->(name) {
where("#{table_name}.name LIKE ?", "%#{name}%")
}

scope :recent, -> {
where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at)
}

scope :deletable, -> {
where("#{table_name}.id NOT IN (SELECT picture_id FROM #{EssencePicture.table_name})")
}

scope :without_tag, -> {
left_outer_joins(:taggings).where(gutentag_taggings: { id: nil })
}
scope :named, ->(name) { where("#{table_name}.name LIKE ?", "%#{name}%") }
scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) }
scope :deletable, -> { where("#{table_name}.id NOT IN (SELECT picture_id FROM #{EssencePicture.table_name})") }
scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: { id: nil }) }

# Class methods

Expand Down
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_boolean_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module Alchemy
class EssenceBooleanSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:value,
)
end
end
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_date_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module Alchemy
class EssenceDateSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:date,
)
end
end
6 changes: 4 additions & 2 deletions app/serializers/alchemy/essence_file_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module Alchemy
class EssenceFileSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:title,
:css_class
:css_class,
)

has_one :attachment
end
Expand Down
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_html_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module Alchemy
class EssenceHtmlSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:source,
)
end
end
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_link_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

module Alchemy
class EssenceLinkSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:link,
:link_title,
:link_target,
:link_class_name,
)
end
end
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_picture_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

module Alchemy
class EssencePictureSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:picture_id,
:caption,
:title,
:alt_tag,
:css_class,
:link,
)

has_one :picture

Expand Down
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_richtext_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module Alchemy
class EssenceRichtextSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:body,
:stripped_body,
)
end
end
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_select_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module Alchemy
class EssenceSelectSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:value,
)
end
end
4 changes: 3 additions & 1 deletion app/serializers/alchemy/essence_text_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module Alchemy
class EssenceTextSerializer < ActiveModel::Serializer
attributes :id,
attributes(
:id,
:body,
:link,
)

def link
return if object.link.blank?
Expand Down
32 changes: 16 additions & 16 deletions spec/controllers/alchemy/admin/essence_files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ module Alchemy
end

let(:essence_file) { mock_model("EssenceFile", :attachment= => nil, content: content) }
let(:content) { mock_model("Content") }
let(:attachment) { mock_model("Attachment") }
let(:content) { mock_model("Content") }
let(:attachment) { mock_model("Attachment") }

describe "#edit" do
before do
expect(EssenceFile).to receive(:find)
.with(essence_file.id.to_s)
.and_return(essence_file)
.with(essence_file.id.to_s)
.and_return(essence_file)
end

it "assigns @essence_file with the EssenceFile found by id" do
get :edit, params: {id: essence_file.id}
get :edit, params: { id: essence_file.id }
expect(assigns(:essence_file)).to eq(essence_file)
end

it "should assign @content with essence_file's content" do
get :edit, params: {id: essence_file.id}
get :edit, params: { id: essence_file.id }
expect(assigns(:content)).to eq(content)
end
end
Expand All @@ -41,13 +41,13 @@ module Alchemy

it "should update the attributes of essence_file" do
put :update, params: {
id: essence_file.id,
essence_file: {
title: "new title",
css_class: "left",
link_text: "Download this file",
},
}, xhr: true
id: essence_file.id,
essence_file: {
title: "new title",
css_class: "left",
link_text: "Download this file",
},
}, xhr: true
expect(essence_file.title).to eq "new title"
expect(essence_file.css_class).to eq "left"
expect(essence_file.link_text).to eq "Download this file"
Expand All @@ -64,19 +64,19 @@ module Alchemy
end

it "should assign @attachment with the Attachment found by attachment_id" do
put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true
put :assign, params: { content_id: content.id, attachment_id: attachment.id }, xhr: true
expect(assigns(:attachment)).to eq(attachment)
end

it "should assign @content.essence.attachment with the attachment found by id" do
expect(content.essence).to receive(:attachment=).with(attachment)
put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true
put :assign, params: { content_id: content.id, attachment_id: attachment.id }, xhr: true
end

it "updates the elements updated_at column" do
content.element.update_column(:updated_at, 3.days.ago)
expect {
put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true
put :assign, params: { content_id: content.id, attachment_id: attachment.id }, xhr: true
}.to change(content.element, :updated_at)
end
end
Expand Down
54 changes: 27 additions & 27 deletions spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Alchemy
end

it "should assign @essence_picture and @content instance variables" do
post :edit, params: {id: 1, content_id: 1}
post :edit, params: { id: 1, content_id: 1 }
expect(assigns(:essence_picture)).to be_a(EssencePicture)
expect(assigns(:content)).to be_a(Content)
end
Expand All @@ -36,7 +36,7 @@ module Alchemy
end

it "renders error message" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:no_image_notice)).to eq(Alchemy.t(:no_image_for_cropper_found))
end
end
Expand Down Expand Up @@ -71,14 +71,14 @@ module Alchemy
end

it "sets sizes to given values" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 300, height: 250 })
end
end

context "with no sizes in content settngs" do
it "sets sizes to zero" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 0, height: 0 })
end
end
Expand All @@ -88,16 +88,16 @@ module Alchemy
it "sets sizes from these values" do
expect(essence).to receive(:render_size).at_least(:once).and_return("30x25")

get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 30, height: 25 })
end

context "when width or height is not fixed" do
it "infers the height from the image file preserving the aspect ratio" do
expect(essence).to receive(:render_size).at_least(:once).and_return("30x")

get :crop, params: {id: 1}
expect(assigns(:min_size)).to eq({ width: 30, height: 0})
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 30, height: 0 })
end

context "and aspect ratio set on the contents settings" do
Expand All @@ -108,7 +108,7 @@ module Alchemy
it "does not infer the height from the image file preserving the aspect ratio" do
expect(essence).to receive(:render_size).at_least(:once).and_return("x25")

get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 50, height: 25 })
end
end
Expand All @@ -123,16 +123,16 @@ module Alchemy
it "width is given, it infers the height from width and ratio" do
expect(essence).to receive(:render_size).at_least(:once).and_return("30x")

get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 30, height: 60 })
end
end

it "infers the height from the image file preserving the aspect ratio" do
expect(essence).to receive(:render_size).at_least(:once).and_return("x25")

get :crop, params: {id: 1}
expect(assigns(:min_size)).to eq({ width: 0, height: 25})
get :crop, params: { id: 1 }
expect(assigns(:min_size)).to eq({ width: 0, height: 25 })
end
end
end
Expand All @@ -144,14 +144,14 @@ module Alchemy
end

it "assigns default mask boxes" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:initial_box)).to eq(default_mask)
expect(assigns(:default_box)).to eq(default_mask)
end
end

context "crop sizes present in essence" do
let(:mask) { {"x1" => "0", "y1" => "0", "x2" => "120", "y2" => "160"} }
let(:mask) { { "x1" => "0", "y1" => "0", "x2" => "120", "y2" => "160" } }

before do
allow(essence).to receive(:crop_from).and_return("0x0")
Expand All @@ -160,7 +160,7 @@ module Alchemy

it "assigns cropping boxes" do
expect(essence).to receive(:cropping_mask).and_return(mask)
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:initial_box)).to eq(mask)
expect(assigns(:default_box)).to eq(default_mask)
end
Expand All @@ -172,7 +172,7 @@ module Alchemy
end

it "sets ratio to false" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:ratio)).to eq(false)
end
end
Expand All @@ -183,7 +183,7 @@ module Alchemy
end

it "doesn't set a fixed ratio" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:ratio)).to eq(false)
end
end
Expand All @@ -194,7 +194,7 @@ module Alchemy
end

it "sets a fixed ratio from sizes" do
get :crop, params: {id: 1}
get :crop, params: { id: 1 }
expect(assigns(:ratio)).to eq(80.0 / 60.0)
end
end
Expand All @@ -219,19 +219,19 @@ module Alchemy

it "updates the essence attributes" do
expect(essence).to receive(:update).and_return(true)
put :update, params: {id: 1, essence_picture: attributes}, xhr: true
put :update, params: { id: 1, essence_picture: attributes }, xhr: true
end

it "saves the cropping mask" do
expect(essence).to receive(:update).and_return(true)
put :update, params: {
id: 1,
essence_picture: {
render_size: "1x1",
crop_from: "0x0",
crop_size: "100x100",
},
}, xhr: true
id: 1,
essence_picture: {
render_size: "1x1",
crop_from: "0x0",
crop_size: "100x100",
},
}, xhr: true
end
end

Expand All @@ -245,14 +245,14 @@ module Alchemy
end

it "should assign a Picture" do
put :assign, params: {content_id: "1", picture_id: "1"}, xhr: true
put :assign, params: { content_id: "1", picture_id: "1" }, xhr: true
expect(assigns(:content).essence.picture).to eq(picture)
end

it "updates the element timestamp" do
content.element.update_column(:updated_at, 3.days.ago)
expect {
put :assign, params: {content_id: "1", picture_id: "1"}, xhr: true
put :assign, params: { content_id: "1", picture_id: "1" }, xhr: true
}.to change(content.element, :updated_at)
end
end
Expand Down
Loading

0 comments on commit d92aa0b

Please sign in to comment.