kalimba 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+
3
+ describe Kalimba::Resource do
4
+ before :all do
5
+ class ResourceTestPerson < Human
6
+ type "http://schema.org/ResourceTestPerson"
7
+ base_uri "http://example.org/people"
8
+ end
9
+ end
10
+
11
+ describe "extended class" do
12
+ subject { ResourceTestPerson }
13
+
14
+ it { should respond_to :type }
15
+ it { should respond_to :properties }
16
+
17
+ describe "properties" do
18
+ subject { ResourceTestPerson.properties }
19
+
20
+ it { should be_a Hash }
21
+
22
+ %w(name duties).each do |name|
23
+ it { should include name }
24
+ end
25
+ end
26
+
27
+ describe "instance" do
28
+ let(:person) { ResourceTestPerson.new }
29
+ subject { person }
30
+
31
+ it { should respond_to :name }
32
+ it { should respond_to :name= }
33
+ it { should respond_to :duties }
34
+ it { should respond_to :duties= }
35
+
36
+ it { should respond_to :to_model }
37
+ it { should respond_to :to_key }
38
+ it { should respond_to :to_param }
39
+
40
+ it { should respond_to :attributes }
41
+
42
+ context "created via 'for'" do
43
+ subject { ResourceTestPerson.for "charlie" }
44
+
45
+ it { should be_a ResourceTestPerson }
46
+
47
+ it "should set subject to the given URI" do
48
+ expect(subject.subject).to eql URI("http://example.org/people/#charlie")
49
+ end
50
+ end
51
+
52
+ describe "serialization" do
53
+ describe "to_rdf" do
54
+ subject { person.to_rdf }
55
+
56
+ context "for a new record" do
57
+ let(:person) { ResourceTestPerson.new }
58
+
59
+ it { should be_nil }
60
+ end
61
+
62
+ context "for a persisted record or new record with a subject" do
63
+ let(:person) { ResourceTestPerson.for("alice") }
64
+
65
+ it { should be_a URI }
66
+
67
+ it { should eql person.subject }
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "attributes" do
73
+ subject { person.attributes }
74
+
75
+ it { should be_a Hash }
76
+
77
+ %w(name duties).each do |name|
78
+ it { should include name }
79
+ end
80
+
81
+ context "when the resource is frozen" do
82
+ before { person.freeze }
83
+
84
+ it { should be_frozen }
85
+ end
86
+
87
+ describe "collections" do
88
+ it "should be enumerable" do
89
+ expect(person.duties).to be_a Enumerable
90
+ expect(person.attributes["duties"]).to be_a Enumerable
91
+ end
92
+ end
93
+
94
+ context "when assigned via assign_attributes" do
95
+ before { person.assign_attributes(:duties => %w(eat sleep drink), :name => "Alice") }
96
+
97
+ it "should have accessors return the assigned values" do
98
+ expect(person.name).to eql "Alice"
99
+ expect(person.duties).to eql %w(eat sleep drink)
100
+ end
101
+ end
102
+
103
+ context "when assigned on initialization" do
104
+ let(:person) { ResourceTestPerson.new(:name => "Bob", :duties => ["running"]) }
105
+
106
+ it "should have accessors return the assigned values" do
107
+ expect(person.name).to eql "Bob"
108
+ expect(person.duties).to eql %w(running)
109
+ end
110
+ end
111
+ end
112
+
113
+ context "with changes" do
114
+ before { subject.name = "Bob" }
115
+
116
+ it { should be_changed }
117
+
118
+ it "should have changed attributes marked" do
119
+ expect(person.changes).to include "name"
120
+ end
121
+
122
+ context "after save" do
123
+ before { subject.save }
124
+
125
+ it { should_not be_changed }
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe "validations" do
4
+ before :all do
5
+ class ValidationsTestPerson < Human
6
+ validates_presence_of :name
7
+ end
8
+ end
9
+
10
+ let(:person) { ValidationsTestPerson.create }
11
+
12
+ describe "validates_presence_of" do
13
+ it "should add an error on :name" do
14
+ expect(person).to have(1).errors_on(:name)
15
+ end
16
+
17
+ context "given non-blank :name attribute" do
18
+ before { person.name = "Alan" }
19
+
20
+ it "should have no errors on :name" do
21
+ expect(person).to have(:no).errors_on(:name)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ require "kalimba/persistence/redlander"
2
+ require "kalimba"
3
+
4
+ support_dir = File.join(File.dirname(__FILE__), "support")
5
+ Dir.foreach(support_dir) do |ext|
6
+ require File.join(support_dir, ext) if ext.end_with?(".rb")
7
+ end
8
+
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+
21
+ config.before :all do
22
+ class Human < Kalimba::Resource
23
+ type "http://schema.org/Human"
24
+ base_uri "http://example.org/people"
25
+ property :name, :predicate => "http://xmlns.com/foaf/0.1#name", :datatype => NS::XMLSchema["string"]
26
+ property :rank, :predicate => "http://works.com#rank", :datatype => NS::XMLSchema["integer"]
27
+ has_many :duties, :predicate => "http://works.com#duty", :datatype => NS::XMLSchema["string"]
28
+ end
29
+
30
+ class Engineer < Kalimba::Resource
31
+ type "http://schema.org/Engineer"
32
+ base_uri "http://example.org/people"
33
+ property :rank, :predicate => "http://works.com#rank", :datatype => NS::XMLSchema["integer"]
34
+ property :retired, :predicate => "http://works.com#retired", :datatype => NS::XMLSchema["date"]
35
+ property :boss, :predicate => "http://works.com#boss", :datatype => "http://schema.org/Engineer"
36
+ has_many :duties, :predicate => "http://works.com#duty", :datatype => NS::XMLSchema["string"]
37
+ has_many :coworkers, :predicate => "http://works.com#coworker", :datatype => "http://schema.org/Engineer"
38
+ end
39
+ end
40
+
41
+ config.before do
42
+ Kalimba.repository.statements.delete_all
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ module RSpec
2
+ module Rails
3
+ if defined?(Kalimba)
4
+ module Extensions
5
+ module Kalimba
6
+ # Extension to enhance `should have` on AR Model classes
7
+ #
8
+ # @example
9
+ #
10
+ # ModelClass.should have(:no).records
11
+ # ModelClass.should have(1).record
12
+ # ModelClass.should have(n).records
13
+ def records
14
+ find(:all)
15
+ end
16
+ alias :record :records
17
+ end
18
+
19
+ class ::Kalimba::Resource
20
+ extend RSpec::Rails::Extensions::Kalimba
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ module ::ActiveModel::Validations
28
+ # Extension to enhance `should have` on AR Model instances. Calls
29
+ # model.valid? in order to prepare the object's errors object.
30
+ #
31
+ # You can also use this to specify the content of the error messages.
32
+ #
33
+ # @example
34
+ #
35
+ # model.should have(:no).errors_on(:attribute)
36
+ # model.should have(1).error_on(:attribute)
37
+ # model.should have(n).errors_on(:attribute)
38
+ #
39
+ # model.errors_on(:attribute).should include("can't be blank")
40
+ def errors_on(attribute)
41
+ self.valid?
42
+ [self.errors[attribute]].flatten.compact
43
+ end
44
+ alias :error_on :errors_on
45
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kalimba
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Slava Kravchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.11.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.11.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: kalimba-redlander
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ActiveModel-based framework, which allows the developer to combine RDF
70
+ resources into ActiveRecord-like models.
71
+ email:
72
+ - slava.kravchenko@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - kalimba-redlander.gemspec
83
+ - kalimba.gemspec
84
+ - lib/kalimba.rb
85
+ - lib/kalimba/attribute_assignment.rb
86
+ - lib/kalimba/callbacks.rb
87
+ - lib/kalimba/exceptions.rb
88
+ - lib/kalimba/localized_attributes.rb
89
+ - lib/kalimba/persistence.rb
90
+ - lib/kalimba/railtie.rb
91
+ - lib/kalimba/railties/repository.rake
92
+ - lib/kalimba/reflection.rb
93
+ - lib/kalimba/resource.rb
94
+ - lib/kalimba/validations.rb
95
+ - lib/kalimba/version.rb
96
+ - spec/lib/kalimba/attributes_spec.rb
97
+ - spec/lib/kalimba/callbacks_spec.rb
98
+ - spec/lib/kalimba/persistence_spec.rb
99
+ - spec/lib/kalimba/resource_spec.rb
100
+ - spec/lib/kalimba/validations_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/resource_ext.rb
103
+ homepage: https://github.com/cordawyn/kalimba
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.0.rc.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Kalimba provides ActiveRecord-like capabilities for RDF resources.
126
+ test_files:
127
+ - spec/lib/kalimba/attributes_spec.rb
128
+ - spec/lib/kalimba/callbacks_spec.rb
129
+ - spec/lib/kalimba/persistence_spec.rb
130
+ - spec/lib/kalimba/resource_spec.rb
131
+ - spec/lib/kalimba/validations_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/support/resource_ext.rb