Skip to content

Commit

Permalink
Merge pull request #1 from ActiveTriples/setup_badges
Browse files Browse the repository at this point in the history
Setup badges; Add more testing coverage
  • Loading branch information
elrayle committed Jan 9, 2015
2 parents 6145856 + ffa571c commit db884e3
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 101 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
28 changes: 24 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
.bundle/
log/*.log
pkg/
Gemfile.lock
tmp/*
.sass-cache
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.bundle
*.so
*.o
*.a
mkmf.log
.idea
.ruby-gemset
.ruby-version
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ source "https://rubygems.org"

gemspec

# GETTING FROM GEMFILE UNTIL ActiveTriples master CODE IS RELEASED (>0.4.0), THEN MOVE THIS BACK TO *.gemspec FILE
# Use active-triple for handling of triple persistence
gem 'active-triples', :git => '[email protected]:ActiveTriples/ActiveTriples.git', :branch => 'master'

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ActiveTriples::LocalName

[![Build Status](https://travis-ci.org/ActiveTriples/active_triples-local_name.png?branch=master)](https://travis-ci.org/ActiveTriples/active_triples-local_name)
[![Coverage Status](https://coveralls.io/repos/ActiveTriples/active_triples-local_name/badge.png?branch=master)](https://coveralls.io/r/ActiveTriples/active_triples-local_name?branch=master)
[![Gem Version](https://badge.fury.io/rb/active_triples-local_name.svg)](http://badge.fury.io/rb/active_triples-local_name)

Provides utilities for working with local names under the [ActiveTriples](https:/ActiveTriples/ActiveTriples)
framework. Includes a default implementation of a local name minter.
Expand Down
4 changes: 2 additions & 2 deletions active_triples-local_name.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Gem::Specification.new do |s|
s.license = "APACHE2"
s.required_ruby_version = '>= 1.9.3'

# GETTING FROM GEMFILE UNTIL persistent check CODE IS RELEASED
# s.add_dependency('active-triples', '~> 0.4')
s.add_dependency('active-triples', '~> 0.5')

s.add_dependency('deprecation', '~> 0.1')
s.add_dependency('activesupport', '>= 3.0.0')

s.add_development_dependency('rdoc')
s.add_development_dependency('rspec')
s.add_development_dependency('coveralls')
s.add_development_dependency('guard-rspec')

s.files = `git ls-files`.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion lib/active_triples/local_name/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveTriples
module LocalName
VERSION = "0.1.0"
VERSION = "0.5.0"
end
end
121 changes: 112 additions & 9 deletions spec/active_triples/local_name/minter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,55 @@ def self.timeHashMinter3_method( *args )
ActiveTriples::Repositories.clear_repositories!
end

context "when class doesn't have base_uri defined" do
it "should raise an Exception" do
expect{ ActiveTriples::LocalName::Minter.generate_local_name(DummyResource) }.to raise_error(RuntimeError, 'Requires base_uri to be defined in for_class.')
context "when one or more arguments are invalid" do
# def self.generate_local_name(for_class, max_tries=10, *minter_args, &minter_block)

context "and all arguments are missing" do
it "should raise error" do
# NOTE: ruby < 2 puts out (0 for 1); ruby >= 2 puts out (0 for 1+)
expect{ ActiveTriples::LocalName::Minter.generate_local_name() }.
to raise_error(ArgumentError, /wrong number of arguments \(0 for 1\+?\)/)
end
end

context "and max_tries is negative" do
it "should raise error" do
expect{ ActiveTriples::LocalName::Minter.generate_local_name(DummyResource,-1) }.
to raise_error(ArgumentError, 'Argument max_tries must be >= 1 if passed in')
end
end

context "and class doesn't inherit from ActiveTriples::Resource" do
before do
class DummyNonResource
end
end
after do
Object.send(:remove_const, "DummyNonResource") if Object
end

it "should raise error" do
expect{ ActiveTriples::LocalName::Minter.generate_local_name(DummyNonResource) }.
to raise_error(ArgumentError, 'Argument for_class must inherit from ActiveTriples::Resource')
end
end


context "and class doesn't have base_uri defined" do
it "should raise error" do
expect{ ActiveTriples::LocalName::Minter.generate_local_name(DummyResource) }.
to raise_error(RuntimeError, 'Requires base_uri to be defined in for_class.')
end
end

## TODO: Can't see how to test this. The test complains if I pass anything other than a Proc instead of complaining that the passing in thing isn't callable.
# context "block isn't callable" do
# it "should raise error" do
# x = "foo"
# expect{ ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,{:prefix => 'a'},&x) }.
# to raise_error(ArgumentError, 'Invalid minter_block.')
# end
# end
end

context "when all IDs available" do
Expand All @@ -93,7 +138,7 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI)
expect(id).to be_kind_of String
expect(id.length).to eq 36
id.should match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

Expand Down Expand Up @@ -291,7 +336,7 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,{:prefix=>"s"})
expect(id).to be_kind_of String
expect(id.length).to eq 37
id.should match /s[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /s[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

Expand All @@ -300,7 +345,7 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,1)
expect(id).to be_kind_of String
expect(id.length).to eq 36
id.should match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

Expand All @@ -309,7 +354,7 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,{:prefix=>1.5})
expect(id).to be_kind_of String
expect(id.length).to eq 36
id.should match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

Expand All @@ -318,7 +363,7 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,{:prefix=>{"a"=>"b"}})
expect(id).to be_kind_of String
expect(id.length).to eq 36
id.should match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

Expand All @@ -327,10 +372,68 @@ def self.timeHashMinter3_method( *args )
id = ActiveTriples::LocalName::Minter.generate_local_name(DummyResourceWithBaseURI,10,{:prefix=>[1,2,3]})
expect(id).to be_kind_of String
expect(id.length).to eq 36
id.should match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end
end

end

describe "default_minter" do
context "when options are empty" do
it "creates a uuid" do
id = ActiveTriples::LocalName::Minter.default_minter
expect(id).to be_kind_of String
expect(id.length).to eq 36
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

context "when options is passed a prefix" do
context "and prefix is string" do
it "should generate a prefixed ID" do
id = ActiveTriples::LocalName::Minter.default_minter({:prefix=>"s"})
expect(id).to be_kind_of String
expect(id.length).to eq 37
expect(id).to match /s[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

context "and prefix is integer" do
it "should generate ID ignoring prefix" do
id = ActiveTriples::LocalName::Minter.default_minter({:prefix=>1})
expect(id).to be_kind_of String
expect(id.length).to eq 36
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

context "and prefix is float" do
it "should generate ID ignoring prefix" do
id = ActiveTriples::LocalName::Minter.default_minter({:prefix=>1.5})
expect(id).to be_kind_of String
expect(id.length).to eq 36
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

context "and prefix is hash" do
it "should generate ID ignoring prefix" do
id = ActiveTriples::LocalName::Minter.default_minter({:prefix=>{"a"=>"b"}})
expect(id).to be_kind_of String
expect(id.length).to eq 36
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end

context "and prefix is array" do
it "should generate ID ignoring prefix" do
id = ActiveTriples::LocalName::Minter.default_minter({:prefix=>[1,2,3]})
expect(id).to be_kind_of String
expect(id.length).to eq 36
expect(id).to match /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
end
end
end
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'coveralls'
Coveralls.wear!

require 'bundler/setup'
Bundler.setup

Expand Down
81 changes: 0 additions & 81 deletions spec/support/active_model_lint.rb

This file was deleted.

0 comments on commit db884e3

Please sign in to comment.