-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e3ce68
commit 3daac9c
Showing
6 changed files
with
116 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module NavigationMaps | ||
# Abstract class from which all models in this engine inherit. | ||
class BlueprintArea < ApplicationRecord | ||
self.table_name = "decidim_navigation_maps_blueprint_areas" | ||
|
||
belongs_to :blueprint, foreign_key: :decidim_navigation_maps_blueprint_id, class_name: "Decidim::NavigationMaps::Blueprint" | ||
|
||
validates :blueprint, presence: true | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
db/migrate/20191125142751_create_decidim_navigation_maps_blueprint_areas.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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 | ||
t.references :decidim_navigation_maps_blueprint, null: false, foreign_key: true, index: { name: "decidim_navigation_maps_constraint_blueprint_id" } | ||
t.jsonb :title, default: {} | ||
t.jsonb :description, default: {} | ||
t.string :area_type | ||
t.string :url | ||
|
||
t.timestamps | ||
end | ||
|
||
# Search areas and create distributed entries | ||
Blueprint.find_each do |blueprint| | ||
blueprint.blueprint.each do |_key, area| | ||
Area.create!( | ||
area: area, | ||
decidim_navigation_maps_blueprint_id: blueprint.id, | ||
area_type: "link", | ||
url: area["properties"]["link"] | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim | ||
module NavigationMaps | ||
describe BlueprintArea do | ||
subject { blueprint_area } | ||
|
||
let(:organization) { create(:organization) } | ||
let(:blueprint) { create(:blueprint, organization: organization) } | ||
let(:blueprint_area) { build(:blueprint_area, blueprint: blueprint) } | ||
let(:data) { { x: "coord x", y: "coord y" } } | ||
|
||
it { is_expected.to be_valid } | ||
|
||
it "blueprint is associated with organization" do | ||
expect(subject.blueprint).to eq(blueprint) | ||
expect(subject.blueprint.organization).to eq(organization) | ||
end | ||
|
||
# TODO: validate json area | ||
|
||
# context "when no data" do | ||
# let(:data) { [] } | ||
# it "is not valid" do | ||
# expect(subject).not_to be_valid | ||
# end | ||
# end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters