This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
forked from ruby-rdf/spira
/
dirty_spec.rb
92 lines (72 loc) · 2.88 KB
/
dirty_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "spec_helper"
describe Spira do
before :all do
class ::DirtyTest < Spira::Base
property :name, :predicate => RDFS.label
property :age, :predicate => FOAF.age, :type => Integer
has_many :items, :predicate => RDFS.seeAlso
end
end
before :each do
@repo = RDF::Repository.new
@uri = RDF::URI("http://example.org/example/people/alice")
@repo << RDF::Statement.new(@uri, RDF::RDFS.label, "Alice")
@repo << RDF::Statement.new(@uri, RDF::FOAF.age, 15)
@repo << RDF::Statement.new(@uri, RDF::RDFS.seeAlso, "A Literal")
@repo << RDF::Statement.new(@uri, RDF::RDFS.seeAlso, "Another Literal")
Spira.add_repository!(:default, @repo)
end
context "when tracking dirty attributes" do
before :each do
@test = DirtyTest.for(@uri)
end
it "should not mark the projetion as dirty initially" do
@test.should_not be_changed
end
context "that are properties" do
it "should not mark attributes as dirty when loading" do
@test.changed_attributes.should_not include("name")
@test.changed_attributes.should_not include("age")
end
it "should mark the projection as dirty if an attribute is dirty" do
@test.name = "Steve"
@test.should be_changed
end
it "should mark attributes as dirty when changed" do
@test.name = "Steve"
@test.changed_attributes.should include("name")
@test.changed_attributes.should_not include("age")
end
it "should mark attributes as dirty when providing them as arguments" do
test = DirtyTest.for(@uri, :name => "Steve")
@test.changed_attributes.should_not include("name")
@test.changed_attributes.should_not include("age")
end
end
context "that are lists" do
it "should not mark attributes as dirty when loading" do
@test.changed_attributes.should_not include("items")
end
it "should mark the projection as dirty if an attribute is dirty" do
@test.items = ["Steve"]
@test.changed_attributes.should include("items")
end
it "should mark attributes as dirty when changed" do
@test.items = ["Steve"]
@test.changed_attributes.should include("items")
@test.changed_attributes.should_not include("age")
end
it "should not mark attributes as dirty when providing them as arguments" do
test = DirtyTest.for(@uri, :items => ["Steve"])
@test.changed_attributes.should_not include("items")
@test.changed_attributes.should_not include("age")
end
it "should mark attributes as dirty when updated" do
# TODO: a fix is pending for this, read comments on #persist! method
pending "ActiveModel::Dirty cannot track that - read its docs"
# @test.items << "Steve"
# @test.changed_attributes.should include(:items)
end
end
end
end