izi_json_ld 1.0.2 → 1.0.7

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.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/app/entities/aggregate_rating_entity.rb +1 -1
  3. data/app/entities/answer_entity.rb +7 -0
  4. data/app/entities/application_entity.rb +54 -7
  5. data/app/entities/article_entity.rb +16 -0
  6. data/app/entities/breadcrumb_list_entity.rb +7 -0
  7. data/app/entities/faq_page_entity.rb +8 -0
  8. data/app/entities/image_object_entity.rb +6 -0
  9. data/app/entities/list_item_entity.rb +9 -0
  10. data/app/entities/offer_entity.rb +2 -2
  11. data/app/entities/organization_entity.rb +10 -0
  12. data/app/entities/person_entity.rb +14 -0
  13. data/app/entities/product_entity.rb +2 -3
  14. data/app/entities/question_entity.rb +19 -0
  15. data/app/entities/rating_entity.rb +1 -1
  16. data/app/entities/review_entity.rb +2 -2
  17. data/app/entities/web_page_entity.rb +11 -0
  18. data/lib/izi_json_ld/types.rb +3 -0
  19. data/lib/izi_json_ld/types/date_time.rb +11 -0
  20. data/lib/izi_json_ld/types/one_or_more.rb +13 -0
  21. data/lib/izi_json_ld/version.rb +1 -1
  22. data/spec/dummy/config/application.rb +5 -1
  23. data/spec/dummy/config/environments/test.rb +9 -7
  24. data/spec/dummy/db/development.sqlite3 +0 -0
  25. data/spec/dummy/db/test.sqlite3 +0 -0
  26. data/spec/dummy/log/development.log +16 -0
  27. data/spec/dummy/log/test.log +17448 -0
  28. data/spec/entities/article_entity_spec.rb +113 -0
  29. data/spec/entities/breadcrumb_list_entity_spec.rb +55 -0
  30. data/spec/entities/faq_page_entity_spec.rb +88 -0
  31. data/spec/entities/product_entity_spec.rb +27 -0
  32. data/spec/rails_helper.rb +1 -17
  33. metadata +24 -21
  34. data/spec/dummy/Gemfile +0 -14
  35. data/spec/dummy/Gemfile.lock +0 -229
  36. data/spec/dummy/app/models/application_record.rb +0 -3
  37. data/spec/dummy/bin/_guard-core +0 -29
  38. data/spec/dummy/bin/guard +0 -29
  39. data/spec/dummy/bin/rails +0 -4
  40. data/spec/dummy/bin/rake +0 -4
  41. data/spec/dummy/bin/rspec +0 -29
  42. data/spec/dummy/bin/setup +0 -33
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe ArticleEntity do
4
+ let(:item) do
5
+ described_class.new(
6
+ headline: 'Test Article Title',
7
+ mainEntityOfPage: {
8
+ web_page: 'https://exampla.com/blog/page'
9
+ }
10
+ )
11
+ end
12
+
13
+ it 'should be searializable as hash' do
14
+ expect(item.as_json).to be_present
15
+ end
16
+
17
+ it 'should have @type' do
18
+ expect(item.as_json).to have_key '@type'
19
+ expect(item.as_json['@type']).to be_present
20
+ expect(item.as_json['@type']).to eq 'Article'
21
+ end
22
+
23
+ it 'should have @context at root entity' do
24
+ expect(item.as_json).to have_key '@context'
25
+ expect(item.as_json['@context']).to be_present
26
+ expect(item.as_json['@context']).to include 'schema.org'
27
+ end
28
+
29
+ it 'possible to set mainEntityOfPage as URL' do
30
+ custom = described_class.new(headline: 'Title', mainEntityOfPage: 'https://exampla.com/blog/page')
31
+ expect(custom.as_json.dig('mainEntityOfPage')).to be_present
32
+ expect(custom.as_json.dig('mainEntityOfPage')).to eq 'https://exampla.com/blog/page'
33
+ end
34
+
35
+ context 'filled Article' do
36
+ let(:item) do
37
+ described_class.new(
38
+ mainEntityOfPage: {
39
+ web_page: 'https://exampla.com/blog/page'
40
+ },
41
+ headline: 'Test Article Title',
42
+ description: 'Test Article Description',
43
+ image: 'https://exampla.com/blog/page.png',
44
+ author: { name: 'TestUser' },
45
+ publisher: {
46
+ name: 'TestInc',
47
+ logo: { url: 'https://exampla.com/logo.png' }
48
+ },
49
+ datePublished: 1.week.ago,
50
+ dateModified: 2.days.ago
51
+ )
52
+ end
53
+
54
+ it 'should not fail' do
55
+ expect do
56
+ item.dump
57
+ item.as_json
58
+ item.to_json
59
+ end.not_to raise_exception
60
+ end
61
+
62
+ [
63
+ ['Publisher name', %w[publisher name], 'TestInc'],
64
+ ['Main Entity id', %w[mainEntityOfPage @id], 'https://exampla.com/blog/page'],
65
+ ['Publisher type', %w[publisher @type], 'Organization'],
66
+ ['Publisher logo type', %w[publisher logo @type], 'ImageObject'],
67
+ ['Publisher logo', %w[publisher logo url], 'https://exampla.com/logo.png'],
68
+ ['Post image', %w[image], 'https://exampla.com/blog/page.png'],
69
+ ['Author as org', %w[author @type], 'Organization'],
70
+ ['Author name', %w[author name], 'TestUser']
71
+ ].each do |(desc, path, val)|
72
+ it "should render #{desc}[#{path.join('.')}]" do
73
+ expect(item.as_json.dig(*path)).to be_present
74
+ expect(item.as_json.dig(*path)).to eq val
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'with author as a Person' do
80
+ let(:item) do
81
+ described_class.new(
82
+ mainEntityOfPage: {
83
+ web_page: 'https://exampla.com/blog/page'
84
+ },
85
+ headline: 'Test Article Title',
86
+ publisher: {
87
+ person_name: 'SiteOwner',
88
+ email: 'site.owner@example.com',
89
+ image: 'owner.png'
90
+ },
91
+ author: {
92
+ person_name: 'TestBlogger',
93
+ image: 'blogger.png'
94
+ }
95
+ )
96
+ end
97
+
98
+ [
99
+ ['Publisher as person', %w[publisher @type], 'Person'],
100
+ ['Publisher name', %w[publisher name], 'SiteOwner'],
101
+ ['Publisher email', %w[publisher email], 'site.owner@example.com'],
102
+ ['Publisher image', %w[publisher image], 'owner.png'],
103
+ ['Author as person', %w[author @type], 'Person'],
104
+ ['Author name', %w[author name], 'TestBlogger'],
105
+ ['Author image', %w[author image], 'blogger.png']
106
+ ].each do |(desc, path, val)|
107
+ it "should render #{desc}[#{path.join('.')}]" do
108
+ expect(item.as_json.dig(*path)).to be_present
109
+ expect(item.as_json.dig(*path)).to eq val
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe BreadcrumbListEntity do
4
+ let(:item) { described_class.new(itemListElement: []) }
5
+
6
+ it 'should be searializable as hash' do
7
+ expect(item.as_json).to be_present
8
+ end
9
+
10
+ it 'should have @type' do
11
+ expect(item.as_json).to have_key '@type'
12
+ expect(item.as_json['@type']).to be_present
13
+ expect(item.as_json['@type']).to eq 'BreadcrumbList'
14
+ end
15
+
16
+ it 'should have @context at root entity' do
17
+ expect(item.as_json).to have_key '@context'
18
+ expect(item.as_json['@context']).to be_present
19
+ expect(item.as_json['@context']).to include 'schema.org'
20
+ end
21
+
22
+ context 'with simple item' do
23
+ let(:item) do
24
+ described_class.new(itemListElement: { name: 'Home', position: 0, item: 'https://example.com' })
25
+ end
26
+
27
+ it 'should not fail' do
28
+ expect do
29
+ item.dump
30
+ item.as_json
31
+ item.to_json
32
+ end.not_to raise_exception
33
+ end
34
+ end
35
+
36
+ context 'with multiple items' do
37
+ let(:item) do
38
+ described_class.new(
39
+ itemListElement: [
40
+ { name: 'Home', position: 0, item: 'https://example.com' },
41
+ { name: 'Blog', position: 1, item: 'https://example.com/blog' },
42
+ { name: 'Post', position: 2, item: 'https://example.com/blog/post' },
43
+ ]
44
+ )
45
+ end
46
+
47
+ it 'should not fail' do
48
+ expect do
49
+ item.dump
50
+ item.as_json
51
+ item.to_json
52
+ end.not_to raise_exception
53
+ end
54
+ end
55
+ end
@@ -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
@@ -35,6 +35,12 @@ RSpec.describe ProductEntity do
35
35
  expect(item.as_json['aggregateRating']).to be_present
36
36
  expect(item.as_json.dig('aggregateRating', 'ratingValue')).to eq 4
37
37
  end
38
+
39
+ it 'should have aggregateRating @type' do
40
+ expect(item.as_json).to have_key 'aggregateRating'
41
+ expect(item.as_json['aggregateRating']).to be_present
42
+ expect(item.as_json.dig('aggregateRating', '@type')).to eq 'AggregateRating'
43
+ end
38
44
  end
39
45
 
40
46
  context 'with offers' do
@@ -45,6 +51,12 @@ RSpec.describe ProductEntity do
45
51
  expect(item.as_json['offers']).to be_present
46
52
  expect(item.as_json.dig('offers', 'url')).to eq 'test'
47
53
  end
54
+
55
+ it 'offers should have right @type' do
56
+ expect(item.as_json).to have_key 'offers'
57
+ expect(item.as_json['offers']).to be_present
58
+ expect(item.as_json.dig('offers', '@type')).to eq 'Offer'
59
+ end
48
60
  end
49
61
 
50
62
  context 'with review' do
@@ -70,5 +82,20 @@ RSpec.describe ProductEntity do
70
82
  expect(data.as_json['review']).to be_present
71
83
  expect(data.as_json['review'].class.name).to eq 'Array'
72
84
  end
85
+
86
+ it 'review & reviewRating should contain right @type' do
87
+ data = described_class.new(name: 'Test', review: reviews)
88
+ expect(data.as_json.dig('review', 0, '@type')).to eq 'Review'
89
+ expect(data.as_json.dig('review', 0, 'reviewRating', '@type')).to eq 'Rating'
90
+ end
91
+
92
+ it 'ensure proper serialization' do
93
+ data = described_class.new(name: 'Test', review: reviews)
94
+ raw = data.to_json
95
+ parsed = JSON.parse(raw)
96
+ expect(parsed).to be_present
97
+ expect(parsed.dig('review', 0, '@type')).to eq 'Review'
98
+ expect(parsed.dig('review', 0, 'reviewRating', '@type')).to eq 'Rating'
99
+ end
73
100
  end
74
101
  end
data/spec/rails_helper.rb CHANGED
@@ -22,25 +22,9 @@ require 'rspec/rails'
22
22
  #
23
23
  # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
24
24
 
25
- # Checks for pending migrations and applies them before tests are run.
26
- # If you are not using ActiveRecord, you can remove these lines.
27
- begin
28
- ActiveRecord::Migration.maintain_test_schema!
29
- rescue ActiveRecord::PendingMigrationError => e
30
- puts e.to_s.strip
31
- exit 1
32
- end
33
25
  RSpec.configure do |config|
34
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
36
-
37
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
38
- # examples within a transaction, remove the following line or assign false
39
- # instead of true.
40
- config.use_transactional_fixtures = true
41
-
42
26
  # You can uncomment this line to turn off ActiveRecord support entirely.
43
- # config.use_active_record = false
27
+ config.use_active_record = false
44
28
 
45
29
  # RSpec Rails can automatically mix in different behaviours to your tests
46
30
  # based on their file location, for example enabling you to call `get` and
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.2
4
+ version: 1.0.7
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-15 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -48,31 +48,34 @@ 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
53
+ - app/entities/article_entity.rb
54
+ - app/entities/breadcrumb_list_entity.rb
55
+ - app/entities/faq_page_entity.rb
56
+ - app/entities/image_object_entity.rb
57
+ - app/entities/list_item_entity.rb
52
58
  - app/entities/offer_entity.rb
59
+ - app/entities/organization_entity.rb
60
+ - app/entities/person_entity.rb
53
61
  - app/entities/product_entity.rb
62
+ - app/entities/question_entity.rb
54
63
  - app/entities/rating_entity.rb
55
64
  - app/entities/review_entity.rb
65
+ - app/entities/web_page_entity.rb
56
66
  - app/helpers/json_ld_helper.rb
57
67
  - lib/izi_json_ld.rb
58
68
  - lib/izi_json_ld/engine.rb
59
69
  - lib/izi_json_ld/extentions/autoload_paths.rb
60
70
  - lib/izi_json_ld/types.rb
71
+ - lib/izi_json_ld/types/date_time.rb
72
+ - lib/izi_json_ld/types/one_or_more.rb
61
73
  - lib/izi_json_ld/version.rb
62
- - spec/dummy/Gemfile
63
- - spec/dummy/Gemfile.lock
64
74
  - spec/dummy/Rakefile
65
75
  - spec/dummy/app/assets/config/manifest.js
66
76
  - spec/dummy/app/controllers/application_controller.rb
67
77
  - spec/dummy/app/helpers/application_helper.rb
68
- - spec/dummy/app/models/application_record.rb
69
78
  - spec/dummy/app/views/layouts/application.html.erb
70
- - spec/dummy/bin/_guard-core
71
- - spec/dummy/bin/guard
72
- - spec/dummy/bin/rails
73
- - spec/dummy/bin/rake
74
- - spec/dummy/bin/rspec
75
- - spec/dummy/bin/setup
76
79
  - spec/dummy/config.ru
77
80
  - spec/dummy/config/application.rb
78
81
  - spec/dummy/config/boot.rb
@@ -88,11 +91,15 @@ files:
88
91
  - spec/dummy/config/initializers/wrap_parameters.rb
89
92
  - spec/dummy/config/puma.rb
90
93
  - spec/dummy/config/routes.rb
94
+ - spec/dummy/db/development.sqlite3
91
95
  - spec/dummy/db/test.sqlite3
92
96
  - spec/dummy/log/development.log
93
97
  - spec/dummy/log/test.log
94
98
  - spec/dummy/tmp/development_secret.txt
95
99
  - spec/entities/aggregate_rating_entity_spec.rb
100
+ - spec/entities/article_entity_spec.rb
101
+ - spec/entities/breadcrumb_list_entity_spec.rb
102
+ - spec/entities/faq_page_entity_spec.rb
96
103
  - spec/entities/offer_entity_spec.rb
97
104
  - spec/entities/product_entity_spec.rb
98
105
  - spec/entities/rating_entity_spec.rb
@@ -118,23 +125,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
125
  - !ruby/object:Gem::Version
119
126
  version: '0'
120
127
  requirements: []
121
- rubygems_version: 3.1.2
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.14.4
122
130
  signing_key:
123
131
  specification_version: 4
124
132
  summary: Izi Lightup
125
133
  test_files:
126
134
  - spec/spec_helper.rb
127
- - spec/dummy/app/models/application_record.rb
128
135
  - spec/dummy/app/controllers/application_controller.rb
129
136
  - spec/dummy/app/views/layouts/application.html.erb
130
137
  - spec/dummy/app/assets/config/manifest.js
131
138
  - spec/dummy/app/helpers/application_helper.rb
132
- - spec/dummy/bin/rake
133
- - spec/dummy/bin/setup
134
- - spec/dummy/bin/_guard-core
135
- - spec/dummy/bin/guard
136
- - spec/dummy/bin/rspec
137
- - spec/dummy/bin/rails
138
139
  - spec/dummy/config/routes.rb
139
140
  - spec/dummy/config/environments/production.rb
140
141
  - spec/dummy/config/environments/development.rb
@@ -152,14 +153,16 @@ test_files:
152
153
  - spec/dummy/config.ru
153
154
  - spec/dummy/Rakefile
154
155
  - spec/dummy/db/test.sqlite3
155
- - spec/dummy/Gemfile
156
+ - spec/dummy/db/development.sqlite3
156
157
  - spec/dummy/log/test.log
157
158
  - spec/dummy/log/development.log
158
- - spec/dummy/Gemfile.lock
159
159
  - spec/dummy/tmp/development_secret.txt
160
160
  - spec/rails_helper.rb
161
161
  - spec/entities/aggregate_rating_entity_spec.rb
162
162
  - spec/entities/review_entity_spec.rb
163
+ - spec/entities/breadcrumb_list_entity_spec.rb
164
+ - spec/entities/faq_page_entity_spec.rb
163
165
  - spec/entities/rating_entity_spec.rb
164
166
  - spec/entities/offer_entity_spec.rb
167
+ - spec/entities/article_entity_spec.rb
165
168
  - spec/entities/product_entity_spec.rb