middleman-dato 0.0.1.rc4 → 0.0.1.rc5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,14 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module Dato::MetaTags
4
4
  RSpec.describe OgLocale do
5
- subject(:meta_tag) { described_class.new(builder, space, record) }
5
+ subject(:meta_tag) { described_class.new(builder, base_url, space, record) }
6
6
  let(:builder) { MockBuilder.new }
7
+ let(:base_url) { nil }
7
8
  let(:space) { nil }
8
9
  let(:record) { nil }
9
10
 
10
- describe '.value' do
11
+ describe ".value" do
11
12
  it "returns the current locale" do
12
13
  I18n.with_locale(:it) do
13
14
  expect(meta_tag.value).to eq "it_IT"
@@ -0,0 +1,104 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Dato::Record do
4
+ subject(:record) { described_class.new(attributes, content_type) }
5
+ let(:attributes) { {} }
6
+ let(:content_type) { { fields: {} } }
7
+
8
+ it "gets attributes and content type as constructor parameters" do
9
+ record
10
+ end
11
+
12
+ describe "#singleton?" do
13
+ context "if the record is a singleton" do
14
+ let(:content_type) { { fields: {}, singleton: true } }
15
+
16
+ it "returns true" do
17
+ expect(record.singleton?).to eq(true)
18
+ end
19
+ end
20
+
21
+ context "else" do
22
+ let(:content_type) { { fields: {}, singleton: false } }
23
+
24
+ it "returns false" do
25
+ expect(record.singleton?).to eq(false)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#respond_to?" do
31
+ let(:attributes) { { foo: "bar" } }
32
+
33
+ context "if the record contains the requested field" do
34
+ it "returns true" do
35
+ expect(record.respond_to?(:foo)).to eq(true)
36
+ end
37
+ end
38
+
39
+ context "else" do
40
+ it "returns true" do
41
+ expect(record.respond_to?(:bar)).to eq(false)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#id" do
47
+ let(:attributes) { { id: 123 } }
48
+
49
+ it "returns the id of the record" do
50
+ expect(record.id).to eq(123)
51
+ end
52
+ end
53
+
54
+ describe "#updated_at" do
55
+ let(:attributes) { { updated_at: "2015-06-09T12:47" } }
56
+
57
+ it "parses the field and returns a Time object" do
58
+ expect(record.updated_at).to eq(Time.new(2015, 6, 9, 12, 47))
59
+ end
60
+ end
61
+
62
+ describe "#slug" do
63
+ let(:attributes) { { id: 1, title: "Foo Bar" } }
64
+
65
+ context 'if there is a "title" field' do
66
+ let(:content_type) { { fields: { title: { field_type: "title" } } } }
67
+
68
+ it "retuns the slug of the record" do
69
+ expect(record.slug).to eq("1-foo-bar")
70
+ end
71
+ end
72
+
73
+ context "else" do
74
+ let(:content_type) { { fields: { title: { field_type: "text" } } } }
75
+
76
+ it "returns nil" do
77
+ expect(record.slug).to be_nil
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#method_missing" do
83
+ let(:content_type) { { fields: { foo: { field_type: "text" } } } }
84
+ let(:attributes) { { foo: "bar" } }
85
+
86
+ before do
87
+ allow(Dato::Field).to receive(:value).and_return("bar")
88
+ end
89
+
90
+ context "if the requested method matches one attribute" do
91
+ before { record.foo }
92
+
93
+ it 'calls the ".value" method of "Field" class' do
94
+ expect(Dato::Field).to have_received(:value).with(attributes[:foo], content_type[:fields][:foo])
95
+ end
96
+ end
97
+
98
+ context "if the same attribute is requested multiple times" do
99
+ it "returns the same object" do
100
+ expect(record.foo.object_id).to eq(record.foo.object_id)
101
+ end
102
+ end
103
+ end
104
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
- require 'active_support/dependencies'
1
+ require "simplecov"
2
+ SimpleCov.start
2
3
 
3
- require 'i18n'
4
+ require "active_support/dependencies"
5
+
6
+ require "i18n"
4
7
 
5
8
  I18n.available_locales = [:it, :en]
6
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.rc4
4
+ version: 0.0.1.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -74,10 +74,14 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".rubocop.yml"
77
78
  - Gemfile
78
79
  - Rakefile
79
80
  - lib/dato/client.rb
80
- - lib/dato/file.rb
81
+ - lib/dato/field.rb
82
+ - lib/dato/fields/belongs_to.rb
83
+ - lib/dato/fields/file.rb
84
+ - lib/dato/fields/seo.rb
81
85
  - lib/dato/meta_tags/article_modified_time.rb
82
86
  - lib/dato/meta_tags/article_publisher.rb
83
87
  - lib/dato/meta_tags/base.rb
@@ -97,12 +101,13 @@ files:
97
101
  - lib/dato/middleman_extension.rb
98
102
  - lib/dato/record.rb
99
103
  - lib/dato/repo.rb
100
- - lib/dato/seo.rb
101
104
  - lib/middleman-dato.rb
102
105
  - lib/middleman_extension.rb
103
106
  - middleman-dato.gemspec
107
+ - spec/dato/field_spec.rb
104
108
  - spec/dato/meta_tags/article_modified_time_spec.rb
105
109
  - spec/dato/meta_tags/og_locale_spec.rb
110
+ - spec/dato/record_spec.rb
106
111
  - spec/spec_helper.rb
107
112
  - spec/support/mock_builder.rb
108
113
  homepage: http://cantierecreativo.net
@@ -129,8 +134,10 @@ signing_key:
129
134
  specification_version: 4
130
135
  summary: Fetches data from a Dato space
131
136
  test_files:
137
+ - spec/dato/field_spec.rb
132
138
  - spec/dato/meta_tags/article_modified_time_spec.rb
133
139
  - spec/dato/meta_tags/og_locale_spec.rb
140
+ - spec/dato/record_spec.rb
134
141
  - spec/spec_helper.rb
135
142
  - spec/support/mock_builder.rb
136
143
  has_rdoc:
data/lib/dato/file.rb DELETED
@@ -1,16 +0,0 @@
1
- require "imgix"
2
-
3
- module Dato
4
- class File
5
- attr_reader :attributes
6
-
7
- def initialize(data)
8
- @attributes = data.with_indifferent_access
9
- end
10
-
11
- def file
12
- @file ||= Imgix::Client.new(host: 'dato-images.imgix.net')
13
- .path(attributes[:path])
14
- end
15
- end
16
- end
data/lib/dato/seo.rb DELETED
@@ -1,31 +0,0 @@
1
- require "imgix"
2
-
3
- module Dato
4
- class Seo
5
- attr_reader :attributes
6
-
7
- def initialize(data)
8
- @attributes = data.with_indifferent_access
9
- end
10
-
11
- def image
12
- @attributes[:image] && File.new(@attributes[:image])
13
- end
14
-
15
- def respond_to?(method, include_private = false)
16
- if @attributes.has_key?(method)
17
- true
18
- else
19
- super
20
- end
21
- end
22
-
23
- def method_missing(method, *arguments, &block)
24
- if @attributes.has_key?(method) && arguments.size == 0
25
- @attributes[method.to_sym]
26
- else
27
- super
28
- end
29
- end
30
- end
31
- end