common_repository_model 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,3 +7,5 @@ Rake::TestTask.new do |t|
7
7
  t.test_files = FileList['spec/**/*_spec.rb']
8
8
  t.verbose = true
9
9
  end
10
+
11
+ task :default => :test
@@ -21,7 +21,16 @@ module CommonRepositoryModel
21
21
  find({name_s: name}).first
22
22
  end
23
23
 
24
+ def self.find_by_name!(name)
25
+ find({name_s: name.to_s}).first ||
26
+ raise(
27
+ CommonRepositoryModel::ObjectNotFoundError.new(
28
+ "#{self.class} with name: #{name.to_s} not found"
29
+ )
30
+ )
31
+ end
32
+
24
33
  # We shouldn't be calling these
25
34
  protected :save, :save!
26
35
  end
27
- end
36
+ end
@@ -1,5 +1,8 @@
1
1
  require 'active_fedora'
2
2
  module CommonRepositoryModel
3
+ class ObjectNotFoundError < ActiveFedora::ObjectNotFoundError
4
+ end
5
+
3
6
  class PersistenceBase < ActiveFedora::Base
4
7
  end
5
8
  end
@@ -1,3 +1,3 @@
1
1
  module CommonRepositoryModel
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,10 +3,6 @@ require 'common_repository_model/area'
3
3
  require 'common_repository_model/collection'
4
4
 
5
5
  describe CommonRepositoryModel::Area do
6
- after(:each) do
7
- subject.delete if subject.persisted?
8
- end
9
-
10
6
  describe 'without persisting' do
11
7
  subject { FactoryGirl.build(:area, name: name) }
12
8
  let(:name) { 'My Area Name'}
@@ -34,21 +30,28 @@ describe CommonRepositoryModel::Area do
34
30
  end
35
31
 
36
32
  describe 'integration (with persistence)' do
37
- subject { FactoryGirl.create(:area) }
38
33
  let(:collection) { FactoryGirl.build(:collection, area: nil) }
39
- it 'should find by name' do
40
- CommonRepositoryModel::Area.find_by_name(subject.name).must_equal subject
41
- CommonRepositoryModel::Area.
42
- find_by_name("#{subject.name}-tmp").must_equal nil
34
+ it 'should .find_by_name and .find_by_name!' do
35
+ with_persisted_area do |area|
36
+ CommonRepositoryModel::Area.find_by_name(area.name).must_equal area
37
+ CommonRepositoryModel::Area.
38
+ find_by_name("#{area.name}-tmp").must_equal nil
39
+
40
+ CommonRepositoryModel::Area.find_by_name!(area.name).must_equal area
41
+ lambda {
42
+ CommonRepositoryModel::Area.find_by_name!("#{area.name}-tmp")
43
+ }.must_raise(CommonRepositoryModel::ObjectNotFoundError)
44
+ end
43
45
  end
44
46
  it 'should save' do
45
- # Before we can add a collection, the containing object
46
- # must be saved
47
- subject.collections << collection
48
- subject.send(:save).must_equal true
49
- new_subject = subject.class.find(subject.pid)
50
-
51
- new_subject.collections.size.must_equal 1
47
+ with_persisted_area do |area|
48
+ # Before we can add a collection, the containing object
49
+ # must be saved
50
+ area.collections << collection
51
+ area.send(:save).must_equal true
52
+ new_area = area.class.find(area.pid)
53
+ new_area.collections.size.must_equal 1
54
+ end
52
55
  end
53
56
  end
54
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: common_repository_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport