Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #88 Create a resource detailing an abstraction schema.
- Loading branch information
Showing
7 changed files
with
97 additions
and
2 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
5 changes: 5 additions & 0 deletions
5
app/controllers/abstractor/abstractor_abstraction_schemas_controller.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,5 @@ | ||
module Abstractor | ||
class AbstractorAbstractionSchemasController < Abstractor::ApplicationController | ||
include Abstractor::Methods::Controllers::AbstractorAbstractionSchemasController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ | |
end | ||
resources :abstractor_suggestions | ||
end | ||
|
||
resources :abstractor_abstraction_schemas do | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/abstractor/methods/controllers/abstractor_abstraction_schemas_controller.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,23 @@ | ||
module Abstractor | ||
module Methods | ||
module Controllers | ||
module AbstractorAbstractionSchemasController | ||
def self.included(base) | ||
base.send :helper, :all | ||
base.send :before_filter, :set_abstractor_abstraction_schema, only: :show | ||
end | ||
|
||
def show | ||
respond_to do |format| | ||
format.json { render json: Abstractor::Serializers::AbstractorAbstractionSchemaSerializer.new(@abstractor_abstraction_schema).as_json } | ||
end | ||
end | ||
|
||
private | ||
def set_abstractor_abstraction_schema | ||
@abstractor_abstraction_schema = Abstractor::AbstractorAbstractionSchema.find(params[:id]) | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
lib/abstractor/serializers/abstractor_abstraction_schema_serializer.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,29 @@ | ||
module Abstractor | ||
module Serializers | ||
class AbstractorAbstractionSchemaSerializer | ||
def initialize(abstractor_abstraction_schema) | ||
@abstractor_abstraction_schema = abstractor_abstraction_schema | ||
end | ||
|
||
def as_json(options = {}) | ||
{ | ||
"predicate" => abstractor_abstraction_schema.predicate, | ||
"display_name" => abstractor_abstraction_schema.display_name, | ||
"abstractor_object_type" => abstractor_abstraction_schema.abstractor_object_type.value, | ||
"preferred_name" => abstractor_abstraction_schema.preferred_name, | ||
"predicate_variants" => abstractor_abstraction_schema.abstractor_abstraction_schema_predicate_variants.map { |abstractor_abstraction_schema_predicate_variant| { 'value' => abstractor_abstraction_schema_predicate_variant.value } }, | ||
"object_values" => abstractor_abstraction_schema.abstractor_object_values.map do |abstractor_object_value| | ||
{ | ||
'value' => abstractor_object_value.value, | ||
'object_value_variants' => abstractor_object_value.abstractor_object_value_variants.map { |abstractor_object_value_variant| { 'value' => abstractor_object_value_variant.value } } | ||
} | ||
end | ||
} | ||
end | ||
|
||
private | ||
|
||
attr_reader :abstractor_abstraction_schema | ||
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
34 changes: 34 additions & 0 deletions
34
spec/requests/abstractor/abstractor_abstraction_schema_controller_spec.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,34 @@ | ||
require 'spec_helper' | ||
require './test/dummy/lib/setup/setup/' | ||
describe Abstractor::AbstractorAbstractionSchemasController, :type => :request do | ||
let(:accept_json) { { "Accept" => "application/json" } } | ||
let(:json_content_type) { { "Content-Type" => "application/json" } } | ||
let(:accept_and_return_json) { accept_json.merge(json_content_type) } | ||
|
||
before(:each) do | ||
Abstractor::Setup.system | ||
end | ||
|
||
describe "GET /abstractor_abstraction_schemas/:id" do | ||
it "returns a requested movie", focus: true do | ||
abstractor_object_type = Abstractor::AbstractorObjectType.where(value: 'list').first | ||
abstractor_abstraction_schema = FactoryGirl.create(:abstractor_abstraction_schema, predicate: 'has_some_property', display_name: 'some_property', abstractor_object_type: abstractor_object_type, preferred_name: 'property') | ||
abstractor_abstraction_schema.abstractor_abstraction_schema_predicate_variants << FactoryGirl.build(:abstractor_abstraction_schema_predicate_variant, value: 'smoperty') | ||
abstractor_abstraction_schema.abstractor_object_values << FactoryGirl.build(:abstractor_object_value, value: 'foo') | ||
FactoryGirl.create(:abstractor_object_value_variant, abstractor_object_value: abstractor_abstraction_schema.abstractor_object_values.first, value: 'boo') | ||
|
||
get "/abstractor_abstraction_schemas/#{abstractor_abstraction_schema.id}", {}, accept_json | ||
|
||
expect(response.status).to be 200 | ||
|
||
body = JSON.parse(response.body) | ||
puts body | ||
expect(body['predicate']).to eq 'has_some_property' | ||
expect(body['display_name']).to eq 'some_property' | ||
expect(body['abstractor_object_type']).to eq 'list' | ||
expect(body['preferred_name']).to eq 'property' | ||
expect(body['predicate_variants']).to eq [{ 'value' => 'smoperty' }] | ||
expect(body['object_values']).to eq [{"value"=>"foo", "object_value_variants"=>[{"value"=>"boo"}]}] | ||
end | ||
end | ||
end |