yaml_record 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yaml_record/base.rb +11 -0
- data/lib/yaml_record/version.rb +1 -1
- data/test/base_test.rb +38 -32
- metadata +7 -5
data/lib/yaml_record/base.rb
CHANGED
@@ -196,6 +196,17 @@ module YamlRecord
|
|
196
196
|
self
|
197
197
|
end
|
198
198
|
|
199
|
+
# Returns the instance of a record as a parameter
|
200
|
+
# By default return an id
|
201
|
+
#
|
202
|
+
# === Example:
|
203
|
+
#
|
204
|
+
# @post.to_param => <id>
|
205
|
+
#
|
206
|
+
def to_param
|
207
|
+
self.id
|
208
|
+
end
|
209
|
+
|
199
210
|
# Reload YamlRecord instance attributes from file
|
200
211
|
#
|
201
212
|
# === Example:
|
data/lib/yaml_record/version.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -6,68 +6,68 @@ class YamlObject < YamlRecord::Base
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class BaseTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
9
|
+
|
10
|
+
def setup
|
11
11
|
@obj_title = "Simple Title"
|
12
12
|
@obj_id = "1234"
|
13
13
|
@obj2_id = "5678"
|
14
14
|
@obj2_title = "Simple Title 2"
|
15
|
-
|
15
|
+
|
16
16
|
@attr = {
|
17
17
|
:child_ids => [@obj_id],
|
18
18
|
:title => @obj_title,
|
19
19
|
:body => "Body!!"
|
20
20
|
}
|
21
|
-
|
21
|
+
|
22
22
|
@attr2 = {
|
23
23
|
:child_ids => [@obj2_id],
|
24
24
|
:title => @obj2_title,
|
25
25
|
:body => "Body!!"
|
26
26
|
}
|
27
|
-
|
27
|
+
|
28
28
|
clean_yaml_record(YamlObject)
|
29
29
|
@fs = YamlObject.create(@attr)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
context "for instance methods" do
|
33
|
-
|
33
|
+
|
34
34
|
context "for [] method" do
|
35
35
|
should("get attribute with [attribute]"){ assert_equal @fs.title, @fs[:title] }
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
context "for []= method" do
|
39
39
|
setup do
|
40
40
|
@fs[:title] = "Toto"
|
41
41
|
end
|
42
42
|
should("set attribute with [attribute]="){ assert_equal @fs[:title], "Toto" }
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
context "for save method" do
|
46
46
|
setup do
|
47
47
|
@fs2 = YamlObject.new(@attr)
|
48
48
|
@fs2.save
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
should("save on yaml file"){ assert_equal YamlObject.last.attributes.diff(@attr), {:id => @fs2.reload.id } }
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
context "for update_attributes method" do
|
55
|
-
setup do
|
55
|
+
setup do
|
56
56
|
@fs.update_attributes(:title => "Toto", :body => "http://somewhereelse.com")
|
57
57
|
@fs.reload
|
58
58
|
end
|
59
59
|
should("update title") { assert_equal @fs.title, "Toto" }
|
60
60
|
should("update body") { assert_equal @fs.body, "http://somewhereelse.com" }
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
context "for column_names method" do
|
64
64
|
should("return an array with attributes names") { assert_equal @fs.column_names.sort!, YamlObject.properties.map { |p| p.to_s }.sort! }
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
context "for persisted_attributes method" do
|
68
68
|
should("return persisted attributes") { assert_equal [:title, :body, :child_ids, :id ].sort_by {|sym| sym.to_s}, @fs.persisted_attributes.keys.sort_by {|sym| sym.to_s} }
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
context "for new_record? method" do
|
72
72
|
setup do
|
73
73
|
@fs3 = YamlObject.new
|
@@ -75,7 +75,7 @@ class BaseTest < Test::Unit::TestCase
|
|
75
75
|
should("be a new record") { assert @fs3.new_record? }
|
76
76
|
should("not be a new record") { assert_false @fs.new_record? }
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
context "for destroyed? method" do
|
80
80
|
setup do
|
81
81
|
@fs4 = YamlObject.create(@attr)
|
@@ -84,15 +84,15 @@ class BaseTest < Test::Unit::TestCase
|
|
84
84
|
should("be a destoyed") { assert @fs4.destroyed? }
|
85
85
|
should("not be destroyed") { assert_false @fs.destroyed? }
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
context "for destroy method" do
|
89
|
-
setup do
|
89
|
+
setup do
|
90
90
|
@fs5 = YamlObject.create(@attr)
|
91
91
|
@fs5.destroy
|
92
92
|
end
|
93
93
|
should("not find @fs5"){ assert_nil YamlObject.find(@fs5.id) }
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
context "for reload method" do
|
97
97
|
setup do
|
98
98
|
@fs.title = "Foo"
|
@@ -100,16 +100,22 @@ class BaseTest < Test::Unit::TestCase
|
|
100
100
|
should("equal to Foo"){ assert_equal @fs.title, "Foo" }
|
101
101
|
should("equal to correct title"){ assert_equal @fs.reload.title, @obj_title }
|
102
102
|
end
|
103
|
+
|
104
|
+
context "for to_param method" do
|
105
|
+
setup { @fs.id = "a1b2c3" }
|
106
|
+
|
107
|
+
should("return id of record") { assert_equal(@fs.to_param, @fs.id) }
|
108
|
+
end
|
103
109
|
end
|
104
|
-
|
110
|
+
|
105
111
|
context "for class methods" do
|
106
112
|
context "for self.find_by_attribute method" do
|
107
|
-
setup do
|
113
|
+
setup do
|
108
114
|
@fs_found = YamlObject.find_by_attribute(:title, @obj_title)
|
109
115
|
end
|
110
116
|
should("be same object as @fs"){ assert_equal @fs_found, YamlObject.find(@fs.id) }
|
111
117
|
end
|
112
|
-
|
118
|
+
|
113
119
|
context "for self.find_by_id method" do
|
114
120
|
setup do
|
115
121
|
@fs_found = YamlObject.find_by_id(@fs.id)
|
@@ -118,9 +124,9 @@ class BaseTest < Test::Unit::TestCase
|
|
118
124
|
should("be same object as @fs"){ assert_equal @fs.attributes, @fs_found.attributes }
|
119
125
|
should("be same object as @fs bis"){ assert_equal @fs.attributes, @fs_found2.attributes }
|
120
126
|
end
|
121
|
-
|
127
|
+
|
122
128
|
context "for self.all method" do
|
123
|
-
setup do
|
129
|
+
setup do
|
124
130
|
clean_yaml_record(YamlObject)
|
125
131
|
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
126
132
|
end
|
@@ -128,29 +134,29 @@ class BaseTest < Test::Unit::TestCase
|
|
128
134
|
should("return as first item @fs"){ assert_equal YamlObject.all.first.attributes, @fs.attributes }
|
129
135
|
should("return as last item @fs2"){ assert_equal YamlObject.all.last.attributes, @fs2.attributes }
|
130
136
|
end
|
131
|
-
|
137
|
+
|
132
138
|
context "for self.first method" do
|
133
139
|
setup do
|
134
140
|
clean_yaml_record(YamlObject)
|
135
141
|
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
136
142
|
end
|
137
|
-
|
143
|
+
|
138
144
|
should("return @fs as the first item"){ assert_equal YamlObject.first.attributes, @fs.attributes }
|
139
145
|
should("return @fs"){ assert_equal YamlObject.first(2).first.attributes, @fs.attributes }
|
140
146
|
should("return @fs2"){ assert_equal YamlObject.first(2).last.attributes, @fs2.attributes }
|
141
147
|
end
|
142
|
-
|
148
|
+
|
143
149
|
context "for self.last method" do
|
144
150
|
setup do
|
145
151
|
clean_yaml_record(YamlObject)
|
146
152
|
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
147
153
|
end
|
148
|
-
|
154
|
+
|
149
155
|
should("return @fs as the first item"){ assert_equal YamlObject.last.attributes, @fs2.attributes }
|
150
156
|
should("return @fs"){ assert_equal YamlObject.last(2).first.attributes, @fs.attributes }
|
151
157
|
should("return @fs2"){ assert_equal YamlObject.last(2).last.attributes, @fs2.attributes }
|
152
158
|
end
|
153
|
-
|
159
|
+
|
154
160
|
context "for self.write_contents method" do
|
155
161
|
setup do
|
156
162
|
clean_yaml_record(YamlObject)
|
@@ -159,7 +165,7 @@ class BaseTest < Test::Unit::TestCase
|
|
159
165
|
end
|
160
166
|
should("write in yaml file"){ assert_equal YAML.load_file(YamlObject.source), [ @attr, @attr2 ] }
|
161
167
|
end
|
162
|
-
|
168
|
+
|
163
169
|
context "for self.create method" do
|
164
170
|
setup do
|
165
171
|
clean_yaml_record(YamlObject)
|
@@ -170,7 +176,7 @@ class BaseTest < Test::Unit::TestCase
|
|
170
176
|
should("set its is_created to true"){ assert @fs.is_created }
|
171
177
|
should("set @fs_not_created is_created field to false"){ assert_false @fs_not_created.is_created }
|
172
178
|
end
|
173
|
-
|
179
|
+
|
174
180
|
context "for set_id!" do
|
175
181
|
setup do
|
176
182
|
@fs_no_id = YamlObject.new(@attr)
|
@@ -183,5 +189,5 @@ class BaseTest < Test::Unit::TestCase
|
|
183
189
|
should("keep the same id"){ assert_equal @fs_with_id.id, @id }
|
184
190
|
end
|
185
191
|
end
|
186
|
-
|
192
|
+
|
187
193
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nico Taing
|
@@ -16,7 +16,8 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-15 00:00:00 -07:00
|
20
|
+
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: activesupport
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- test/base_test.rb
|
86
87
|
- test/test_helper.rb
|
87
88
|
- yaml_record.gemspec
|
89
|
+
has_rdoc: true
|
88
90
|
homepage: https://github.com/nico-taing/yaml_record
|
89
91
|
licenses: []
|
90
92
|
|
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
116
|
requirements: []
|
115
117
|
|
116
118
|
rubyforge_project: yaml_record
|
117
|
-
rubygems_version: 1.
|
119
|
+
rubygems_version: 1.6.2
|
118
120
|
signing_key:
|
119
121
|
specification_version: 3
|
120
122
|
summary: YAML file persistence engine
|