Skip to content

Commit 63555c8

Browse files
authored
Merge branch 'main' into dependabot/bundler/rubocop-rails-2.33.1
2 parents d518b19 + aaea780 commit 63555c8

File tree

91 files changed

+840
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+840
-130
lines changed

.env.prod.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PORT=5000
2424

2525
RACK_ENV=production
2626
RAILS_ENV=production
27-
RAILS_LOG_LEVEL=debug
27+
RAILS_LOG_LEVEL=info
2828
RAILS_LOG_TO_STDOUT=true
2929
RAILS_SERVE_STATIC_FILES=true
3030

.github/workflows/rubyonrails.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- ruby: '3.4.4'
1414
rails: '7.1.5.1'
1515
allowed_failure: false # ✅ required
16-
# - ruby: '3.4.4'
17-
# rails: '7.2'
18-
# allowed_failure: true # ⚠️ allowed to fail
1916
- ruby: '3.4.4'
20-
rails: '8.0'
17+
rails: '7.2.2.1'
18+
allowed_failure: false # ⚠️ allowed to fail
19+
- ruby: '3.4.4'
20+
rails: '8.0.2'
2121
allowed_failure: true # ⚠️ allowed to fail
2222

2323
env:
@@ -89,6 +89,22 @@ jobs:
8989
bundle exec rspec
9090
continue-on-error: ${{ matrix.allowed_failure }}
9191

92+
- name: Generate coverage badge
93+
if: ${{ github.ref == 'refs/heads/main' && success() }}
94+
continue-on-error: true
95+
run: |
96+
COVERAGE=$(jq -r '.result.covered_percent' coverage/.last_run.json)
97+
COLOR=$(node -e "cov=parseFloat(process.argv[1]);console.log(cov>=90?'green':cov>=75?'orange':'red')" $COVERAGE)
98+
npx badgen-cli coverage ${COVERAGE}% -c $COLOR > coverage.svg
99+
100+
- name: Commit badge
101+
if: ${{ github.ref == 'refs/heads/main' && success() }}
102+
continue-on-error: true
103+
uses: stefanzweifel/git-auto-commit-action@v5
104+
with:
105+
commit_message: "chore: update coverage badge"
106+
file_pattern: coverage.svg
107+
92108
# ── style & security jobs (unchanged) ───────────────────────────────────────
93109
rubocop:
94110
runs-on: ubuntu-latest

app/controllers/better_together/application_controller.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
99

1010
protect_from_forgery with: :exception
1111

12+
layout :determine_layout
13+
1214
before_action :check_platform_setup
1315
before_action :set_locale
1416
before_action :store_user_location!, if: :storable_location?
@@ -23,12 +25,13 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
2325
Rack::MiniProfiler.authorize_request if current_user&.permitted_to?('manage_platform')
2426
end
2527

26-
rescue_from ActiveRecord::RecordNotFound, with: :handle404
27-
rescue_from ActionController::RoutingError, with: :handle404
28+
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
29+
rescue_from ActionController::RoutingError, with: :render_not_found
2830
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2931
rescue_from StandardError, with: :handle_error
3032

31-
helper_method :current_invitation, :default_url_options, :valid_platform_invitation_token_present?
33+
helper_method :current_invitation, :default_url_options, :valid_platform_invitation_token_present?,
34+
:turbo_native_app?
3235

3336
def self.default_url_options
3437
super.merge(locale: I18n.locale)
@@ -126,11 +129,11 @@ def valid_platform_invitation_token_present?
126129

127130
private
128131

129-
def handle404
130-
render_404
132+
def disallow_robots
133+
view_context.content_for(:meta_robots, 'noindex,nofollow')
131134
end
132135

133-
def render_404 # rubocop:todo Naming/VariableNumber
136+
def render_not_found
134137
render 'errors/404', status: :not_found
135138
end
136139

@@ -254,5 +257,13 @@ def metric_viewable_type
254257
def metric_viewable_id
255258
metric_viewable&.id
256259
end
260+
261+
def determine_layout
262+
turbo_native_app? ? 'better_together/turbo_native' : 'better_together/application'
263+
end
264+
265+
def turbo_native_app?
266+
request.user_agent.to_s.include?('Turbo Native')
267+
end
257268
end
258269
end

app/controllers/better_together/content/blocks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Content
55
# CRUD for content blocks independently of pages
66
class BlocksController < ResourceController
77
before_action :authenticate_user!
8+
before_action :disallow_robots
89
before_action :set_block, only: %i[show edit update destroy]
910
before_action only: %i[index], if: -> { Rails.env.development? } do
1011
# Make sure that all BLock subclasses are loaded in dev to generate new block buttons

app/controllers/better_together/content/page_blocks_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Content
55
# CRUD for page blocks
66
class PageBlocksController < ApplicationController
77
before_action :authenticate_user!
8+
before_action :disallow_robots
89
before_action :set_page
910

1011
def new

app/controllers/better_together/conversations_controller.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module BetterTogether
44
# Handles managing conversations
55
class ConversationsController < ApplicationController
66
before_action :authenticate_user!
7+
before_action :disallow_robots
78
before_action :set_conversations, only: %i[index new show]
89
before_action :set_conversation, only: %i[show]
910

@@ -20,7 +21,7 @@ def new
2021
authorize @conversation
2122
end
2223

23-
def create # rubocop:todo Metrics/MethodLength
24+
def create # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
2425
@conversation = Conversation.new(conversation_params.merge(creator: helpers.current_person))
2526

2627
authorize @conversation
@@ -33,7 +34,16 @@ def create # rubocop:todo Metrics/MethodLength
3334
format.html { redirect_to @conversation }
3435
end
3536
else
36-
render :new
37+
respond_to do |format|
38+
format.turbo_stream do
39+
render turbo_stream: turbo_stream.update(
40+
'form_errors',
41+
partial: 'layouts/better_together/errors',
42+
locals: { object: @conversation }
43+
)
44+
end
45+
format.html { render :new }
46+
end
3747
end
3848
end
3949

app/controllers/better_together/friendly_resource_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def set_resource_instance
2323
# 2. By friendly on all available locales
2424
@resource ||= find_by_translatable
2525

26-
handle404 && return if @resource.nil?
26+
render_not_found && return if @resource.nil?
2727

2828
@resource
2929
end

app/controllers/better_together/geography/continents_controller.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,40 @@ def new
2222
def edit; end
2323

2424
# POST /geography/continents
25-
def create
25+
def create # rubocop:todo Metrics/MethodLength
2626
@geography_continent = Geography::Continent.new(geography_continent_params)
2727

2828
if @geography_continent.save
2929
redirect_to @geography_continent, notice: 'Continent was successfully created.'
3030
else
31-
render :new, status: :unprocessable_entity
31+
respond_to do |format|
32+
format.turbo_stream do
33+
render turbo_stream: turbo_stream.update(
34+
'form_errors',
35+
partial: 'layouts/better_together/errors',
36+
locals: { object: @geography_continent }
37+
)
38+
end
39+
format.html { render :new, status: :unprocessable_entity }
40+
end
3241
end
3342
end
3443

3544
# PATCH/PUT /geography/continents/1
36-
def update
45+
def update # rubocop:todo Metrics/MethodLength
3746
if @geography_continent.update(geography_continent_params)
3847
redirect_to @geography_continent, notice: 'Continent was successfully updated.', status: :see_other
3948
else
40-
render :edit, status: :unprocessable_entity
49+
respond_to do |format|
50+
format.turbo_stream do
51+
render turbo_stream: turbo_stream.update(
52+
'form_errors',
53+
partial: 'layouts/better_together/errors',
54+
locals: { object: @geography_continent }
55+
)
56+
end
57+
format.html { render :edit, status: :unprocessable_entity }
58+
end
4159
end
4260
end
4361

app/controllers/better_together/geography/countries_controller.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,41 @@ def new
2828
def edit; end
2929

3030
# POST /geography/countries
31-
def create
31+
def create # rubocop:todo Metrics/MethodLength
3232
@geography_country = resource_class.new(geography_country_params)
3333
authorize_geography_country
3434

3535
if @geography_country.save
3636
redirect_to @geography_country, notice: 'Country was successfully created.', status: :see_other
3737
else
38-
render :new, status: :unprocessable_entity
38+
respond_to do |format|
39+
format.turbo_stream do
40+
render turbo_stream: turbo_stream.update(
41+
'form_errors',
42+
partial: 'layouts/better_together/errors',
43+
locals: { object: @geography_country }
44+
)
45+
end
46+
format.html { render :new, status: :unprocessable_entity }
47+
end
3948
end
4049
end
4150

4251
# PATCH/PUT /geography/countries/1
43-
def update
52+
def update # rubocop:todo Metrics/MethodLength
4453
if @geography_country.update(geography_country_params)
4554
redirect_to @geography_country, notice: 'Country was successfully updated.', status: :see_other
4655
else
47-
render :edit, status: :unprocessable_entity
56+
respond_to do |format|
57+
format.turbo_stream do
58+
render turbo_stream: turbo_stream.update(
59+
'form_errors',
60+
partial: 'layouts/better_together/errors',
61+
locals: { object: @geography_country }
62+
)
63+
end
64+
format.html { render :edit, status: :unprocessable_entity }
65+
end
4866
end
4967
end
5068

app/controllers/better_together/geography/region_settlements_controller.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,41 @@ def new
2222
def edit; end
2323

2424
# POST /geography/region_settlements
25-
def create
25+
def create # rubocop:todo Metrics/MethodLength
2626
@geography_region_settlement = Geography::RegionSettlement.new(geography_region_settlement_params)
2727

2828
if @geography_region_settlement.save
2929
redirect_to @geography_region_settlement, notice: 'Region settlement was successfully created.'
3030
else
31-
render :new, status: :unprocessable_entity
31+
respond_to do |format|
32+
format.turbo_stream do
33+
render turbo_stream: turbo_stream.update(
34+
'form_errors',
35+
partial: 'layouts/better_together/errors',
36+
locals: { object: @geography_region_settlement }
37+
)
38+
end
39+
format.html { render :new, status: :unprocessable_entity }
40+
end
3241
end
3342
end
3443

3544
# PATCH/PUT /geography/region_settlements/1
36-
def update
45+
def update # rubocop:todo Metrics/MethodLength
3746
if @geography_region_settlement.update(geography_region_settlement_params)
3847
redirect_to @geography_region_settlement, notice: 'Region settlement was successfully updated.',
3948
status: :see_other
4049
else
41-
render :edit, status: :unprocessable_entity
50+
respond_to do |format|
51+
format.turbo_stream do
52+
render turbo_stream: turbo_stream.update(
53+
'form_errors',
54+
partial: 'layouts/better_together/errors',
55+
locals: { object: @geography_region_settlement }
56+
)
57+
end
58+
format.html { render :edit, status: :unprocessable_entity }
59+
end
4260
end
4361
end
4462

0 commit comments

Comments
 (0)