Skip to content

Commit

Permalink
Merge 896e890 into 7284cff
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Johnson committed Jul 8, 2015
2 parents 7284cff + 896e890 commit f5391e1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/active_triples/rdf_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ def type=(type)
self.update(RDF::Statement.new(rdf_subject, RDF.type, type))
end

##
# Compares self to other for {RDF::Term} equality.
#
# Delegates the check to `other#==` passing it the term version of `self`.
#
# @param other [Object]
#
# @see RDF::Term#==
# @see RDF::Node#==
# @see RDF::URI#==
def ==(other)
other == to_term
end

##
# Looks for labels in various default fields, prioritizing
# configured label fields.
Expand Down
35 changes: 34 additions & 1 deletion spec/active_triples/rdf_source_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
require 'spec_helper'

describe ActiveTriples::RDFSource do
let(:dummy_source) { Class.new { include ActiveTriples::RDFSource } }

let(:source_class) { Class.new { include ActiveTriples::RDFSource } }
let(:uri) { RDF::URI('http://example.org/moomin') }

subject { source_class.new }

describe '#==' do

shared_examples 'Term equality' do
it 'equals itself' do
expect(subject).to eq subject
end

it 'equals its clone' do
expect(subject).to eq source_class.new(subject.rdf_subject)
end

it 'does not equal another term' do
expect(subject).not_to eq RDF::Node.new
end

it 'does not equal another term' do
expect(subject).not_to eq source_class.new
end
end

include_examples 'Term equality'

context 'with a URI' do
include_examples 'Term equality' do
subject { source_class.new(uri) }
end
end
end

describe ".apply_schema" do
let(:dummy_source) { Class.new { include ActiveTriples::RDFSource } }

before do
class MyDataModel < ActiveTriples::Schema
property :test_title, :predicate => RDF::DC.title
Expand Down

0 comments on commit f5391e1

Please sign in to comment.