|
6 | 6 | subject { described_class.call(site: site, type: type) } |
7 | 7 |
|
8 | 8 | let(:site) { create(:site, locales: [{ label: 'English', prefix: 'en' }, { label: 'French', prefix: 'fr' }]) } |
| 9 | + let(:global_store) { create(:sections_content_store) } |
9 | 10 | let(:type) { 'hero' } |
10 | 11 |
|
11 | | - describe 'when the site has sections of the specified type' do |
| 12 | + describe 'when the site has global sections of the specified type' do |
12 | 13 | before do |
13 | | - site.update!(sections_translations: { |
14 | | - en: [ |
15 | | - { type: 'hero', settings: [{ value: 'Hello' }] }, |
16 | | - { type: 'footer', settings: [{ value: 'Footer' }] } |
17 | | - ], |
18 | | - fr: [ |
19 | | - { type: 'hero', settings: [{ value: 'Bonjour' }] }, |
20 | | - { type: 'footer', settings: [{ value: 'Pied de page' }] } |
21 | | - ] |
22 | | - }) |
| 14 | + global_store.update!(sections_translations: { |
| 15 | + en: [ |
| 16 | + { type: 'hero', settings: [{ value: 'Hello' }] }, |
| 17 | + { type: 'footer', settings: [{ value: 'Footer' }] } |
| 18 | + ], |
| 19 | + fr: [ |
| 20 | + { type: 'hero', settings: [{ value: 'Bonjour' }] }, |
| 21 | + { type: 'footer', settings: [{ value: 'Pied de page' }] } |
| 22 | + ] |
| 23 | + }) |
23 | 24 | end |
24 | 25 |
|
25 | 26 | it 'removes the sections of the specified type in all locales and returns the count' do |
|
28 | 29 |
|
29 | 30 | # Check English locale |
30 | 31 | Maglev::I18n.with_locale(:en) do |
31 | | - sections = site.reload.sections |
| 32 | + sections = global_store.reload.sections |
32 | 33 | expect(sections.length).to eq(1) |
33 | 34 | expect(sections.first['type']).to eq('footer') |
34 | 35 | expect(sections.first['settings'].first['value']).to eq('Footer') |
35 | 36 | end |
36 | 37 |
|
37 | 38 | # Check French locale |
38 | 39 | Maglev::I18n.with_locale(:fr) do |
39 | | - sections = site.reload.sections |
| 40 | + sections = global_store.reload.sections |
40 | 41 | expect(sections.length).to eq(1) |
41 | 42 | expect(sections.first['type']).to eq('footer') |
42 | 43 | expect(sections.first['settings'].first['value']).to eq('Pied de page') |
|
46 | 47 |
|
47 | 48 | describe 'when the site has no sections of the specified type' do |
48 | 49 | before do |
49 | | - site.update!(sections_translations: { |
50 | | - en: [{ type: 'footer', settings: [{ value: 'Footer' }] }], |
51 | | - fr: [{ type: 'footer', settings: [{ value: 'Pied de page' }] }] |
52 | | - }) |
| 50 | + global_store.update!(sections_translations: { |
| 51 | + en: [{ type: 'footer', settings: [{ value: 'Footer' }] }], |
| 52 | + fr: [{ type: 'footer', settings: [{ value: 'Pied de page' }] }] |
| 53 | + }) |
53 | 54 | end |
54 | 55 |
|
55 | 56 | it 'does not modify the sections and returns zero' do |
56 | 57 | expect(subject).to eq(0) |
57 | 58 |
|
58 | 59 | # Check English locale |
59 | 60 | Maglev::I18n.with_locale(:en) do |
60 | | - sections = site.reload.sections |
| 61 | + sections = global_store.reload.sections |
61 | 62 | expect(sections.length).to eq(1) |
62 | 63 | expect(sections.first['type']).to eq('footer') |
63 | 64 | expect(sections.first['settings'].first['value']).to eq('Footer') |
64 | 65 | end |
65 | 66 |
|
66 | 67 | # Check French locale |
67 | 68 | Maglev::I18n.with_locale(:fr) do |
68 | | - sections = site.reload.sections |
| 69 | + sections = global_store.reload.sections |
69 | 70 | expect(sections.length).to eq(1) |
70 | 71 | expect(sections.first['type']).to eq('footer') |
71 | 72 | expect(sections.first['settings'].first['value']).to eq('Pied de page') |
|
74 | 75 | end |
75 | 76 |
|
76 | 77 | describe 'when removing all sections of a type' do |
77 | | - let!(:page) { create(:page) } |
| 78 | + let(:page) { create(:page) } |
| 79 | + let(:page_store) { page.stores.first } |
78 | 80 |
|
79 | 81 | before do |
80 | 82 | # Set up sections for both site and page |
81 | | - site.update!(sections_translations: { |
82 | | - en: [{ type: 'hero' }, { type: 'footer' }], |
83 | | - fr: [{ type: 'hero' }, { type: 'footer' }] |
84 | | - }) |
85 | | - |
86 | | - page.update!(sections_translations: { |
87 | | - en: [{ type: 'hero' }, { type: 'banner' }], |
88 | | - fr: [{ type: 'hero' }, { type: 'banner' }] |
89 | | - }) |
| 83 | + global_store.update!(sections_translations: { |
| 84 | + en: [{ type: 'hero' }, { type: 'footer' }], |
| 85 | + fr: [{ type: 'hero' }, { type: 'footer' }] |
| 86 | + }) |
| 87 | + |
| 88 | + page_store.update!(sections_translations: { |
| 89 | + en: [{ type: 'hero' }, { type: 'banner' }], |
| 90 | + fr: [{ type: 'hero' }, { type: 'banner' }] |
| 91 | + }) |
90 | 92 | end |
91 | 93 |
|
92 | 94 | it 'removes the sections from both site and pages and returns total count' do |
|
95 | 97 |
|
96 | 98 | # Check site sections |
97 | 99 | Maglev::I18n.with_locale(:en) do |
98 | | - expect(site.reload.sections.map { |s| s['type'] }).to eq(['footer']) |
| 100 | + expect(global_store.reload.sections.map { |s| s['type'] }).to eq(['footer']) |
99 | 101 | end |
100 | 102 |
|
101 | 103 | # Check page sections |
102 | 104 | Maglev::I18n.with_locale(:en) do |
103 | | - expect(page.reload.sections.map { |s| s['type'] }).to eq(['banner']) |
| 105 | + expect(page_store.reload.sections.map { |s| s['type'] }).to eq(['banner']) |
104 | 106 | end |
105 | 107 | end |
106 | 108 | end |
|
0 commit comments