izi_json_ld 1.0.5 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe FaqPageEntity do
4
+ let(:item) { described_class.new(mainEntity: []) }
5
+
6
+ it 'should be searializable as hash' do
7
+ expect(item.as_json).to be_present
8
+ end
9
+
10
+ it 'should be searializable as string' do
11
+ expect(item.to_json).to be_present
12
+ end
13
+
14
+ it 'should return html_safe string' do
15
+ expect(item.to_json).to be_html_safe
16
+ end
17
+
18
+ it 'should have @type' do
19
+ expect(item.as_json).to have_key '@type'
20
+ expect(item.as_json['@type']).to be_present
21
+ expect(item.as_json['@type']).to eq 'FAQPage'
22
+ end
23
+
24
+ context 'filled' do
25
+ let(:item) do
26
+ described_class.new(
27
+ mainEntity: [
28
+ { name: 'Question 1', acceptedAnswer: { text: 'Test answer 1' } },
29
+ { name: 'Question 2', acceptedAnswer: { text: 'Test answer 2' } },
30
+ { name: 'Question 3', acceptedAnswer: { text: 'Test answer 3' } }
31
+ ]
32
+ )
33
+ end
34
+ let(:singular) do
35
+ described_class.new(
36
+ mainEntity: {
37
+ name: 'Sing-Question', acceptedAnswer: { text: 'Sing-Answer' }
38
+ }
39
+ )
40
+ end
41
+ let(:shortland) do
42
+ described_class.new(
43
+ mainEntity: [
44
+ { name: 'ShortQuestion', answer: 'ShortAnswer' }
45
+ ]
46
+ )
47
+ end
48
+
49
+ it 'should render items' do
50
+ expect(item.as_json).to have_key 'mainEntity'
51
+ expect(item.as_json['mainEntity']).to be_present
52
+ expect(item.as_json['mainEntity'].size).to eq 3
53
+ end
54
+
55
+ it 'should render answer properly' do
56
+ answer = item.as_json.dig('mainEntity', 0)
57
+ expect(answer['name']).to eq 'Question 1'
58
+ expect(answer.dig('acceptedAnswer', 'text')).to eq 'Test answer 1'
59
+ end
60
+
61
+ it 'should render singular' do
62
+ answer = singular.as_json['mainEntity']
63
+ expect(answer['name']).to eq 'Sing-Question'
64
+ expect(answer.dig('acceptedAnswer', 'text')).to eq 'Sing-Answer'
65
+ end
66
+
67
+ it 'should accept name/answer shortland items' do
68
+ answer = shortland.as_json.dig('mainEntity', 0)
69
+
70
+ expect(answer).to be_present
71
+ expect(answer['name']).to eq 'ShortQuestion'
72
+ expect(answer.dig('acceptedAnswer', 'text')).to eq 'ShortAnswer'
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
87
+ end
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,14 @@
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
8
  description: 'TODO',
9
9
  reviewRating: { ratingValue: 3 }
10
- )
10
+ }
11
11
  end
12
+ let(:item) { described_class.new(item_data) }
12
13
 
13
14
  it 'should be searializable as hash' do
14
15
  expect(item.as_json).to be_present
@@ -28,17 +29,46 @@ RSpec.describe ReviewEntity do
28
29
  expect(item.as_json['@type']).to eq 'Review'
29
30
  end
30
31
 
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)
32
+ context 'datePublished' do
33
+ it 'should allow set datePublished as datetime' do
34
+ i2 = described_class.new(datePublished: time)
35
+ obj = JSON.parse(i2.to_json)
36
+
37
+ new_time = Time.zone.parse(obj['datePublished'])
38
+ expect(new_time).to be_within(1.second).of(time)
39
+ end
40
+
41
+ it 'should allow set datePublished as iso8601' do
42
+ i2 = described_class.new(datePublished: time.iso8601)
43
+ obj = JSON.parse(i2.to_json)
44
+
45
+ new_time = Time.zone.parse(obj['datePublished'])
46
+ expect(new_time).to be_within(1.second).of(time)
47
+ end
36
48
  end
37
49
 
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)
50
+ context 'author' do
51
+ it 'should parse author name as person' do
52
+ author = item.as_json['author']
53
+ expect(author).to be_a Hash
54
+ expect(author['@type']).to eq 'Person'
55
+ expect(author['name']).to eq item.author
56
+ end
57
+
58
+ it 'should allow to pass author hash' do
59
+ raw = described_class.new(item_data.merge(author: { person_name: 'Kenny' }))
60
+ author = raw.as_json['author']
61
+ expect(author).to be_a Hash
62
+ expect(author['@type']).to eq 'Person'
63
+ expect(author['name']).to eq raw.author.name
64
+ end
65
+
66
+ it 'should allow to pass author hash (Organization)' do
67
+ raw = described_class.new(item_data.merge(author: { name: 'Kenny' }))
68
+ author = raw.as_json['author']
69
+ expect(author).to be_a Hash
70
+ expect(author['@type']).to eq 'Organization'
71
+ expect(author['name']).to eq raw.author.name
72
+ end
43
73
  end
44
74
  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.5
4
+ version: 1.0.9
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-18 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -48,15 +48,18 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - README.rdoc
50
50
  - app/entities/aggregate_rating_entity.rb
51
+ - app/entities/answer_entity.rb
51
52
  - app/entities/application_entity.rb
52
53
  - app/entities/article_entity.rb
53
54
  - app/entities/breadcrumb_list_entity.rb
55
+ - app/entities/faq_page_entity.rb
54
56
  - app/entities/image_object_entity.rb
55
57
  - app/entities/list_item_entity.rb
56
58
  - app/entities/offer_entity.rb
57
59
  - app/entities/organization_entity.rb
58
60
  - app/entities/person_entity.rb
59
61
  - app/entities/product_entity.rb
62
+ - app/entities/question_entity.rb
60
63
  - app/entities/rating_entity.rb
61
64
  - app/entities/review_entity.rb
62
65
  - app/entities/web_page_entity.rb
@@ -90,13 +93,14 @@ files:
90
93
  - spec/dummy/config/routes.rb
91
94
  - spec/dummy/db/development.sqlite3
92
95
  - spec/dummy/db/test.sqlite3
93
- - spec/dummy/log/development.log
94
96
  - spec/dummy/log/test.log
95
97
  - spec/dummy/tmp/development_secret.txt
96
98
  - spec/entities/aggregate_rating_entity_spec.rb
97
99
  - spec/entities/article_entity_spec.rb
98
100
  - spec/entities/breadcrumb_list_entity_spec.rb
101
+ - spec/entities/faq_page_entity_spec.rb
99
102
  - spec/entities/offer_entity_spec.rb
103
+ - spec/entities/person_entity_spec.rb
100
104
  - spec/entities/product_entity_spec.rb
101
105
  - spec/entities/rating_entity_spec.rb
102
106
  - spec/entities/review_entity_spec.rb
@@ -121,7 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
125
  - !ruby/object:Gem::Version
122
126
  version: '0'
123
127
  requirements: []
124
- rubygems_version: 3.1.2
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.14.4
125
130
  signing_key:
126
131
  specification_version: 4
127
132
  summary: Izi Lightup
@@ -150,12 +155,13 @@ test_files:
150
155
  - spec/dummy/db/test.sqlite3
151
156
  - spec/dummy/db/development.sqlite3
152
157
  - spec/dummy/log/test.log
153
- - spec/dummy/log/development.log
154
158
  - spec/dummy/tmp/development_secret.txt
155
159
  - spec/rails_helper.rb
156
160
  - spec/entities/aggregate_rating_entity_spec.rb
157
161
  - spec/entities/review_entity_spec.rb
158
162
  - spec/entities/breadcrumb_list_entity_spec.rb
163
+ - spec/entities/faq_page_entity_spec.rb
164
+ - spec/entities/person_entity_spec.rb
159
165
  - spec/entities/rating_entity_spec.rb
160
166
  - spec/entities/offer_entity_spec.rb
161
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