Skip to content

Commit

Permalink
Merge pull request #67 from AlchemyCMS/add-anchors
Browse files Browse the repository at this point in the history
Add dom_id attribute to ingredient headline and text serializers
  • Loading branch information
tvdeyen authored Dec 16, 2022
2 parents 48b04c8 + 6313241 commit d3d5091
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 44 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/brakeman-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ name: Brakeman Scan
# This section configures the trigger for the workflow. Feel free to customize depending on your convention
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
brakeman-scan:
name: Brakeman Scan
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2

# Customize the ruby version depending on your needs
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'
# Customize the ruby version depending on your needs
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"

- name: Setup Brakeman
env:
BRAKEMAN_VERSION: '4.10' # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION
- name: Setup Brakeman
env:
BRAKEMAN_VERSION: "5.4" # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION
# Execute Brakeman CLI and generate a SARIF output with the security issues identified during the analysis
- name: Scan
continue-on-error: true
run: |
brakeman -f sarif -o output.sarif.json .
# Execute Brakeman CLI and generate a SARIF output with the security issues identified during the analysis
- name: Scan
continue-on-error: true
run: |
brakeman -f sarif -o output.sarif.json .
# Upload the SARIF file generated in the previous step
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: output.sarif.json
# Upload the SARIF file generated in the previous step
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: output.sarif.json
27 changes: 9 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ jobs:
fail-fast: false
matrix:
alchemy_branch:
- 6.0-stable
- main
ruby:
- "2.7"
- "3.0"
- "3.1"
env:
ALCHEMY_BRANCH: ${{ matrix.alchemy_branch }}
steps:
- uses: actions/checkout@v1
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.x
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Restore apt cache
id: apt-cache
uses: actions/cache@v1
Expand All @@ -32,21 +38,6 @@ jobs:
sudo apt-get update -qq
sudo apt-get install -qq --fix-missing libsqlite3-dev -o dir::cache::archives="/home/runner/apt/cache"
sudo chown -R runner /home/runner/apt/cache
- name: Install bundler
run: |
gem install bundler
- name: Restore Ruby Gems cache
id: cache
uses: actions/cache@v1
with:
path: vendor/bundle
key: bundle-${{ hashFiles('**/Gemfile.lock') }}-${{ matrix.alchemy_branch }}
restore-keys: |
bundle-
- name: Install bundle
timeout-minutes: 10
run: |
bundle install --jobs 4 --retry 3 --path vendor/bundle
- name: Build and test with RSpec
env:
RAILS_ENV: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class IngredientHeadlineSerializer < BaseSerializer
include IngredientSerializer

attributes :level, :size

# Introduced in Alchemy 6.1
if Alchemy::Ingredients::Headline.stored_attributes[:data].include?(:dom_id)
attribute :dom_id
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class IngredientTextSerializer < BaseSerializer
# maintain compatibility with EssenceText
attribute :body, &:value
attribute :link_url, &:link

# Introduced in Alchemy 6.1
if Alchemy::Ingredients::Text.stored_attributes[:data].include?(:dom_id)
attribute :dom_id
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it "has the right keys and values" do
expect(subject[:value]).to eq("/attachment/#{attachment.id}/show")
expect(subject[:value]).to eq("/attachment/#{attachment.id}/show.png")
expect(subject[:link_title]).to eq("File")
expect(subject[:attachment_name]).to eq("image")
expect(subject[:attachment_file_name]).to eq("image.png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
)
)
end

context "with dom_id", if: Alchemy::Ingredients::Headline.stored_attributes[:data].include?(:dom_id) do
before do
ingredient.dom_id = "hello-you-world"
end

it "is included in the response" do
expect(subject[:dom_id]).to eq "hello-you-world"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@
expect(subject[:link_url]).to eq "https://alchemy-cms.com"
end
end

context "with dom_id", if: Alchemy::Ingredients::Text.stored_attributes[:data].include?(:dom_id) do
before do
ingredient.dom_id = "welcome"
end

it "is included in the response" do
expect(subject[:dom_id]).to eq "welcome"
end
end
end
end

0 comments on commit d3d5091

Please sign in to comment.