yeti 0.3.5 → 0.3.6
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.
- data/lib/yeti/editor.rb +5 -4
- data/lib/yeti/version.rb +1 -1
- data/spec/yeti/editor_spec.rb +8 -8
- metadata +4 -4
data/lib/yeti/editor.rb
CHANGED
@@ -101,13 +101,13 @@ module Yeti
|
|
101
101
|
def #{name}
|
102
102
|
unless defined? @#{name}
|
103
103
|
opts = self.class.attribute_options[:#{name}]
|
104
|
-
@#{name} =
|
104
|
+
@#{name} = format_output #{from}, opts
|
105
105
|
end
|
106
106
|
@#{name}
|
107
107
|
end
|
108
108
|
def #{name}=(value)
|
109
109
|
opts = self.class.attribute_options[:#{name}]
|
110
|
-
value =
|
110
|
+
value = format_input value, opts
|
111
111
|
return if value==#{name}
|
112
112
|
#{name}_will_change!
|
113
113
|
@#{name} = value
|
@@ -134,11 +134,12 @@ module Yeti
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def format_input(value, attribute_opts)
|
137
|
-
value.
|
137
|
+
value = value.clean.strip if value.respond_to? :clean
|
138
|
+
value
|
138
139
|
end
|
139
140
|
|
140
141
|
def format_output(value, attribute_opts)
|
141
|
-
value
|
142
|
+
value
|
142
143
|
end
|
143
144
|
|
144
145
|
end
|
data/lib/yeti/version.rb
CHANGED
data/spec/yeti/editor_spec.rb
CHANGED
@@ -123,11 +123,11 @@ describe ::Yeti::Editor do
|
|
123
123
|
context "new record" do
|
124
124
|
its(:id){ should be_nil }
|
125
125
|
its(:name){ should be_nil }
|
126
|
-
it "#name=
|
126
|
+
it "#name= don't touch value if it's not a string" do
|
127
127
|
subject.name = ["test"]
|
128
|
-
subject.name.should ==
|
128
|
+
subject.name.should == ["test"]
|
129
129
|
end
|
130
|
-
it "#name= cleans the value of
|
130
|
+
it "#name= cleans the value of harmful content if it's a string" do
|
131
131
|
subject.name = "\tInfected\210\004"
|
132
132
|
subject.name.should == "Infected"
|
133
133
|
end
|
@@ -206,15 +206,15 @@ describe ::Yeti::Editor do
|
|
206
206
|
subject.name.should == "Anthony"
|
207
207
|
end
|
208
208
|
it{ should be_valid }
|
209
|
-
it "
|
210
|
-
subject.stub(:
|
209
|
+
it "output formatting can be customized" do
|
210
|
+
subject.stub(:format_output).with("Anthony", {
|
211
211
|
attribute_name: :name,
|
212
212
|
from: :edited,
|
213
213
|
}).and_return(expected = mock)
|
214
214
|
subject.name.should be expected
|
215
215
|
end
|
216
|
-
it "
|
217
|
-
subject.stub(:
|
216
|
+
it "input formatting can be customized" do
|
217
|
+
subject.stub(:format_input).with("Tony", {
|
218
218
|
attribute_name: :name,
|
219
219
|
from: :edited,
|
220
220
|
}).and_return(expected = mock)
|
@@ -264,7 +264,7 @@ describe ::Yeti::Editor do
|
|
264
264
|
subject.timestamp.should == "2001-01-01"
|
265
265
|
end
|
266
266
|
it "attribute value can come from specified method on another object" do
|
267
|
-
subject.related_id.should ==
|
267
|
+
subject.related_id.should == 2
|
268
268
|
end
|
269
269
|
it "attribute raises if value cannot be found in source" do
|
270
270
|
lambda{ subject.invalid }.should raise_error NoMethodError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
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: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: -227008563247670147
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: -227008563247670147
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
131
|
rubygems_version: 1.8.23
|