poro 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Inflector' do
4
+
5
+ before(:all) do
6
+ @inflector = Poro::Util::Inflector
7
+ end
8
+
9
+ it 'should camelize' do
10
+ @inflector.camelize('some_underscored_thing').should == "SomeUnderscoredThing"
11
+ end
12
+
13
+ it 'should underscore' do
14
+ @inflector.underscore('SomeCamelizedThing').should == "some_camelized_thing"
15
+ end
16
+
17
+ it 'should pluralize' do
18
+ @inflector.pluralize('person').should == 'people'
19
+ end
20
+
21
+ it 'should singularize' do
22
+ @inflector.singularize('people').should == 'person'
23
+ end
24
+
25
+ it 'should not include itself into string' do
26
+ "Foo".should_not respond_to(:underscore)
27
+ "Foo".should_not respond_to(:camelize)
28
+ "Foo".should_not respond_to(:pluralize)
29
+ "Foo".should_not respond_to(:singularize)
30
+ end
31
+
32
+ end
@@ -0,0 +1,75 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "Modelify" do
4
+
5
+ before(:each) do
6
+ class ModelifyTestContext
7
+ def method_missing(method, *args, &block)
8
+ return "#{method} called"
9
+ end
10
+
11
+ def primary_key
12
+ return :id
13
+ end
14
+ end
15
+
16
+ @standin_context = ModelifyTestContext.new
17
+
18
+ Poro::ContextManager.instance = Poro::ContextManager.new do |klass|
19
+ @standin_context
20
+ end
21
+
22
+ class ModelifyFoo
23
+ include Poro::Modelify
24
+ end
25
+
26
+ @obj_klass = ModelifyFoo
27
+ @obj = ModelifyFoo.new
28
+ end
29
+
30
+ it 'should include class methods' do
31
+ @obj_klass.should respond_to(:fetch)
32
+ end
33
+
34
+ it 'should include instance methods' do
35
+ @obj.should respond_to(:save)
36
+ end
37
+
38
+ it 'should reference the context' do
39
+ @obj_klass.context.should == @standin_context
40
+ @obj.context.should == @standin_context
41
+ end
42
+
43
+ it 'should pass-through find' do
44
+ @obj_klass.fetch(3).should == "fetch called"
45
+ end
46
+
47
+ it 'should pass-through save' do
48
+ @obj.save.should == "save called"
49
+ end
50
+
51
+ it 'should pass-through remove' do
52
+ @obj.remove.should == "remove called"
53
+ end
54
+
55
+ it 'should add id methods by default' do
56
+ obj = @obj.dup
57
+
58
+ obj.should respond_to(:id)
59
+ obj.should respond_to(:id=)
60
+
61
+ obj.id.should be_nil
62
+ new_id = rand(10000)
63
+ obj.id = new_id
64
+ obj.id.should == new_id
65
+ end
66
+
67
+ it 'should respond_to find' do
68
+ @obj_klass.should respond_to(:find)
69
+ end
70
+
71
+ it 'should respond_to data_store_find' do
72
+ @obj_klass.should respond_to(:data_storefind)
73
+ end
74
+
75
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require 'drb'
3
+
4
+ describe "Poro::Util::ModuleFinder" do
5
+
6
+ before(:all) do
7
+ @module_finder = Poro::Util::ModuleFinder
8
+ end
9
+
10
+ it 'should find simple classes' do
11
+ @module_finder.find(String).should == String
12
+ @module_finder.find(DRb::DRbError).should == DRb::DRbError
13
+ end
14
+
15
+ it 'should find a class from a string' do
16
+ @module_finder.find("String").should == String
17
+ @module_finder.find("DRb::DRbError").should == DRb::DRbError
18
+ end
19
+
20
+ it 'should find an absolute class from a string' do
21
+ @module_finder.find("::String").should == ::String
22
+ @module_finder.find("::DRb::DRbError").should == ::DRb::DRbError
23
+ end
24
+
25
+ it 'should find a class inside a root path' do
26
+ @module_finder.find("DRbError", 'DRb').should == ::DRb::DRbError
27
+ @module_finder.find("DRbError", DRb).should == ::DRb::DRbError
28
+ end
29
+
30
+ it 'should return a toplevel class like ruby if no inside one is found' do
31
+ @module_finder.find("String", 'DRb').should == String
32
+ end
33
+
34
+ it 'should error if no class found inside when strict.' do
35
+ lambda {@module_finder.find("String", 'DRb', true)}.should raise_error(NameError)
36
+ end
37
+
38
+ it 'should handle an empty string' do
39
+ lambda {@module_finder.find('')}.should raise_error(NameError)
40
+ lambda {@module_finder.find(' ')}.should raise_error(NameError)
41
+ lambda {@module_finder.find("\t")}.should raise_error(NameError)
42
+ end
43
+
44
+ it 'should handle nil' do
45
+ lambda {@module_finder.find(nil)}.should raise_error(NameError)
46
+ end
47
+
48
+ it 'should not run embedded code' do
49
+ lambda {@module_finder.find('Object.new')}.should raise_error(NameError)
50
+ lambda {@module_finder.find('raise RuntimeError')}.should raise_error(NameError)
51
+ end
52
+
53
+ it 'should handle garbage' do
54
+ lambda {@module_finder.find('::::;cougar;#asdkjh*&(^&%^&')}.should raise_error(NameError)
55
+ end
56
+
57
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'MongoContext' do
4
+
5
+ before(:each) do
6
+ begin
7
+ require 'mongo'
8
+ rescue LoadError => e
9
+ pending "Skip due to missing gem: #{e.class}: #{e.message}"
10
+ end
11
+ end
12
+
13
+ it "should have tests" do
14
+ pending "No tests written yet."
15
+ end
16
+
17
+ describe 'Decoding' do
18
+
19
+ it 'should not need class name on root object' do
20
+ pending
21
+ end
22
+
23
+ end
24
+
25
+ describe 'Encoding' do
26
+ end
27
+
28
+ end
@@ -0,0 +1,55 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "SingleStore" do
4
+
5
+ before(:all) do
6
+ @klass_one = Class.new(Object)
7
+ end
8
+
9
+
10
+ it 'should find factories by multiple name formats' do
11
+ @klass = Poro::ContextFactories::SingleStore::HashFactory
12
+
13
+ [:hash, 'hash', 'HashFactory', 'HashContext', 'hash_context', :hash_context, @klass].each do |ident|
14
+ factory = Poro::ContextFactories::SingleStore.instantiate(ident)
15
+ factory.should be_kind_of(@klass), "Could not instantiate for #{ident.inspect}"
16
+ end
17
+ end
18
+
19
+ it 'should supply the block' do
20
+ block_called = false
21
+ block_context = nil
22
+ Poro::Context.factory = Poro::ContextFactories::SingleStore.instantiate(:hash) do |klass, context|
23
+ klass.should == @klass_one
24
+ context.should be_kind_of(Poro::Context)
25
+ block_context = context
26
+ block_called = true
27
+ end
28
+
29
+ @klass_one.send(:include, Poro::Persistify)
30
+ returned_context = Poro::Context.fetch(@klass_one)
31
+ block_called.should be_true
32
+ returned_context.should == block_context
33
+ end
34
+
35
+ describe 'HashFactory' do
36
+
37
+ it 'should supply a block with the klass and context' do
38
+ block_called = false
39
+ block_context = nil
40
+ Poro::Context.factory = Poro::ContextFactories::SingleStore::HashFactory.new do |klass, context|
41
+ klass.should == @klass_one
42
+ context.should be_kind_of(Poro::Context)
43
+ block_context = context
44
+ block_called = true
45
+ end
46
+
47
+ @klass_one.send(:include, Poro::Persistify)
48
+ returned_context = Poro::Context.fetch(@klass_one)
49
+ block_called.should be_true
50
+ returned_context.should == block_context
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,4 @@
1
+ # Add the lib dir to the load path.
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ # Require the main require file.
4
+ require File.basename(File.expand_path(File.join(File.dirname(__FILE__),'..')))
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poro
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jeff Reinecke
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-18 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " Plain Ol' Ruby Objects (PORO) is a thing and lightweight persistence engine\n that can use nearly any persistence store. Its purpose is to allow you to\n easily add a persistence store to your existing objects in an application.\n"
22
+ email: jeff@paploo.net
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - README.rdoc
31
+ - LICENSE.txt
32
+ - Rakefile
33
+ - lib/poro/context.rb
34
+ - lib/poro/context_factories/README.txt
35
+ - lib/poro/context_factories/single_store/hash_factory.rb
36
+ - lib/poro/context_factories/single_store/mongo_factory.rb
37
+ - lib/poro/context_factories/single_store.rb
38
+ - lib/poro/context_factories.rb
39
+ - lib/poro/context_factory.rb
40
+ - lib/poro/contexts/hash_context.rb
41
+ - lib/poro/contexts/mongo_context.rb
42
+ - lib/poro/contexts.rb
43
+ - lib/poro/modelify.rb
44
+ - lib/poro/persistify.rb
45
+ - lib/poro/util/inflector/inflections.rb
46
+ - lib/poro/util/inflector/methods.rb
47
+ - lib/poro/util/inflector.rb
48
+ - lib/poro/util/module_finder.rb
49
+ - lib/poro/util.rb
50
+ - lib/poro.rb
51
+ - spec/context_factory_spec.rb
52
+ - spec/context_spec.rb
53
+ - spec/hash_context_spec.rb
54
+ - spec/inflector_spec.rb
55
+ - spec/modelfy.rb
56
+ - spec/module_finder_spec.rb
57
+ - spec/mongo_context_spec.rb
58
+ - spec/single_store_spec.rb
59
+ - spec/spec_helper.rb
60
+ has_rdoc: true
61
+ homepage: http://www.github.com/paploo/poro
62
+ licenses:
63
+ - LICENSE
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 1
76
+ - 9
77
+ - 2
78
+ version: 1.9.2
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A lightweight thin persistence engine that can utilize many different persistence engines.
94
+ test_files: []
95
+