abizvn-cms 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 647b24ac902cdea12774d9951f524848188a9edd8a6c689226ed4302a60f7ec3
4
- data.tar.gz: bca910b59c6dbf508740fffa7f2e28d39c32dd03028fc5d57efa92821b638ef8
3
+ metadata.gz: 5ba582710db4f69bcd4763391b110d3fe1475dc186d6af48bc0a264b3670808e
4
+ data.tar.gz: de72b53fc5d6b651d1f00b4494a58652db9cfbe6c3f163ebf3e8be7079a07709
5
5
  SHA512:
6
- metadata.gz: b8ad531808d48abadcf0c8d3df6f19f1e9b021c8f182e545c4a2ae05a0415bdba29c590bf603700dfcc0fb2eba34434b64be438f790dbe8440736e156ec94d78
7
- data.tar.gz: 8775dc537f88a69efd482a376439abd8b0997c35c0f422d0f63455db2c0843d9848d0aeb0b7479e200112900d0bf6cfe502ae2277d9f40dff96914fc18cacf23
6
+ metadata.gz: 8c366eb41c5eed5dad90ce1045a0bfca578e374b3cc0800f1c2e555d0b525e808aeaf1bebf72bad111a148cbea8604a1763546c2092c196a212e0b4ecec9b275
7
+ data.tar.gz: 2b4c819554f7420a9f45f35a34a71884fa020078c98a8268e355e0ab8e37a0dc54fc1f8fd1f7680b0eff00ebba5251620014f0ed4b7f001b2681bd68cfe004dd
@@ -0,0 +1,12 @@
1
+ module Abizvn
2
+ module Cms
3
+ class ArticleLiteSerializer
4
+ include JSONAPI::Serializer
5
+
6
+ attributes :title, :updated_at
7
+
8
+ attribute :id do |article| article.slug || article.id end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,13 @@
1
+ module Abizvn
2
+ module Cms
3
+ class ArticleSerializer < ArticleLiteSerializer
4
+ attributes :description, :created_at
5
+
6
+ attribute :category do |article|
7
+ if article.category
8
+ CategoryLiteSerializer.new(article.category).serializable_hash[:data][:attributes]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Abizvn
2
+ module Cms
3
+ class CategoryArticlesSerializer < CategoryLiteSerializer
4
+ attribute :articles do |entity, params|
5
+ next unless params[:articles].present?
6
+
7
+ articles = params[:articles].select { |x| x.category_id == entity.id }
8
+
9
+ articles.map do |article|
10
+ ArticleLiteSerializer.new(article).serializable_hash[:data][:attributes]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Abizvn
2
+ module Cms
3
+ class CategoryLiteSerializer
4
+ include JSONAPI::Serializer
5
+
6
+ attributes :id
7
+
8
+ attribute :code do |entity|
9
+ entity.general.code
10
+ end
11
+
12
+ attribute :value do |entity|
13
+ entity.general.value
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Abizvn
2
2
  module Cms
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
data/spec/rails_helper.rb CHANGED
@@ -35,6 +35,7 @@ end
35
35
 
36
36
  # Requires factories for testing
37
37
  Dir.glob(File.join(File.dirname(__FILE__), 'factories', '**', '*.rb')).each { |file| require file }
38
+ Dir.glob(File.join(File.dirname(__FILE__), 'support', '*.rb')).each { |file| require file }
38
39
 
39
40
  RSpec.configure do |config|
40
41
  Shoulda::Matchers.configure do |shoulda_config|
@@ -44,6 +45,8 @@ RSpec.configure do |config|
44
45
  end
45
46
  end
46
47
 
48
+ config.include Abizvn::Cms::CmsValidationHelpers
49
+
47
50
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
48
51
  config.fixture_paths = [
49
52
  Rails.root.join('spec/fixtures')
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Abizvn::Cms::ArticleLiteSerializer, type: :serializer do
4
+ describe "serialization" do
5
+ context 'order validations' do
6
+ let (:article1) { FactoryBot.create(:article) }
7
+ let (:serializer) { described_class.new(article1) }
8
+
9
+ it 'returns required attributes' do
10
+ data = serializer.serializable_hash[:data]
11
+ validate_article_lite_serialized_data(article1, data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Abizvn::Cms::ArticleSerializer, type: :serializer do
4
+ describe "serialization" do
5
+ context 'order validations' do
6
+ let (:article1) { FactoryBot.create(:article) }
7
+ let (:serializer) { described_class.new(article1) }
8
+
9
+ it 'returns required attributes' do
10
+ data = serializer.serializable_hash[:data]
11
+ validate_article_serialized_data(article1, data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Abizvn::Cms::CategoryArticlesSerializer, type: :serializer do
4
+ describe "serialization" do
5
+ context 'order validations' do
6
+ let!(:category1) { FactoryBot.create(:category) }
7
+ let!(:article1) { FactoryBot.create(:article, category: category1) }
8
+ let!(:article2) { FactoryBot.create(:article, category: category1) }
9
+ let!(:serializer) { described_class.new(category1, params: { articles: [article1, article2] }) }
10
+
11
+ it 'returns required attributes' do
12
+ data = serializer.serializable_hash[:data]
13
+ validate_category_articles_serialized_data(category1, data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Abizvn::Cms::CategoryLiteSerializer, type: :serializer do
4
+ describe "serialization" do
5
+ context 'order validations' do
6
+ let (:category1) { FactoryBot.create(:category) }
7
+ let (:serializer) { described_class.new(category1) }
8
+
9
+ it 'returns required attributes' do
10
+ data = serializer.serializable_hash[:data]
11
+ validate_category_lite_serialized_data(category1, data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,89 @@
1
+ module Abizvn
2
+ module Cms
3
+ module CmsValidationHelpers
4
+ def validate_category_articles_serialized_data(category, serialized_data)
5
+ expect(serialized_data).to have_key(:id)
6
+ expect(serialized_data).to have_key(:type)
7
+ expect(serialized_data).to have_key(:attributes)
8
+
9
+ expect(serialized_data[:id]).to eq(category.id.to_s)
10
+ expect(serialized_data[:type]).to eq(:category_articles)
11
+ validate_category_articles_data_attributes(category, serialized_data[:attributes])
12
+ end
13
+
14
+ def validate_category_articles_data_attributes(category, data_attributes)
15
+ validate_category_lite_data_attributes(category, data_attributes)
16
+
17
+ expect(data_attributes).to have_key(:articles)
18
+ expect(data_attributes[:articles].size).to eq(category.articles.size)
19
+
20
+ category.articles.each do |article|
21
+ article_data = data_attributes[:articles].find { |x| x[:id] == (article.slug || article.id) }
22
+ validate_article_lite_data_attributes(article, article_data)
23
+ end
24
+ end
25
+
26
+
27
+ def validate_category_lite_serialized_data(category, serialized_data)
28
+ expect(serialized_data).to have_key(:id)
29
+ expect(serialized_data).to have_key(:type)
30
+ expect(serialized_data).to have_key(:attributes)
31
+
32
+ expect(serialized_data[:id]).to eq(category.id.to_s)
33
+ expect(serialized_data[:type]).to eq(:category_lite)
34
+ validate_category_lite_data_attributes(category, serialized_data[:attributes])
35
+ end
36
+
37
+ def validate_category_lite_data_attributes(category, data_attributes)
38
+ expect(data_attributes).to have_key(:id)
39
+ expect(data_attributes).to have_key(:code)
40
+ expect(data_attributes).to have_key(:value)
41
+
42
+ expect(data_attributes[:id]).to eq(category.id)
43
+ expect(data_attributes[:code]).to eq(category.general.code)
44
+ expect(data_attributes[:value]).to eq(category.general.value)
45
+ end
46
+
47
+
48
+ def validate_article_lite_serialized_data(article, serialized_data)
49
+ expect(serialized_data).to have_key(:id)
50
+ expect(serialized_data).to have_key(:type)
51
+ expect(serialized_data).to have_key(:attributes)
52
+
53
+ expect(serialized_data[:id]).to eq(article.id.to_s)
54
+ expect(serialized_data[:type]).to eq(:article_lite)
55
+ validate_article_lite_data_attributes(article, serialized_data[:attributes])
56
+ end
57
+
58
+ def validate_article_lite_data_attributes(article, data_attributes)
59
+ expect(data_attributes).to have_key(:id)
60
+ expect(data_attributes).to have_key(:title)
61
+ expect(data_attributes).to have_key(:updated_at)
62
+
63
+ expect(data_attributes[:id]).to eq(article.slug || article.id)
64
+ expect(data_attributes[:title]).to eq(article.title)
65
+ expect(data_attributes[:updated_at]).to eq(article.updated_at)
66
+ end
67
+
68
+
69
+ def validate_article_serialized_data(article, serialized_data)
70
+ expect(serialized_data).to have_key(:id)
71
+ expect(serialized_data).to have_key(:type)
72
+ expect(serialized_data).to have_key(:attributes)
73
+
74
+ expect(serialized_data[:id]).to eq(article.id.to_s)
75
+ expect(serialized_data[:type]).to eq(:article)
76
+ validate_article_data_attributes(article, serialized_data[:attributes])
77
+ end
78
+
79
+ def validate_article_data_attributes(article, data_attributes)
80
+ validate_article_lite_data_attributes(article, data_attributes)
81
+
82
+ expect(data_attributes).to have_key(:description)
83
+ expect(data_attributes).to have_key(:created_at)
84
+ expect(data_attributes[:description]).to eq(article.description)
85
+ expect(data_attributes[:created_at]).to eq(article.created_at)
86
+ end
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abizvn-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan
@@ -169,6 +169,10 @@ files:
169
169
  - app/models/abizvn/cms/application_record.rb
170
170
  - app/models/abizvn/cms/article.rb
171
171
  - app/models/abizvn/cms/category.rb
172
+ - app/serializers/abizvn/cms/article_lite_serializer.rb
173
+ - app/serializers/abizvn/cms/article_serializer.rb
174
+ - app/serializers/abizvn/cms/category_articles_serializer.rb
175
+ - app/serializers/abizvn/cms/category_lite_serializer.rb
172
176
  - app/views/layouts/abizvn/cms/application.html.erb
173
177
  - config/routes.rb
174
178
  - db/migrate/20250117094449_create_category.rb
@@ -188,7 +192,12 @@ files:
188
192
  - spec/models/abizvn/cms/article_spec.rb
189
193
  - spec/models/abizvn/cms/category_spec.rb
190
194
  - spec/rails_helper.rb
195
+ - spec/serializers/abizvn/cms/article_lite_serializer_spec.rb
196
+ - spec/serializers/abizvn/cms/article_serializer_spec.rb
197
+ - spec/serializers/abizvn/cms/category_articles_serializer_spec.rb
198
+ - spec/serializers/abizvn/cms/category_lite_serializer_spec.rb
191
199
  - spec/spec_helper.rb
200
+ - spec/support/cms_validation_helpers.rb
192
201
  homepage: https://github.com/abizvncom/abizvn-cms
193
202
  licenses:
194
203
  - MIT