archangel 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.jshintrc +3 -3
- data/.reek +9 -0
- data/Gemfile +1 -0
- data/app/assets/javascripts/archangel/object/flash.js +2 -2
- data/app/assets/javascripts/archangel/object/routes.js.erb +4 -0
- data/app/assets/javascripts/archangel/object/routes/backend.js +13 -2
- data/app/helpers/archangel/flash_helper.rb +1 -1
- data/app/models/archangel/asset.rb +1 -1
- data/app/models/archangel/collection.rb +3 -3
- data/app/models/archangel/page.rb +1 -1
- data/app/models/archangel/site.rb +3 -4
- data/app/models/archangel/user.rb +4 -2
- data/app/models/archangel/widget.rb +1 -1
- data/app/services/archangel/render_service.rb +1 -7
- data/app/services/archangel/template_render_service.rb +1 -3
- data/app/themes/default/assets/javascripts/default/backend.js +0 -2
- data/app/themes/default/assets/javascripts/default/backend/core.js +71 -2
- data/app/themes/default/assets/javascripts/default/common/flash.js +1 -1
- data/app/themes/default/views/layouts/auth.html.erb +2 -0
- data/app/themes/default/views/layouts/backend/_sidebar.html.erb +7 -5
- data/app/views/archangel/shared/_flash_messages.html.erb +3 -3
- data/app/views/devise/shared/_links.html.erb +7 -7
- data/db/migrate/20171003210347_create_archangel_users.rb +2 -2
- data/db/migrate/20171005224054_create_archangel_pages.rb +1 -1
- data/db/migrate/20171006175939_create_archangel_widgets.rb +1 -1
- data/db/migrate/20171006194044_create_archangel_collections.rb +1 -1
- data/db/seeds.rb +72 -7
- data/docs/Extension/Models.md +1 -1
- data/lib/archangel/command/templates/extension/config/routes.rb +1 -1
- data/lib/archangel/engine.rb +4 -0
- data/lib/archangel/version.rb +1 -1
- data/lib/generators/archangel/dummy/templates/config/database.yml +0 -12
- data/spec/lib/archangel/command/extension_spec.rb +1 -1
- data/spec/models/archangel/asset_spec.rb +11 -14
- data/spec/models/archangel/collection_spec.rb +37 -7
- data/spec/models/archangel/entry_spec.rb +8 -6
- data/spec/models/archangel/field_spec.rb +21 -10
- data/spec/models/archangel/page_spec.rb +65 -24
- data/spec/models/archangel/site_spec.rb +45 -2
- data/spec/models/archangel/template_spec.rb +16 -9
- data/spec/models/archangel/user_spec.rb +44 -15
- data/spec/models/archangel/widget_spec.rb +44 -10
- data/spec/policies/archangel/asset_policy_spec.rb +26 -9
- data/spec/policies/archangel/collection_policy_spec.rb +23 -8
- data/spec/policies/archangel/entries_policy_spec.rb +26 -9
- data/spec/policies/archangel/page_policy_spec.rb +23 -8
- data/spec/policies/archangel/site_policy_spec.rb +11 -9
- data/spec/policies/archangel/template_policy_spec.rb +23 -8
- data/spec/policies/archangel/user_policy_spec.rb +23 -8
- data/spec/policies/archangel/widget_policy_spec.rb +23 -8
- metadata +2 -4
- data/app/themes/default/assets/javascripts/default/common/navigation.js +0 -30
- data/app/themes/default/assets/javascripts/default/common/sidebar.js +0 -114
@@ -4,8 +4,51 @@ require "rails_helper"
|
|
4
4
|
|
5
5
|
module Archangel
|
6
6
|
RSpec.describe Site, type: :model do
|
7
|
-
|
8
|
-
it {
|
7
|
+
context "validations" do
|
8
|
+
it { is_expected.to validate_presence_of(:locale) }
|
9
|
+
it { is_expected.to validate_presence_of(:name) }
|
10
|
+
|
11
|
+
it { is_expected.to allow_value("").for(:theme) }
|
12
|
+
|
13
|
+
it "allows certain languages" do
|
14
|
+
expect(subject)
|
15
|
+
.to validate_inclusion_of(:locale).in_array(Archangel::LANGUAGES)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "allows certain languages" do
|
19
|
+
expect(subject)
|
20
|
+
.to validate_inclusion_of(:theme).in_array(Archangel.themes)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it { is_expected.to have_many(:assets) }
|
25
|
+
it { is_expected.to have_many(:collections) }
|
26
|
+
it { is_expected.to have_many(:pages) }
|
27
|
+
it { is_expected.to have_many(:templates) }
|
28
|
+
it { is_expected.to have_many(:users) }
|
29
|
+
it { is_expected.to have_many(:widgets) }
|
30
|
+
it { is_expected.to have_many(:entries).through(:collections) }
|
31
|
+
it { is_expected.to have_many(:fields).through(:collections) }
|
32
|
+
|
33
|
+
context ".current" do
|
34
|
+
it "returns an existing object" do
|
35
|
+
resource = create(:site, name: "My Awesome New Site")
|
36
|
+
|
37
|
+
expect(described_class.current).to eq(resource)
|
38
|
+
expect(described_class.current.name).to eq("My Awesome New Site")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns a new object" do
|
42
|
+
expect(described_class.current.name).to eq("Archangel")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#to_liquid" do
|
47
|
+
it "returns a Liquid object" do
|
48
|
+
resource = build(:site)
|
49
|
+
|
50
|
+
expect(resource.to_liquid).to be_a(Archangel::Liquid::Drops::SiteDrop)
|
51
|
+
end
|
9
52
|
end
|
10
53
|
end
|
11
54
|
end
|
@@ -5,20 +5,27 @@ require "rails_helper"
|
|
5
5
|
module Archangel
|
6
6
|
RSpec.describe Template, type: :model do
|
7
7
|
context "validations" do
|
8
|
-
it {
|
9
|
-
it {
|
8
|
+
it { is_expected.to validate_presence_of(:content) }
|
9
|
+
it { is_expected.to validate_presence_of(:name) }
|
10
10
|
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it { expect(subject).not_to allow_value(nil).for(:partial) }
|
11
|
+
it { is_expected.to allow_value(true).for(:partial) }
|
12
|
+
it { is_expected.to allow_value(false).for(:partial) }
|
14
13
|
|
15
|
-
it {
|
16
|
-
|
14
|
+
it { is_expected.to_not allow_value(nil).for(:partial) }
|
15
|
+
|
16
|
+
it { is_expected.to allow_value("{{ foo }}").for(:content) }
|
17
|
+
it { is_expected.to_not allow_value("{{ foo }").for(:content) }
|
17
18
|
end
|
18
19
|
|
19
20
|
context "associations" do
|
20
|
-
it {
|
21
|
-
|
21
|
+
it { is_expected.to belong_to(:site) }
|
22
|
+
|
23
|
+
it "belongs to Template" do
|
24
|
+
expect(subject).to(
|
25
|
+
belong_to(:parent).conditions(partial: false)
|
26
|
+
.class_name("Archangel::Template")
|
27
|
+
)
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -7,27 +7,33 @@ module Archangel
|
|
7
7
|
context "callbacks" do
|
8
8
|
let(:resource) { create(:user) }
|
9
9
|
|
10
|
-
it
|
11
|
-
|
12
|
-
|
10
|
+
it { is_expected.to callback(:parameterize_username).before(:validation) }
|
11
|
+
|
12
|
+
it { is_expected.to callback(:column_default).after(:initialize) }
|
13
13
|
|
14
|
-
it {
|
15
|
-
it { expect(resource).to callback(:column_reset).after(:destroy) }
|
14
|
+
it { is_expected.to callback(:column_reset).after(:destroy) }
|
16
15
|
end
|
17
16
|
|
18
17
|
context "validations" do
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
18
|
+
it { is_expected.to validate_presence_of(:email) }
|
19
|
+
it { is_expected.to validate_presence_of(:name) }
|
20
|
+
it { is_expected.to validate_presence_of(:password).on(:create) }
|
21
|
+
it { is_expected.to validate_presence_of(:role) }
|
22
|
+
it { is_expected.to validate_presence_of(:username) }
|
23
|
+
|
24
|
+
it { is_expected.to validate_length_of(:password).is_at_least(8) }
|
25
|
+
|
26
|
+
it { is_expected.to validate_presence_of(:password).on(:update) }
|
24
27
|
|
25
|
-
it
|
28
|
+
it "has a unique username scoped to Site" do
|
29
|
+
resource = build(:user)
|
26
30
|
|
27
|
-
|
28
|
-
|
31
|
+
expect(resource).to(
|
32
|
+
validate_uniqueness_of(:username).scoped_to(:site_id).case_insensitive
|
33
|
+
)
|
34
|
+
end
|
29
35
|
|
30
|
-
it do
|
36
|
+
it "allows certain roles" do
|
31
37
|
expect(subject)
|
32
38
|
.to validate_inclusion_of(:role).in_array(Archangel::ROLES)
|
33
39
|
end
|
@@ -60,7 +66,30 @@ module Archangel
|
|
60
66
|
end
|
61
67
|
|
62
68
|
context "associations" do
|
63
|
-
it {
|
69
|
+
it { is_expected.to belong_to(:site) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "#to_param" do
|
73
|
+
it "uses `slug` as the identifier for routes" do
|
74
|
+
resource = build(:user, username: "foo")
|
75
|
+
|
76
|
+
expect(resource.to_param).to eq("foo")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "#column_reset" do
|
81
|
+
before { ::Timecop.freeze }
|
82
|
+
after { ::Timecop.return }
|
83
|
+
|
84
|
+
it "resets `slug` to `slug` + current time" do
|
85
|
+
resource = create(:user)
|
86
|
+
|
87
|
+
username = resource.username
|
88
|
+
|
89
|
+
resource.destroy!
|
90
|
+
|
91
|
+
expect(resource.username).to eq "#{Time.current.to_i}_#{username}"
|
92
|
+
end
|
64
93
|
end
|
65
94
|
end
|
66
95
|
end
|
@@ -5,25 +5,59 @@ require "rails_helper"
|
|
5
5
|
module Archangel
|
6
6
|
RSpec.describe Widget, type: :model do
|
7
7
|
context "callbacks" do
|
8
|
-
it {
|
8
|
+
it { is_expected.to callback(:parameterize_slug).before(:validation) }
|
9
9
|
|
10
|
-
it {
|
10
|
+
it { is_expected.to callback(:column_reset).after(:destroy) }
|
11
11
|
end
|
12
12
|
|
13
13
|
context "validations" do
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
14
|
+
it { is_expected.to validate_presence_of(:content) }
|
15
|
+
it { is_expected.to validate_presence_of(:name) }
|
16
|
+
it { is_expected.to validate_presence_of(:slug) }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to allow_value("{{ foo }}").for(:content) }
|
19
|
+
it { is_expected.to_not allow_value("{{ foo }").for(:content) }
|
19
20
|
|
20
|
-
it
|
21
|
-
|
21
|
+
it "has a unique slug scoped to Site" do
|
22
|
+
resource = build(:widget)
|
23
|
+
|
24
|
+
expect(resource)
|
25
|
+
.to validate_uniqueness_of(:slug).scoped_to(:site_id).case_insensitive
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
context "associations" do
|
25
|
-
it {
|
26
|
-
|
30
|
+
it { is_expected.to belong_to(:site) }
|
31
|
+
|
32
|
+
it "belongs to Template" do
|
33
|
+
expect(subject).to(
|
34
|
+
belong_to(:template).conditions(partial: true)
|
35
|
+
.class_name("Archangel::Template")
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#to_param" do
|
41
|
+
it "uses `slug` as the identifier for routes" do
|
42
|
+
resource = build(:widget, slug: "foo")
|
43
|
+
|
44
|
+
expect(resource.to_param).to eq("foo")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#column_reset" do
|
49
|
+
before { ::Timecop.freeze }
|
50
|
+
after { ::Timecop.return }
|
51
|
+
|
52
|
+
it "resets `slug` to `slug` + current time" do
|
53
|
+
resource = create(:widget)
|
54
|
+
|
55
|
+
slug = resource.slug
|
56
|
+
|
57
|
+
resource.destroy!
|
58
|
+
|
59
|
+
expect(resource.slug).to eq "#{Time.current.to_i}_#{slug}"
|
60
|
+
end
|
27
61
|
end
|
28
62
|
end
|
29
63
|
end
|
@@ -6,17 +6,34 @@ module Archangel
|
|
6
6
|
RSpec.describe AssetPolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:asset) }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
it { should permit(:create) }
|
15
|
-
it { should permit(:new) }
|
16
|
-
it { should permit(:update) }
|
17
|
-
it { should permit(:edit) }
|
18
|
-
it { should permit(:destroy) }
|
11
|
+
context "with `admin` role" do
|
12
|
+
let(:user) { create(:user, :admin) }
|
19
13
|
|
20
|
-
|
14
|
+
it { is_expected.to permit(:index) }
|
15
|
+
it { is_expected.to permit(:show) }
|
16
|
+
it { is_expected.to permit(:new) }
|
17
|
+
it { is_expected.to permit(:create) }
|
18
|
+
it { is_expected.to permit(:edit) }
|
19
|
+
it { is_expected.to permit(:update) }
|
20
|
+
it { is_expected.to permit(:destroy) }
|
21
|
+
|
22
|
+
it { is_expected.to permit(:wysiwyg) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with `editor` role" do
|
26
|
+
let(:user) { create(:user, :editor) }
|
27
|
+
|
28
|
+
it { is_expected.to permit(:index) }
|
29
|
+
it { is_expected.to permit(:show) }
|
30
|
+
it { is_expected.to permit(:new) }
|
31
|
+
it { is_expected.to permit(:create) }
|
32
|
+
it { is_expected.to permit(:edit) }
|
33
|
+
it { is_expected.to permit(:update) }
|
34
|
+
it { is_expected.to permit(:destroy) }
|
35
|
+
|
36
|
+
it { is_expected.to permit(:wysiwyg) }
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
@@ -6,15 +6,30 @@ module Archangel
|
|
6
6
|
RSpec.describe CollectionPolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:collection) }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
context "with `admin` role" do
|
12
|
+
let(:user) { create(:user, :admin) }
|
13
|
+
|
14
|
+
it { is_expected.to permit(:index) }
|
15
|
+
it { is_expected.to permit(:show) }
|
16
|
+
it { is_expected.to permit(:new) }
|
17
|
+
it { is_expected.to permit(:create) }
|
18
|
+
it { is_expected.to permit(:edit) }
|
19
|
+
it { is_expected.to permit(:update) }
|
20
|
+
it { is_expected.to permit(:destroy) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with `editor` role" do
|
24
|
+
let(:user) { create(:user, :editor) }
|
25
|
+
|
26
|
+
it { is_expected.to permit(:index) }
|
27
|
+
it { is_expected.to permit(:show) }
|
28
|
+
it { is_expected.to permit(:new) }
|
29
|
+
it { is_expected.to permit(:create) }
|
30
|
+
it { is_expected.to permit(:edit) }
|
31
|
+
it { is_expected.to permit(:update) }
|
32
|
+
it { is_expected.to permit(:destroy) }
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|
@@ -6,17 +6,34 @@ module Archangel
|
|
6
6
|
RSpec.describe EntryPolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:entry) }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
it { should permit(:create) }
|
15
|
-
it { should permit(:new) }
|
16
|
-
it { should permit(:update) }
|
17
|
-
it { should permit(:edit) }
|
18
|
-
it { should permit(:destroy) }
|
11
|
+
context "with `admin` role" do
|
12
|
+
let(:user) { create(:user, :admin) }
|
19
13
|
|
20
|
-
|
14
|
+
it { is_expected.to permit(:index) }
|
15
|
+
it { is_expected.to permit(:show) }
|
16
|
+
it { is_expected.to permit(:new) }
|
17
|
+
it { is_expected.to permit(:create) }
|
18
|
+
it { is_expected.to permit(:edit) }
|
19
|
+
it { is_expected.to permit(:update) }
|
20
|
+
it { is_expected.to permit(:destroy) }
|
21
|
+
|
22
|
+
it { is_expected.to permit(:sort) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with `editor` role" do
|
26
|
+
let(:user) { create(:user, :editor) }
|
27
|
+
|
28
|
+
it { is_expected.to permit(:index) }
|
29
|
+
it { is_expected.to permit(:show) }
|
30
|
+
it { is_expected.to permit(:new) }
|
31
|
+
it { is_expected.to permit(:create) }
|
32
|
+
it { is_expected.to permit(:edit) }
|
33
|
+
it { is_expected.to permit(:update) }
|
34
|
+
it { is_expected.to permit(:destroy) }
|
35
|
+
|
36
|
+
it { is_expected.to permit(:sort) }
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
@@ -6,15 +6,30 @@ module Archangel
|
|
6
6
|
RSpec.describe PagePolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:page) }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
context "with `admin` role" do
|
12
|
+
let(:user) { create(:user, :admin) }
|
13
|
+
|
14
|
+
it { is_expected.to permit(:index) }
|
15
|
+
it { is_expected.to permit(:show) }
|
16
|
+
it { is_expected.to permit(:new) }
|
17
|
+
it { is_expected.to permit(:create) }
|
18
|
+
it { is_expected.to permit(:edit) }
|
19
|
+
it { is_expected.to permit(:update) }
|
20
|
+
it { is_expected.to permit(:destroy) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with `editor` role" do
|
24
|
+
let(:user) { create(:user, :editor) }
|
25
|
+
|
26
|
+
it { is_expected.to permit(:index) }
|
27
|
+
it { is_expected.to permit(:show) }
|
28
|
+
it { is_expected.to permit(:new) }
|
29
|
+
it { is_expected.to permit(:create) }
|
30
|
+
it { is_expected.to permit(:edit) }
|
31
|
+
it { is_expected.to permit(:update) }
|
32
|
+
it { is_expected.to permit(:destroy) }
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|
@@ -6,25 +6,27 @@ module Archangel
|
|
6
6
|
RSpec.describe SitePolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:site) }
|
11
10
|
|
12
|
-
it { should permit(:show) }
|
13
|
-
|
14
11
|
context "with `admin` role" do
|
15
12
|
let(:user) { create(:user, :admin) }
|
16
13
|
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
14
|
+
it { is_expected.to permit(:show) }
|
15
|
+
it { is_expected.to permit(:update) }
|
16
|
+
it { is_expected.to permit(:edit) }
|
17
|
+
|
18
|
+
it { is_expected.to permit(:sample) }
|
20
19
|
end
|
21
20
|
|
22
21
|
context "with `editor` role" do
|
23
22
|
let(:user) { create(:user, :editor) }
|
24
23
|
|
25
|
-
it {
|
26
|
-
|
27
|
-
it {
|
24
|
+
it { is_expected.to permit(:show) }
|
25
|
+
|
26
|
+
it { is_expected.to permit(:sample) }
|
27
|
+
|
28
|
+
it { is_expected.to_not permit(:update) }
|
29
|
+
it { is_expected.to_not permit(:edit) }
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -6,15 +6,30 @@ module Archangel
|
|
6
6
|
RSpec.describe TemplatePolicy, type: :policy do
|
7
7
|
subject { described_class.new(user, record) }
|
8
8
|
|
9
|
-
let(:user) { create(:user) }
|
10
9
|
let(:record) { create(:template) }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
context "with `admin` role" do
|
12
|
+
let(:user) { create(:user, :admin) }
|
13
|
+
|
14
|
+
it { is_expected.to permit(:index) }
|
15
|
+
it { is_expected.to permit(:show) }
|
16
|
+
it { is_expected.to permit(:new) }
|
17
|
+
it { is_expected.to permit(:create) }
|
18
|
+
it { is_expected.to permit(:edit) }
|
19
|
+
it { is_expected.to permit(:update) }
|
20
|
+
it { is_expected.to permit(:destroy) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with `editor` role" do
|
24
|
+
let(:user) { create(:user, :editor) }
|
25
|
+
|
26
|
+
it { is_expected.to permit(:index) }
|
27
|
+
it { is_expected.to permit(:show) }
|
28
|
+
it { is_expected.to permit(:new) }
|
29
|
+
it { is_expected.to permit(:create) }
|
30
|
+
it { is_expected.to permit(:edit) }
|
31
|
+
it { is_expected.to permit(:update) }
|
32
|
+
it { is_expected.to permit(:destroy) }
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|