<commit_before>require "spec_helper"

describe YearsController do
  context 'as an admin' do
    before do
      sign_in create :admin
    end

    describe '#update' do
      let(:year) { Year.find_by_year(2013) }

      it 'can update the city' do
        new_city = 'Terminator'
        expect {
          put :update, {year: year.year, year_record: {city: new_city}}
        }.to_not raise_exception
        year.reload.city.should == new_city
      end

      it 'cannot update the year attribute' do
        expect {
          put :update, {year: year.year, year_record: {year: 2312}}
        }.to raise_exception(ActiveModel::MassAssignmentSecurity::Error)
      end
    end
  end
end<commit_msg>as a user it should deny access<commit_after>require "spec_helper"

describe YearsController do
  let(:year) { Year.find_by_year(2013) }

  context 'as a user' do
    before do
      sign_in create :user
    end

    it 'denies edit' do
      get :edit, year: year.year
      should_deny_access(response)
    end

    it 'denies update' do
      put :update, year: year.year
      should_deny_access(response)
    end
  end

  context 'as an admin' do
    before do
      sign_in create :admin
    end

    describe '#update' do
      it 'can update the city' do
        new_city = 'Terminator'
        expect {
          put :update, {year: year.year, year_record: {city: new_city}}
        }.to_not raise_exception
        year.reload.city.should == new_city
      end

      it 'cannot update the year attribute' do
        expect {
          put :update, {year: year.year, year_record: {year: 2312}}
        }.to raise_exception(ActiveModel::MassAssignmentSecurity::Error)
      end
    end
  end

  def should_deny_access response
    response.should be_forbidden
    response.should render_template :access_denied
  end
end
{'fraction_non_alphanumeric': 0.08296943231441048, 'fraction_numerical': 0.008733624454148471, 'mean_word_length': 2.4584905660377356, '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': '7545990', 'n_tokens_mistral': 583, 'n_tokens_neox': 555, 'n_words': 174}