Skip to content

Commit

Permalink
create blueprints test
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Nov 23, 2019
1 parent b87d196 commit d3b8134
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 26 deletions.
18 changes: 16 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,38 @@ version: "2"
checks:
argument-count:
enabled: false

complex-logic:
enabled: false

file-lines:
enabled: false

method-complexity:
enabled: false

method-count:
enabled: false

method-lines:
enabled: false

nested-control-flow:
enabled: false

return-statements:
enabled: false

similar-code:
enabled: false
identical-code:
enabled: false

plugins:
bundler-audit:
enabled: true

csslint:
enabled: true

duplication:
enabled: true

Expand Down Expand Up @@ -63,6 +75,8 @@ plugins:
issue_override:
severity: minor

stylelint:
enabled: true

exclude_patterns:
- "**/vendor/"
Expand Down
2 changes: 1 addition & 1 deletion app/commands/decidim/navigation_maps/create_blueprints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call
next if form.invalid?

create_blueprint(form)
if form.remove?
if form.remove
destroy_blueprint!(form)
else
update_blueprint!(form)
Expand Down
23 changes: 0 additions & 23 deletions spec/commands/create_blueprint_spec.rb

This file was deleted.

81 changes: 81 additions & 0 deletions spec/commands/create_blueprints_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim::NavigationMaps
describe CreateBlueprints do
subject { described_class.new(forms) }

let(:organization) { create :organization }
let(:forms) do
instance_double(
BlueprintForms,
blueprints: blueprints,
current_organization: organization
)
end
let(:blueprints) { [form1, form2] }
let(:form1) do
double(
BlueprintForm,
blueprint: data,
id: 1,
title: title,
description: title,
remove: remove,
image: uploaded_image
)
end
let(:form2) do
double(
BlueprintForm,
blueprint: data,
id: 2,
title: title,
description: nil,
remove: false,
image: nil
)
end
let(:data) do
{ x: 0.5, y: 0.6 }
end
let(:title) { Decidim::Faker::Localized.sentence(2) }
let(:remove) { false }
let(:uploaded_image) do
Rack::Test::UploadedFile.new(
Decidim::Dev.test_file("city.jpeg", "image/jpeg"),
"image/jpeg"
)
end

before do
allow(form1).to receive(:invalid?).and_return(false)
allow(form2).to receive(:invalid?).and_return(false)
end

context "when everything is ok" do
it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
end

it "creates all the blueprints" do
expect { subject.call }.to change(Blueprint, :count).by(2)
end
end

context "when one form is invalid" do
before do
allow(form1).to receive(:invalid?).and_return(true)
end

it "still broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
end

it "creates one blueprint" do
expect { subject.call }.to change(Blueprint, :count).by(1)
end
end
end
end

0 comments on commit d3b8134

Please sign in to comment.