has_seo_fields 0.0.1 → 0.0.2
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/has_seo_fields/version.rb +1 -1
- data/lib/has_seo_fields.rb +5 -3
- data/spec/lib/has_seo_fields_spec.rb +18 -4
- metadata +3 -3
data/lib/has_seo_fields.rb
CHANGED
@@ -10,22 +10,24 @@ module HasSeoFields
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def has_seo_fields *args
|
13
|
-
const_set "SEO_NAMES", args
|
14
13
|
|
15
|
-
args.
|
14
|
+
args.map! do |field|
|
16
15
|
getter_name = "seo_#{field}"
|
17
16
|
|
18
17
|
define_method getter_name do
|
18
|
+
field.value if (field = seo_fields.find_by_name getter_name)
|
19
19
|
end
|
20
20
|
|
21
21
|
define_method "#{getter_name}=" do |value|
|
22
|
-
if (field = seo_fields.find_by_name
|
22
|
+
if (field = seo_fields.find_by_name getter_name)
|
23
23
|
field.update_attribute :value, value
|
24
24
|
else
|
25
25
|
seo_fields.create :name => getter_name, :value => value
|
26
26
|
end
|
27
27
|
end
|
28
|
+
getter_name
|
28
29
|
end
|
30
|
+
const_set "SEO_NAMES", args
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -9,7 +9,20 @@ describe HasSeoFields do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "sets SEO_NAMES" do
|
12
|
-
subject.class::SEO_NAMES.should eql([
|
12
|
+
subject.class::SEO_NAMES.should eql(['seo_h1_tag', 'seo_title'])
|
13
|
+
end
|
14
|
+
|
15
|
+
context "getters" do
|
16
|
+
|
17
|
+
it "finds existing record by the name" do
|
18
|
+
subject.seo_fields.create :name => 'seo_h1_tag', :value => 'Cool!'
|
19
|
+
subject.seo_h1_tag.should eql('Cool!')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil if nothing founded" do
|
23
|
+
subject.seo_title.should be_nil
|
24
|
+
end
|
25
|
+
|
13
26
|
end
|
14
27
|
|
15
28
|
context "setters" do
|
@@ -18,11 +31,12 @@ describe HasSeoFields do
|
|
18
31
|
subject.should respond_to('seo_h1_tag=', 'seo_title=')
|
19
32
|
end
|
20
33
|
|
21
|
-
describe "seo field with that
|
34
|
+
describe "seo field with name that does not exists" do
|
22
35
|
|
23
|
-
it "
|
36
|
+
it "creates needed seo field with given value" do
|
24
37
|
subject.seo_h1_tag='Cool city'
|
25
|
-
subject.seo_fields.
|
38
|
+
subject.seo_fields.should have(1).item
|
39
|
+
subject.seo_fields.find_by_name('seo_h1_tag').value.should eql('Cool city')
|
26
40
|
end
|
27
41
|
end
|
28
42
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_seo_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Erlikh
|