Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Nov 27, 2019
1 parent 2fdd692 commit 7611357
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ DEPENDENCIES
web-console (~> 3.5)

RUBY VERSION
ruby 2.6.5p114
ruby 2.6.3p62

BUNDLED WITH
2.0.2
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<%= render partial: "tabs", locals: { tabs: blueprints } %>
<%= render partial: "tabs_content", locals: { tabs: blueprints } %>



<div class="loading">
<div class="inner-loading">
<div class="spinner"></div>
Expand Down
2 changes: 1 addition & 1 deletion app/commands/decidim/navigation_maps/save_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def call
attr_reader :form, :current_blueprint

def initialize_area
@area = BlueprintArea.find_or_initialize_by(area_id: form.area_id, blueprint: @form.context.current_blueprint);
@area = BlueprintArea.find_or_initialize_by(area_id: form.area_id, blueprint: @form.context.current_blueprint)
end

def update_area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def update

def parse_areas
return unless params[:blueprint_area]
return unless params[:blueprint_area][:area].present?
return if params[:blueprint_area][:area].blank?

feature = JSON.parse params[:blueprint_area][:area]
params[:blueprint_area][:area] = feature["geometry"] if feature["geometry"]
Expand Down
28 changes: 14 additions & 14 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ en:
navigation_maps:
admin:
areas:
create:
error: An error ocurred while creating the area
success: Area created successfully
new:
area: New area details
save: Save
cancel: Cancel
save: Save
show:
area: Area details
save: Save
cancel: Cancel
save: Save
update:
success: Area saved successfully
error: An error ocurred while saving the area
create:
success: Area created successfully
error: An error ocurred while creating the area
success: Area saved successfully
content_blocks:
name: Navigation Maps
navigation_map_settings_form:
add: Add
blueprint_image: Blueprint image
image_missing: Please add a blueprint image to start
upload_image: Upload image
id: Id
type: Type
link: Link
title: Title
description: Description
add: Add
info: General info
editor: Map Editor
id: Id
image_missing: Please add a blueprint image to start
info: General info
link: Link
remove_blueprint: Delete this blueprint
title: Title
type: Type
upload_image: Upload image
create:
error: Error creating blueprint
success: Blueprint created successfully
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# frozen_string_literal: true

class CreateDecidimNavigationMapsBlueprintAreas < ActiveRecord::Migration[5.2]
class Blueprint < ApplicationRecord
self.table_name = "decidim_navigation_maps_blueprints"
end

class Area < ApplicationRecord
self.table_name = "decidim_navigation_maps_blueprint_areas"
end

def change
create_table :decidim_navigation_maps_blueprint_areas do |t|
t.jsonb :area
Expand All @@ -21,20 +13,6 @@ def change
t.timestamps
end

# Search areas and create distributed entries
Blueprint.find_each do |blueprint|
next unless blueprint.blueprint

blueprint.blueprint.each do |_key, area|
Area.create!(
area: area["geometry"],
decidim_navigation_maps_blueprint_id: blueprint.id,
area_type: area["type"],
url: area["properties"]["link"]
)
end
end

remove_column :decidim_navigation_maps_blueprints, :blueprint, :jsonb
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddAreaIdToDecidimNavigationMapsBlueprintAreas < ActiveRecord::Migration[5.2]
class Area < ApplicationRecord
self.table_name = "decidim_navigation_maps_blueprint_areas"
Expand Down
11 changes: 9 additions & 2 deletions lib/decidim/navigation_maps/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

factory :blueprint_area, class: Decidim::NavigationMaps::BlueprintArea do
blueprint { create(:blueprint) }
area { { x: 1, y: 1 } }
area do
{
"x" => 1,
"y" => 1
}
end
area_type { "Feature" }
link { "#" }
area_id { "1" }
link { "#link" }
link_type { "link" }
title { Decidim::Faker::Localized.word }
description { generate_localized_title }
end
Expand Down
20 changes: 12 additions & 8 deletions spec/commands/save_area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ module Decidim::NavigationMaps

let(:blueprint) { create :blueprint }
let(:form) do
double(
AreaForm,
AreaForm
.from_params(attributes)
.with_context(current_blueprint: blueprint)
end
let(:attributes) do
{
area: data,
id: id,
area_id: area_id,
title: title,
description: title,
link: link,
current_blueprint: blueprint
)
}
end
let(:data) do
{ x: 0.5, y: 0.6 }
end
let(:title) { Decidim::Faker::Localized.sentence(2) }
let(:description) { Decidim::Faker::Localized.paragraph }
let(:id) { nil }
let(:area_id) { nil }
let(:link) { "#link" }

before do
Expand All @@ -42,20 +46,20 @@ module Decidim::NavigationMaps

context "when id exists" do
let!(:blueprint_area) { create(:blueprint_area, blueprint: blueprint) }
let(:id) { blueprint_area.id }
let(:area_id) { blueprint_area.area_id }

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

it "creates the area" do
it "updates the area" do
expect { subject.call }.to change(BlueprintArea, :count).by(0)
end
end

context "when id does not exist" do
let(:blueprint_area) { build(:blueprint_area, id: id, blueprint: blueprint) }
let(:id) { 11101 }
let(:id) { 11_101 }

it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Decidim::NavigationMaps::Admin
let(:user) { create(:user, :confirmed, :admin, organization: organization) }
let(:blueprint) { create(:blueprint, organization: organization) }

let(:params) do
let(:attributes) do
{
blueprint_area: {
area: data,
Expand Down Expand Up @@ -48,13 +48,14 @@ module Decidim::NavigationMaps::Admin
let!(:area) { create(:blueprint_area, blueprint: blueprint) }

it "returns http success" do
get :show, params: { blueprint_id: blueprint.id, id: area.id }
get :show, params: { blueprint_id: blueprint.id, area_id: area.area_id }
expect(response).to have_http_status(:success)
end
end

context "when area does not exist" do
it "redirects to new" do
get :show, params: { blueprint_id: blueprint.id, id: 1111 }
get :show, params: { blueprint_id: blueprint.id, area_id: 1111 }
expect(response).to have_http_status(:success)
end
end
Expand All @@ -64,7 +65,7 @@ module Decidim::NavigationMaps::Admin
let!(:area) { create(:blueprint_area, blueprint: blueprint) }

it "returns http success" do
post :update, params: { blueprint_id: blueprint.id, id: area.id }
post :update, params: { blueprint_id: blueprint.id, area_id: area.area_id }
expect(response).to have_http_status(:success)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module Decidim::NavigationMaps::Admin
routes { Decidim::NavigationMaps::AdminEngine.routes }

let(:user) { create(:user, :confirmed, :admin, organization: organization) }
let(:organization) do
create(:organization)
end
let(:organization) { create(:organization) }
let(:params) do
{
blueprints: {
Expand Down
9 changes: 7 additions & 2 deletions spec/model/blueprint_area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ module NavigationMaps

let(:organization) { create(:organization) }
let(:blueprint) { create(:blueprint, organization: organization) }
let(:blueprint_area) { build(:blueprint_area, title: title, description: description, link: link, area: area, blueprint: blueprint) }
let(:blueprint_area) { build(:blueprint_area, blueprint: blueprint) }
let(:area) do
{
"x" => "coord x",
"y" => "coord y"
}
end
let(:area_id) { "101" }
let(:title) { Decidim::Faker::Localized.sentence(2) }
let(:description) { Decidim::Faker::Localized.paragraph }
let(:link) { "#link" }
Expand All @@ -29,18 +30,21 @@ module NavigationMaps

# TODO: validate json area
context "when all fields are specified" do
let!(:blueprint_area) { create(:blueprint_area, title: title, description: description, link: link, area: area, area_id: area_id, blueprint: blueprint) }

it "saves data correctly" do
subject.save
subject.reload
expect(subject.title).to eq(title)
expect(subject.description).to eq(description)
expect(subject.link).to eq(link)
expect(subject.area_id).to eq(area_id)
expect(subject.area).to eq(area)
end
end

context "when no area" do
let!(:blueprint_area) { create(:blueprint_area, title: title, description: description, link: link, area: area, blueprint: blueprint) }
let!(:blueprint_area) { create(:blueprint_area, area: area, area_id: area_id, blueprint: blueprint) }

it "save data without area" do
a = BlueprintArea.find(blueprint_area.id)
Expand All @@ -52,6 +56,7 @@ module NavigationMaps
expect(a.title).to eq(title)
expect(a.description).to eq(description)
expect(a.link).to eq(link)
expect(a.area_id).to eq(area_id)
expect(a.area).to eq(area)
end
end
Expand Down
29 changes: 20 additions & 9 deletions spec/model/blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,35 @@ module NavigationMaps

context "when areas are defined" do
let!(:blueprint) { create(:blueprint, organization: organization) }
let!(:area1) { create(:blueprint_area, area: data1, blueprint: blueprint) }
let!(:area2) { create(:blueprint_area, area: data2, blueprint: blueprint) }
let!(:area1) { create(:blueprint_area, area: data, area_id: "101", link: "#link1", blueprint: blueprint) }
let!(:area2) { create(:blueprint_area, area: data, area_id: "102", link: "#link1", blueprint: blueprint) }

let(:blueprint_object) do
{
area1.id.to_s => {
"101" => {
type: "Feature",
geometry: data1
geometry: data,
properties: properties
},
area2.id.to_s => {
"102" => {
type: "Feature",
geometry: data2
geometry: data,
properties: properties
}
}
end
let(:area3) { create(:blueprint_area, area: data2) }
let(:data1) { { "x" => "coord x", "y" => "coord y" } }
let(:data2) { { "x" => "coord x", "y" => "coord y" } }
let(:area3) { create(:blueprint_area, area: data) }
let(:data) do
{
"x" => "coord x",
"y" => "coord y"
}
end
let(:properties) do
{
link: "#link1"
}
end

it { is_expected.to be_valid }

Expand Down

0 comments on commit 7611357

Please sign in to comment.