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

code for party decorator #8

Merged
merged 1 commit into from
Feb 7, 2017
Merged
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
10 changes: 10 additions & 0 deletions lib/parliament/decorators/party.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

module Parliament
module Decorators
module Party
def name
respond_to?(:partyName) ? partyName : ''
end
end
end
end
3 changes: 3 additions & 0 deletions spec/fixtures/no_current_parties.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<http://id.ukpds.org/28a6df70-572f-4063-ab51-ac5457f352bb> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .


11 changes: 11 additions & 0 deletions spec/fixtures/parties_current.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<http://id.ukpds.org/7a048f56-0ddd-48b0-85bd-cf5dd9fa5427> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
<http://id.ukpds.org/7a048f56-0ddd-48b0-85bd-cf5dd9fa5427> <http://id.ukpds.org/schema/partyName> "Labour" .
<http://id.ukpds.org/ab77ae5d-7559-4636-ac25-2a23fd961980> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
<http://id.ukpds.org/ab77ae5d-7559-4636-ac25-2a23fd961980> <http://id.ukpds.org/schema/partyName> "Conservative" .
<http://id.ukpds.org/98f0d50d-d9f7-49e3-a9ad-4f7ddaf08349> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
<http://id.ukpds.org/98f0d50d-d9f7-49e3-a9ad-4f7ddaf08349> <http://id.ukpds.org/schema/partyName> "Independent" .
<http://id.ukpds.org/0aed9061-7b9b-42f1-b3a8-0427460789d8> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
<http://id.ukpds.org/0aed9061-7b9b-42f1-b3a8-0427460789d8> <http://id.ukpds.org/schema/partyName> "Green Party" .
<http://id.ukpds.org/28a6df70-572f-4063-ab51-ac5457f352bb> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
<http://id.ukpds.org/28a6df70-572f-4063-ab51-ac5457f352bb> <http://id.ukpds.org/schema/partyName> "Scottish National Party" .

30 changes: 30 additions & 0 deletions spec/parliament/decorators/party_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative '../../spec_helper'

describe Parliament::Decorators::Party do
let(:data) { StringIO.new(File.read('spec/fixtures/parties_current.nt')) }
let(:empty_name) { StringIO.new(File.read('spec/fixtures/no_current_parties.nt')) }
let(:objects) { Grom::Reader.new(data).objects }
let(:objects_without_name) { Grom::Reader.new(empty_name).objects }
let(:party_node) { objects.first }
let(:objects_without_name_node) { objects_without_name.first }

describe '#name' do
context 'Grom::Node has all the required objects' do
it 'confirms that the type for this Grom::Node object is Party' do
expect(party_node.type).to eq('http://id.ukpds.org/schema/Party')
end

it 'returns the name of the party for the Grom::Node object' do
party_node.extend(Parliament::Decorators::Party)
expect(party_node.name).to eq('Labour')
end
end

context 'Grom::Node does not have have a name' do
it 'confirms that the name for this Grom::Node node does not exist' do
objects_without_name_node.extend(Parliament::Decorators::Party)
expect(objects_without_name_node.name).to eq('')
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'parliament'
require 'webmock/rspec'
require_relative '../lib/parliament/decorators/party'

require 'vcr'

Expand Down