contentful_middleman 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db0206f855bb8bfb8c037a5aabc0c0d1b668db0a
4
- data.tar.gz: bfc915bd5b1d17c43f8c339fda06af0fa594417a
3
+ metadata.gz: afab6f9f2082efc2316157faf338a513c2e6e6eb
4
+ data.tar.gz: 40656a4aec70d29441724ade7b93ef12b48b7f79
5
5
  SHA512:
6
- metadata.gz: 5661015434c5c51b32aeab1c1c735eaee5cc41f053c2e618e15bde6ab874743af5877ab594fcdad6659b2602cdf0c56bab443368398efae8a3c9c63cfc68f005
7
- data.tar.gz: 0a23c10c9ee693e9c3a2f1f8dcf28232c3025ebf0528c055d7e0a9841bcd6448b0ce169a43b8937af36ff654e442f0cee9fdd7885f7688b9ef931c2ece593715
6
+ metadata.gz: 8cf2b26d03c3f463dce1bcb6ea57c5b8e0e76424752bfd00d0afdad350fc1ba9fadb70acfab4cf1d1eecad4ee6ea8e2473076eade4216431a3638a3a7b68c577
7
+ data.tar.gz: 60c4bc8fe795b67fdd33188c9de8349aa09ece3f8168a0fecea667283fb122bf368789e66812db330cc0c07eff5c57176fb9f0dd2b789d8b994009e8869984f7
@@ -1,6 +1,11 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
3
 
4
+ ## 1.3.2
5
+ ### Fixed
6
+ * Fixed Entry ID fetch on import task when having an ID field in the Content Type[#77](https://github.com/contentful/contentful_middleman/issues/77)
7
+ * Fixed `NoMethodError` when Entry has no populated fields[#76](https://github.com/contentful/contentful_middleman/issues/76)
8
+
4
9
  ## 1.3.1
5
10
  ### Fixed
6
11
  * Middleman not loading extension due to `@app` reassignment
@@ -22,6 +22,15 @@ module ContentfulMiddleman
22
22
  @changed_local_data
23
23
  end
24
24
 
25
+ def entries
26
+ @entries ||= @contentful.entries
27
+ end
28
+
29
+ def file_name(content_type_name, entry)
30
+ entry_id = entry.sys.key?(:id) ? entry.sys[:id] : entry.id
31
+ File.join(@space_name, content_type_name, entry_id.to_s)
32
+ end
33
+
25
34
  private
26
35
  def local_data_files
27
36
  entries.map do |entry|
@@ -35,12 +44,8 @@ module ContentfulMiddleman
35
44
  content_type_mapper = content_type_mapper_class.new(entries, @contentful.options)
36
45
  content_type_mapper.map(context, entry)
37
46
 
38
- LocalData::File.new(context.to_yaml, File.join(@space_name, content_type_name, entry.id))
47
+ LocalData::File.new(context.to_yaml, file_name(content_type_name, entry))
39
48
  end.compact
40
49
  end
41
-
42
- def entries
43
- @entries ||= @contentful.entries
44
- end
45
50
  end
46
51
  end
@@ -64,6 +64,9 @@ module ContentfulMiddleman
64
64
 
65
65
  fields = has_multiple_locales? ? entry.fields_with_locales : entry.fields
66
66
 
67
+ # Prevent entries with no values from breaking the import
68
+ fields ||= []
69
+
67
70
  fields.each {|k, v| map_field context, k, v}
68
71
  end
69
72
 
@@ -15,7 +15,7 @@ module ContentfulMiddleman
15
15
  end
16
16
 
17
17
  def ensure_backup_path!
18
- return if ::File.exists? basepath
18
+ return if ::File.exist? basepath
19
19
 
20
20
  FileUtils.mkdir_p basepath
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module ContentfulMiddleman
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -6,9 +6,13 @@ class ClientDouble
6
6
  end
7
7
  end
8
8
 
9
+ class EntryDouble
10
+ end
11
+
9
12
  describe ContentfulMiddleman::ImportTask do
10
13
  let(:path) { File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'space_hash_fixtures')) }
11
- subject { described_class.new 'foobar', {}, {}, ClientDouble.new }
14
+ let(:client) { ClientDouble.new }
15
+ subject { described_class.new 'foobar', {}, {}, client }
12
16
 
13
17
  describe 'instance methods' do
14
18
  before do
@@ -37,5 +41,22 @@ describe ContentfulMiddleman::ImportTask do
37
41
  expect(subject.changed_local_data?).to eq(true)
38
42
  end
39
43
  end
44
+
45
+ it '#entries' do
46
+ expect(subject.entries).to eq client.entries
47
+ end
48
+
49
+ describe '#file_name' do
50
+ it 'uses entry.sys[:id] over entry.id' do
51
+ entry = EntryDouble.new('foo', {}, {id: 'bar'})
52
+ client.entries << entry
53
+
54
+ expect(entry.id).not_to eq entry.sys[:id]
55
+ expect(entry.id).to eq 'bar'
56
+ expect(entry.sys[:id]).to eq 'foo'
57
+
58
+ expect(subject.file_name('baz', entry)).to eq File.join('foobar', 'baz', 'foo')
59
+ end
60
+ end
40
61
  end
41
62
  end
@@ -85,4 +85,14 @@ describe ContentfulMiddleman::Mapper::Base do
85
85
  expect(subject.entries).to match(entries)
86
86
  end
87
87
  end
88
+
89
+ describe 'issues' do
90
+ it 'should not fail on empty entry - #76' do
91
+ entry = EntryDouble.new('foo', {}, nil)
92
+ context = ContentfulMiddleman::Context.new
93
+
94
+ expect { subject.map(context, entry) }.not_to raise_error
95
+ expect(context.hashize).to eq(id: 'foo')
96
+ end
97
+ end
88
98
  end
@@ -1,14 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- class EntryDouble
4
- attr_reader :id, :updated_at
5
-
6
- def initialize(id, updated_at)
7
- @id = id
8
- @updated_at = updated_at
9
- end
10
- end
11
-
12
3
  describe ContentfulMiddleman::VersionHash do
13
4
  let(:path) { File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'space_hash_fixtures')) }
14
5
  describe 'class methods' do
@@ -32,7 +23,7 @@ describe ContentfulMiddleman::VersionHash do
32
23
  end
33
24
 
34
25
  describe '::write_for_space_with_entries' do
35
- let(:entries) { [EntryDouble.new(1, '2015-11-25'), EntryDouble.new(2, '2015-11-25')] }
26
+ let(:entries) { [EntryDouble.new(1, {}, {}, '2015-11-25'), EntryDouble.new(2, {}, {}, '2015-11-25')] }
36
27
 
37
28
  before do
38
29
  described_class.source_root = path
@@ -64,3 +64,27 @@ class OptionsDouble
64
64
  end
65
65
  end
66
66
  end
67
+
68
+ class EntryDouble
69
+ attr_reader :id, :sys, :fields
70
+
71
+ def initialize(id, sys_data = {}, fields = {}, updated_at = nil)
72
+ @id = id
73
+ sys_data[:id] = id
74
+ sys_data[:updated_at] = updated_at
75
+ @sys = sys_data
76
+ @fields = fields
77
+
78
+ unless fields.nil?
79
+ fields.each do |k, v|
80
+ define_singleton_method k do
81
+ v
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ def updated_at
88
+ sys[:updated_at]
89
+ end
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sascha Konietzke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-14 00:00:00.000000000 Z
12
+ date: 2016-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core