Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namspacing for data resources #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_event_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CreateEventRecord < BaseMutation

def resolve(**params)
ResourceService.new(data_provider: context[:current_user].try(:data_provider))
.create(EventRecord, params)
.create(DataResource::EventRecord, params)
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_news_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CreateNewsItem < BaseMutation

def resolve(**params)
ResourceService.new(data_provider: context[:current_user].try(:data_provider))
.create(NewsItem, params)
.create(DataResource::NewsItem, params)
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_point_of_interest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CreatePointOfInterest < BaseMutation

def resolve(**params)
ResourceService.new(data_provider: context[:current_user].try(:data_provider))
.create(PointOfInterest, params)
.create(DataResource::PointOfInterest, params)
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_tour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CreateTour < BaseMutation

def resolve(**params)
ResourceService.new(data_provider: context[:current_user].try(:data_provider))
.create(Tour, params)
.create(DataResource::Tour, params)
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/mutations/destroy_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DestroyRecord < BaseMutation

type Types::DestroyType

RECORD_WHITELIST = ["EventRecord", "NewsItem", "PointOfInterest", "Tour"].freeze
RECORD_WHITELIST = ["DataResource::EventRecord", "DataResource::NewsItem", "DataResource::PointOfInterest", "DataResource::Tour"].freeze

def resolve(id: nil, record_type:, external_id: nil)
return error_status unless RECORD_WHITELIST.include?(record_type)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/event_records_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Resolvers::EventRecordsSearch
include SearchObject.module(:graphql)

scope { EventRecord.filtered_for_current_user(context[:current_user]) }
scope { DataResource::EventRecord.filtered_for_current_user(context[:current_user]) }

type types[Types::EventRecordType]

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/news_items_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Resolvers::NewsItemsSearch
include SearchObject.module(:graphql)

scope { NewsItem.filtered_for_current_user(context[:current_user]) }
scope { DataResource::NewsItem.filtered_for_current_user(context[:current_user]) }

type types[Types::NewsItemType]

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/points_of_interest_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Resolvers::PointsOfInterestSearch
include SearchObject.module(:graphql)

scope { PointOfInterest.filtered_for_current_user(context[:current_user]) }
scope { DataResource::PointOfInterest.filtered_for_current_user(context[:current_user]) }

type types[Types::PointOfInterestType]

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/tours_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Resolvers::ToursSearch
include SearchObject.module(:graphql)

scope { Tour.filtered_for_current_user(context[:current_user]) }
scope { DataResource::Tour.filtered_for_current_user(context[:current_user]) }

type types[Types::TourType]

Expand Down
8 changes: 4 additions & 4 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ class QueryType < Types::BaseObject
field :categories, [CategoryType], null: false

def point_of_interest(id:)
PointOfInterest.find(id)
DataResource::PointOfInterest.find(id)
end

def event_record(id:)
EventRecord.find(id)
DataResource::EventRecord.find(id)
end

def news_item(id:)
NewsItem.find(id)
DataResource::NewsItem.find(id)
end

def tour(id:)
Tour.find(id)
DataResource::Tour.find(id)
end

def categories
Expand Down
2 changes: 1 addition & 1 deletion app/models/attraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Attraction < ApplicationRecord
# callback function which enables setting of category by
# virtual attribute category name. ATTENTION: With this callback
# the setting of category is only possible with category_name
# PointOfInterest.create(category: Category.first) doesn't work anymore.
# DataResource::PointOfInterest.create(category: Category.first) doesn't work anymore.
#
def set_category_id
self.category_id = find_or_create_category.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# this model describes the data for an event e.g. a concert or a reading.
class EventRecord < ApplicationRecord
class DataResource::EventRecord < ApplicationRecord
attr_accessor :category_name
attr_accessor :region_name
attr_accessor :force_create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# News Item is one of the four Main resources for the app. A news Item can be anything
# from an old school news article to a whole story structured in chapters
class NewsItem < ApplicationRecord
class DataResource::NewsItem < ApplicationRecord
attr_accessor :force_create

belongs_to :data_provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# All locations which are interesting and attractive for the public in the
# smart village and the surrounding area
#
class PointOfInterest < Attraction
class DataResource::PointOfInterest < Attraction
attr_accessor :force_create

has_many :opening_hours, as: :openingable, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/tour.rb → app/models/data_resource/tour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# A Tour is a planned route to walk ride or canoe and which passes through
# the surrounding areas of the Smart Village
#
class Tour < Attraction
class DataResource::Tour < Attraction
attr_accessor :force_create

has_many :geometry_tour_data, as: :geo_locateable, class_name: "GeoLocation", dependent: :destroy
Expand Down
8 changes: 4 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_content_block
create_categories

10.times do |n|
poi = PointOfInterest.create(
poi = DataResource::PointOfInterest.create(
name: "Burg #{n}",
description: Faker::Lorem.paragraph,
mobile_description: Faker::Lorem.paragraph,
Expand All @@ -212,7 +212,7 @@ def create_content_block
end

10.times do |n|
tour = Tour.create(
tour = DataResource::Tour.create(
name: "Tour #{n}",
description: Faker::Lorem.paragraph,
mobile_description: Faker::Lorem.paragraph,
Expand All @@ -237,7 +237,7 @@ def create_content_block
end

10.times do |n|
event = EventRecord.create(
event = DataResource::EventRecord.create(
title: "Konzert #{n}",
description: Faker::Lorem.paragraph,
repeat: Faker::Boolean.boolean(0.3),
Expand Down Expand Up @@ -266,7 +266,7 @@ def create_content_block
end

10.times do
news_item = NewsItem.create(
news_item = DataResource::NewsItem.create(
author: Faker::Name.name,
full_version: true,
characters_to_be_shown: false,
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/mutations/create_tour_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe Mutations::Tour do
RSpec.describe Mutations::CreateTour do
def perform(**args)
Mutations::CreateTour.new(object: nil, context: {}).resolve(args)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe EventRecord, type: :model do
RSpec.describe DataResource::EventRecord, type: :model do
let(:event_record_2) { create(:event_record) }
let(:event_record_1) { create(:event_record) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe NewsItem, type: :model do
RSpec.describe DataResource::NewsItem, type: :model do
it { is_expected.to have_many(:content_blocks) }
it { is_expected.to have_one(:address) }
it { is_expected.to have_one(:data_provider) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe PointOfInterest, type: :model do
RSpec.describe DataResource::PointOfInterest, type: :model do
it { is_expected.to have_many(:addresses) }
it { is_expected.to have_one(:contact) }
it { is_expected.to have_one(:operating_company) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe Tour, type: :model do
RSpec.describe DataResource::Tour, type: :model do
it { is_expected.to have_many(:geometry_tour_data) }
it { is_expected.to define_enum_for(:means_of_transportation) }
end
Expand Down
38 changes: 19 additions & 19 deletions spec/services/resource_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
RSpec.describe ResourceService, type: :service do
let(:maz) { create(:data_provider, name: "MAZ", news_item: true) }
let(:tmb) { create(:data_provider, name: "TMB") }
let(:news_item_1) { ResourceService.new(data_provider: maz).create(NewsItem, params_maz) }
let(:news_item_2) { ResourceService.new(data_provider: maz).create(NewsItem, params_maz) }
let(:poi_1) { ResourceService.new(data_provider: tmb).create(PointOfInterest, params_tmb_poi) }
let(:poi_1_changed) { ResourceService.new(data_provider: tmb).create(PointOfInterest, params_tmb_poi_changed) }
let(:poi_2) { ResourceService.new(data_provider: tmb).create(PointOfInterest, params_tmb_poi) }
let(:tour_1) { ResourceService.new(data_provider: tmb).create(Tour, params_tmb_tour) }
let(:tour_1_changed) { ResourceService.new(data_provider: tmb).create(Tour, params_tmb_tour_changed) }
let(:tour_2) { ResourceService.new(data_provider: tmb).create(Tour, params_tmb_tour) }
let(:event_1) { ResourceService.new(data_provider: tmb).create(EventRecord, params_tmb_event) }
let(:event_1_changed) { ResourceService.new(data_provider: tmb).create(EventRecord, params_tmb_event_changed) }
let(:event_2) { ResourceService.new(data_provider: tmb).create(EventRecord, params_tmb_event) }
let(:news_item_1) { ResourceService.new(data_provider: maz).create(DataResource::NewsItem, params_maz) }
let(:news_item_2) { ResourceService.new(data_provider: maz).create(DataResource::NewsItem, params_maz) }
let(:poi_1) { ResourceService.new(data_provider: tmb).create(DataResource::PointOfInterest, params_tmb_poi) }
let(:poi_1_changed) { ResourceService.new(data_provider: tmb).create(DataResource::PointOfInterest, params_tmb_poi_changed) }
let(:poi_2) { ResourceService.new(data_provider: tmb).create(DataResource::PointOfInterest, params_tmb_poi) }
let(:tour_1) { ResourceService.new(data_provider: tmb).create(DataResource::Tour, params_tmb_tour) }
let(:tour_1_changed) { ResourceService.new(data_provider: tmb).create(DataResource::Tour, params_tmb_tour_changed) }
let(:tour_2) { ResourceService.new(data_provider: tmb).create(DataResource::Tour, params_tmb_tour) }
let(:event_1) { ResourceService.new(data_provider: tmb).create(DataResource::EventRecord, params_tmb_event) }
let(:event_1_changed) { ResourceService.new(data_provider: tmb).create(DataResource::EventRecord, params_tmb_event_changed) }
let(:event_2) { ResourceService.new(data_provider: tmb).create(DataResource::EventRecord, params_tmb_event) }

def params_maz
{ author: "Robert sdf",
Expand Down Expand Up @@ -159,10 +159,10 @@ def params_tmb_event_changed
end

it "deletes the old record" do
expect(NewsItem.exists?(news_item_1.id)).to eq(false)
expect(DataResource::NewsItem.exists?(news_item_1.id)).to eq(false)
end
it "creates a new record" do
expect(NewsItem.exists?(news_item_2.id)).to eq(true)
expect(DataResource::NewsItem.exists?(news_item_2.id)).to eq(true)
end
it "the new record has the same external_id as the old one" do
expect(news_item_1.external_id).to eq(news_item_2.external_id)
Expand Down Expand Up @@ -210,17 +210,17 @@ def params_tmb_event_changed
expect(poi_1_changed.id).not_to eq(poi_1.id)
expect(tour_1_changed.id).not_to eq(tour_1.id)
expect(event_1_changed.id).not_to eq(event_1.id)
expect(PointOfInterest.exists?(poi_1_changed.id)).to eq(true)
expect(Tour.exists?(tour_1_changed.id)).to eq(true)
expect(EventRecord.exists?(event_1_changed.id)).to eq(true)
expect(DataResource::PointOfInterest.exists?(poi_1_changed.id)).to eq(true)
expect(DataResource::Tour.exists?(tour_1_changed.id)).to eq(true)
expect(DataResource::EventRecord.exists?(event_1_changed.id)).to eq(true)
end
it "destroys the old record" do
poi_1_changed
tour_1_changed
event_1_changed
expect(PointOfInterest.exists?(poi_1.id)).to eq(false)
expect(Tour.exists?(tour_1.id)).to eq(false)
expect(EventRecord.exists?(event_1.id)).to eq(false)
expect(DataResource::PointOfInterest.exists?(poi_1.id)).to eq(false)
expect(DataResource::Tour.exists?(tour_1.id)).to eq(false)
expect(DataResource::EventRecord.exists?(event_1.id)).to eq(false)
end
end
end
Expand Down