<commit_before># frozen_string_literal: true

require "rails_helper"

RSpec.describe "alchemy/ingredients/_picture_editor" do
  let(:picture) { stub_model(Alchemy::Picture) }
  let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat_ingredients") }
  let(:element_editor) { Alchemy::ElementEditor.new(element) }

  let(:ingredient) do
    stub_model(
      Alchemy::Ingredients::Picture,
      caption: "This is a cute cat",
      element: element,
      picture: picture,
      role: "image",
    )
  end

  let(:settings) { {} }

  it_behaves_like "an alchemy ingredient editor"

  before do
    allow(element_editor).to receive(:ingredients) { [Alchemy::IngredientEditor.new(ingredient)] }
    allow(ingredient).to receive(:settings) { settings }
  end

  subject do
    render element_editor
    rendered
  end

  context "with settings[:deletable] being nil" do
    it "should not render a button to link and unlink the picture" do
      is_expected.to have_selector("a .icon.fa-link")
      is_expected.to have_selector("a .icon.fa-unlink")<commit_msg>Include helpers in picture ingredient editor spec<commit_after># frozen_string_literal: true

require "rails_helper"

RSpec.describe "alchemy/ingredients/_picture_editor" do
  let(:picture) { stub_model(Alchemy::Picture) }
  let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat_ingredients") }
  let(:element_editor) { Alchemy::ElementEditor.new(element) }

  let(:ingredient) do
    stub_model(
      Alchemy::Ingredients::Picture,
      caption: "This is a cute cat",
      element: element,
      picture: picture,
      role: "image",
    )
  end

  let(:settings) { {} }

  it_behaves_like "an alchemy ingredient editor"

  before do
    allow(element_editor).to receive(:ingredients) { [Alchemy::IngredientEditor.new(ingredient)] }
    allow(ingredient).to receive(:settings) { settings }
    view.class.send :include, Alchemy::Admin::BaseHelper
    view.class.send :include, Alchemy::Admin::IngredientsHelper
  end

  subject do
    render element_editor
    rendered
  end

  context "with settings[:deletable] being nil" do
    it "should not render a button to link and unlink the picture" do
      is_expected.to have_selector("a .icon.fa-link")
      is_expected.to have_selector("a .icon.fa-unlink")
{'fraction_non_alphanumeric': 0.11115935735996527, 'fraction_numerical': 0.0, 'mean_word_length': 4.200902934537246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6884423', 'n_tokens_mistral': 778, 'n_tokens_neox': 727, 'n_words': 169}