izi_json_ld 1.0.6 → 1.0.10

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.
@@ -71,5 +71,18 @@ RSpec.describe FaqPageEntity do
71
71
  expect(answer['name']).to eq 'ShortQuestion'
72
72
  expect(answer.dig('acceptedAnswer', 'text')).to eq 'ShortAnswer'
73
73
  end
74
+
75
+ it 'should not render useless @context' do
76
+ parsed = JSON.parse(item.to_json)
77
+
78
+ expect(parsed['@context']).to be_present
79
+ expect(parsed['@context']).to eq 'https://schema.org'
80
+
81
+ expect(parsed.dig('mainEntity', 0)).to be_present
82
+ expect(parsed.dig('mainEntity', 0)).not_to have_key '@context'
83
+
84
+ expect(parsed.dig('mainEntity', 0, 'acceptedAnswer')).to be_present
85
+ expect(parsed.dig('mainEntity', 0, 'acceptedAnswer')).not_to have_key '@context'
86
+ end
74
87
  end
75
88
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe PersonEntity do
4
+ let(:item) { described_class.new(person_name: 'Johan') }
5
+
6
+ it 'should be searializable as string' do
7
+ expect(item.to_json).to be_present
8
+ end
9
+
10
+ it 'should have @context' do
11
+ expect(item.as_json).to have_key '@context'
12
+ expect(item.as_json['@context']).to be_present
13
+ expect(item.as_json['@context']).to include 'schema.org'
14
+ end
15
+
16
+ it 'should have @type' do
17
+ expect(item.as_json).to have_key '@type'
18
+ expect(item.as_json['@type']).to be_present
19
+ expect(item.as_json['@type']).to eq 'Person'
20
+ end
21
+
22
+ it 'allow to pass single sameAs item' do
23
+ item2 = nil
24
+ expect do
25
+ item2 = described_class.new(person_name: 'Johan', sameAs: 'http://example.com')
26
+ end.not_to raise_error
27
+ expect(item2).to be_present
28
+ expect(item2.as_json).to be_present
29
+ expect(item2.as_json['sameAs']).to eq 'http://example.com'
30
+ end
31
+
32
+ it 'allow to pass multiple sameAs links' do
33
+ item2 = nil
34
+ expect do
35
+ item2 = described_class.new(person_name: 'Johan', sameAs: ['http://example.com', 'http://example.com/extra'])
36
+ end.not_to raise_error
37
+ expect(item2).to be_present
38
+ expect(item2.as_json).to be_present
39
+ expect(item2.as_json['sameAs']).to include 'http://example.com'
40
+ expect(item2.as_json['sameAs']).to include 'http://example.com/extra'
41
+ end
42
+ end
@@ -2,13 +2,15 @@
2
2
 
3
3
  RSpec.describe ReviewEntity do
4
4
  let(:time) { 1.week.ago }
5
- let(:item) do
6
- described_class.new(
5
+ let(:item_data) do
6
+ {
7
7
  author: 'John',
8
+ publisher: 'Fodojo LLC',
8
9
  description: 'TODO',
9
10
  reviewRating: { ratingValue: 3 }
10
- )
11
+ }
11
12
  end
13
+ let(:item) { described_class.new(item_data) }
12
14
 
13
15
  it 'should be searializable as hash' do
14
16
  expect(item.as_json).to be_present
@@ -28,17 +30,71 @@ RSpec.describe ReviewEntity do
28
30
  expect(item.as_json['@type']).to eq 'Review'
29
31
  end
30
32
 
31
- it 'should allow set datePublished as datetime' do
32
- i2 = described_class.new(datePublished: time)
33
- obj = JSON.parse(i2.to_json)
34
- newTime = Time.zone.parse(obj['datePublished'])
35
- expect(newTime).to be_within(1.second).of(time)
33
+ context 'datePublished' do
34
+ it 'should allow set datePublished as datetime' do
35
+ i2 = described_class.new(datePublished: time)
36
+ obj = JSON.parse(i2.to_json)
37
+
38
+ new_time = Time.zone.parse(obj['datePublished'])
39
+ expect(new_time).to be_within(1.second).of(time)
40
+ end
41
+
42
+ it 'should allow set datePublished as iso8601' do
43
+ i2 = described_class.new(datePublished: time.iso8601)
44
+ obj = JSON.parse(i2.to_json)
45
+
46
+ new_time = Time.zone.parse(obj['datePublished'])
47
+ expect(new_time).to be_within(1.second).of(time)
48
+ end
36
49
  end
37
50
 
38
- it 'should allow set datePublished as iso8601' do
39
- i2 = described_class.new(datePublished: time.iso8601)
40
- obj = JSON.parse(i2.to_json)
41
- newTime = Time.zone.parse(obj['datePublished'])
42
- expect(newTime).to be_within(1.second).of(time)
51
+ context 'author' do
52
+ it 'should parse author name as person' do
53
+ author = item.as_json['author']
54
+ expect(author).to be_a Hash
55
+ expect(author['@type']).to eq 'Person'
56
+ expect(author['name']).to eq item.author
57
+ end
58
+
59
+ it 'should allow to pass author hash' do
60
+ raw = described_class.new(item_data.merge(author: { person_name: 'Kenny' }))
61
+ author = raw.as_json['author']
62
+ expect(author).to be_a Hash
63
+ expect(author['@type']).to eq 'Person'
64
+ expect(author['name']).to eq raw.author.name
65
+ end
66
+
67
+ it 'should allow to pass author hash (Organization)' do
68
+ raw = described_class.new(item_data.merge(author: { name: 'Kenny' }))
69
+ author = raw.as_json['author']
70
+ expect(author).to be_a Hash
71
+ expect(author['@type']).to eq 'Organization'
72
+ expect(author['name']).to eq raw.author.name
73
+ end
74
+ end
75
+
76
+ context 'publisher' do
77
+ it 'should parse publisher name as organizaton' do
78
+ publisher = item.as_json['publisher']
79
+ expect(publisher).to be_a Hash
80
+ expect(publisher['@type']).to eq 'Organization'
81
+ expect(publisher['name']).to eq item.publisher
82
+ end
83
+
84
+ it 'should allow to pass publisher hash' do
85
+ raw = described_class.new(item_data.merge(publisher: { person_name: 'Kenny' }))
86
+ publisher = raw.as_json['publisher']
87
+ expect(publisher).to be_a Hash
88
+ expect(publisher['@type']).to eq 'Person'
89
+ expect(publisher['name']).to eq raw.publisher.name
90
+ end
91
+
92
+ it 'should allow to pass publisher hash (Organization)' do
93
+ raw = described_class.new(item_data.merge(publisher: { name: 'Kenny' }))
94
+ publisher = raw.as_json['publisher']
95
+ expect(publisher).to be_a Hash
96
+ expect(publisher['@type']).to eq 'Organization'
97
+ expect(publisher['name']).to eq raw.publisher.name
98
+ end
43
99
  end
44
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izi_json_ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -93,7 +93,6 @@ files:
93
93
  - spec/dummy/config/routes.rb
94
94
  - spec/dummy/db/development.sqlite3
95
95
  - spec/dummy/db/test.sqlite3
96
- - spec/dummy/log/development.log
97
96
  - spec/dummy/log/test.log
98
97
  - spec/dummy/tmp/development_secret.txt
99
98
  - spec/entities/aggregate_rating_entity_spec.rb
@@ -101,6 +100,7 @@ files:
101
100
  - spec/entities/breadcrumb_list_entity_spec.rb
102
101
  - spec/entities/faq_page_entity_spec.rb
103
102
  - spec/entities/offer_entity_spec.rb
103
+ - spec/entities/person_entity_spec.rb
104
104
  - spec/entities/product_entity_spec.rb
105
105
  - spec/entities/rating_entity_spec.rb
106
106
  - spec/entities/review_entity_spec.rb
@@ -155,13 +155,13 @@ test_files:
155
155
  - spec/dummy/db/test.sqlite3
156
156
  - spec/dummy/db/development.sqlite3
157
157
  - spec/dummy/log/test.log
158
- - spec/dummy/log/development.log
159
158
  - spec/dummy/tmp/development_secret.txt
160
159
  - spec/rails_helper.rb
161
160
  - spec/entities/aggregate_rating_entity_spec.rb
162
161
  - spec/entities/review_entity_spec.rb
163
162
  - spec/entities/breadcrumb_list_entity_spec.rb
164
163
  - spec/entities/faq_page_entity_spec.rb
164
+ - spec/entities/person_entity_spec.rb
165
165
  - spec/entities/rating_entity_spec.rb
166
166
  - spec/entities/offer_entity_spec.rb
167
167
  - spec/entities/article_entity_spec.rb
@@ -1,16 +0,0 @@
1
-  (0.1ms) SELECT sqlite_version(*)
2
- ↳ bin/rails:4
3
-  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
4
- ↳ bin/rails:4
5
-  (1.2ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
6
- ↳ bin/rails:4
7
- ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
8
- ↳ bin/rails:4
9
-  (0.1ms) begin transaction
10
- ↳ bin/rails:4
11
- ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", "2021-03-17 08:43:32.839496"], ["updated_at", "2021-03-17 08:43:32.839496"]]
12
- ↳ bin/rails:4
13
-  (0.7ms) commit transaction
14
- ↳ bin/rails:4
15
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
16
- ↳ bin/rails:4