<commit_before>require 'helper'

shared_examples_for Charm::Scaffold do
  describe '#new' do
    context 'when not signed in' do
      specify do
        expect { get :new }.to raise_error(Charm::Unauthorized)
      end
    end

    context 'when signed in as user' do
      specify do
        controller.send :current_user=, create(:user)
        expect { get :new }.to raise_error(Charm::Forbidden)
      end
    end

    context 'when signed in as admin' do
      specify do
        controller.send :current_user=, create(:admin)
        expect { get :new }.not_to raise_error
      end
    end
  end
end<commit_msg>scaffold_spec not full refactored yet<commit_after>require 'helper'

shared_examples_for Charm::Scaffold do
  let(:page) { create :page }

  describe '#new' do
    context 'when signed in as admin' do
      specify do
        controller.send :current_user=, create(:admin)
        expect { get :new }.not_to raise_error
      end
    end

    context 'when signed in as user' do
      specify do
        controller.send :current_user=, create(:user)
        expect { get :new }.to raise_error(Charm::Forbidden)
      end
    end

    context 'when not signed in' do
      specify do
        expect { get :new }.to raise_error(Charm::Unauthorized)
      end
    end
  end

  describe '#edit' do
    context 'when signed in as admin' do
      specify do
        controller.send :current_user=, create(:admin)
        expect { get :edit, { id: page.id } }.not_to raise_error
      end
    end

    context 'when signed in as user' do
      specify do
        controller.send :current_user=, create(:user)
        expect { get :edit, { id: page.id } }.to raise_error(Charm::Forbidden)
      end
    end

    context 'when signed in as guest' do
      specify do
        expect { get :edit, { id: page.id } }.to raise_error(Charm::Unauthorized)
      end
    end
  end

  describe '#destroy' do
    context 'when signed in as admin' do
      specify do
        controller.send :current_user=, create(:admin)
        expect { delete :destroy, { id: page.id } }.not_to raise_error
      end
    end

    context 'when signed in as user' do
      specify do
        controller.send :current_user=, create(:user)
        expect { delete :destroy, { id: page.id } }.to raise_error(Charm::Forbidden)
      end
    end

    context 'when signed in as guest or user' do
      specify { expect { delete :destroy, { id: page.id } }.to raise_error(Charm::Unauthorized) }
    end
  end
end
{'fraction_non_alphanumeric': 0.08992372541148133, 'fraction_numerical': 0.0, 'mean_word_length': 2.4090287277701776, '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': '4662523', 'n_tokens_mistral': 767, 'n_tokens_neox': 769, 'n_words': 260}