File tree Expand file tree Collapse file tree 7 files changed +62
-12
lines changed Expand file tree Collapse file tree 7 files changed +62
-12
lines changed Original file line number Diff line number Diff line change 1
1
class Staff ::PagesController < Staff ::ApplicationController
2
+ before_action :require_website
2
3
before_action :enable_website_subnav
3
4
before_action :set_page , except : :index
4
5
before_action :authorize_page , except : :index
@@ -98,4 +99,11 @@ def page_params
98
99
:unpublished_body
99
100
)
100
101
end
102
+
103
+ def require_website
104
+ return if current_website
105
+
106
+ redirect_to new_event_staff_website_path ( current_event ) ,
107
+ alert : "Please configure your website before attempting to create pages"
108
+ end
101
109
end
Original file line number Diff line number Diff line change @@ -6,19 +6,25 @@ class Staff::WebsitesController < Staff::ApplicationController
6
6
def new ; end
7
7
8
8
def create
9
- @website . update ( website_params )
10
-
11
- flash [ :success ] = "Website was successfully created."
12
- redirect_to edit_event_staff_website_path ( current_event )
9
+ if @website . update ( website_params )
10
+ flash [ :success ] = "Website was successfully created."
11
+ redirect_to edit_event_staff_website_path ( current_event )
12
+ else
13
+ flash [ :warning ] = "There were errors creating your website configuration"
14
+ render :new
15
+ end
13
16
end
14
17
15
18
def edit ; end
16
19
17
20
def update
18
- @website . update ( website_params )
19
-
20
- flash [ :success ] = "Website was successfully updated."
21
- redirect_to edit_event_staff_website_path ( current_event )
21
+ if @website . update ( website_params )
22
+ flash [ :success ] = "Website was successfully updated."
23
+ redirect_to edit_event_staff_website_path ( current_event )
24
+ else
25
+ flash [ :warning ] = "There were errors updating your website configuration"
26
+ render :edit
27
+ end
22
28
end
23
29
24
30
private
Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ class Website < ApplicationRecord
8
8
has_many :session_formats , through : :event
9
9
has_many :session_format_configs
10
10
11
-
12
- accepts_nested_attributes_for :fonts , reject_if : :all_blank , allow_destroy : true
11
+ accepts_nested_attributes_for :fonts ,
12
+ reject_if : -> ( font ) { font [ 'name' ] . blank? && font [ 'file' ] . blank? } ,
13
+ allow_destroy : true
13
14
accepts_nested_attributes_for :contents , reject_if : :all_blank , allow_destroy : true
14
15
accepts_nested_attributes_for :meta_data
15
16
accepts_nested_attributes_for :session_format_configs
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ class Website::Font < ApplicationRecord
3
3
4
4
has_one_attached :file
5
5
6
+ validates :file , :name , presence : true
7
+
6
8
scope :primary , -> { where ( primary : true ) }
7
9
scope :secondary , -> { where ( secondary : true ) }
8
10
end
Original file line number Diff line number Diff line change 40
40
= ff.input :name
41
41
= ff.hidden_field :session_format_id
42
42
43
- %div {"data-controller" : " nested-form" }
44
- %legend.fieldset-legend Fonts
43
+ %div {"data-controller" : " nested-form" , class: " nested-fonts " }
44
+ %h4 Fonts
45
45
%template{" data-nested-form-target" : " template" }
46
46
= f.simple_fields_for :fonts,
47
47
Website::Font.new,
Original file line number Diff line number Diff line change 47
47
expect ( current_path ) . to eq ( '/home' )
48
48
end
49
49
50
+ scenario "Organizer fails to add font file correctly" , :js do
51
+ website = create ( :website , event : event )
52
+
53
+ login_as ( organizer )
54
+ visit edit_event_staff_website_path ( event )
55
+
56
+ click_on ( "Add Font" )
57
+ click_on ( "Save" )
58
+ expect ( page ) . to have_content ( "Website was successfully updated" )
59
+
60
+ expect ( website . fonts . count ) . to eq ( 0 )
61
+
62
+ click_on ( "Add Font" )
63
+ within ( ".nested-fonts" ) { fill_in ( "Name" , with : "Times" ) }
64
+ click_on ( "Save" )
65
+
66
+ expect ( page ) . to have_content ( "There were errors updating your website configuration" )
67
+ within ( ".nested-fonts" ) { expect ( page ) . to have_content ( "can't be blank" ) }
68
+ end
69
+
50
70
scenario "Organizer configures tailwind with head content" , :js do
51
71
website = create ( :website , event : event )
52
72
home_page = create ( :page , website : website )
Original file line number Diff line number Diff line change 5
5
let ( :organizer ) { create ( :organizer , event : event ) }
6
6
let! ( :website ) { create ( :website , :with_details , event : event ) }
7
7
8
+ scenario "Organizer cannot access pages until website is created" do
9
+ website . destroy
10
+ login_as ( organizer )
11
+
12
+ visit event_path ( event )
13
+ within ( '.navbar' ) { click_on ( "Website" ) }
14
+ within ( '.website-subnav' ) { click_on ( "Pages" ) }
15
+
16
+ expect ( page ) . to have_content (
17
+ "Please configure your website before attempting to create pages"
18
+ )
19
+ end
20
+
8
21
scenario "Organizer creates and edits a website page" , :js do
9
22
login_as ( organizer )
10
23
You can’t perform that action at this time.
0 commit comments