<commit_before>require 'rails_helper'

RSpec.describe CloneRecipeController, type: :controller do
  let(:recipe) { Recipe.create(recipe_attributes) }
  let(:beerxml) { file_fixture('beerxml.xml').read }
  let(:recipe_attributes) do
    {
      user: user,
      name: 'recipe test',
      beerxml: beerxml
    }
  end

  describe "GET #new" do
    login_user

    it "returns http success" do
      get :new, params: { id: recipe.id }
      expect(response).to have_http_status(:success)
    end
  end

  describe "POST #create" do
    login_user

    it "returns http success and clones recipe with new name" do
      post :create, params: { id: recipe.id, name: "foo bar" }
      cloned_recipe = Recipe.last
      expect(response).to redirect_to(cloned_recipe)
      expect(cloned_recipe.id).not_to eq recipe.id
      expect(cloned_recipe.name).to eq "foo bar"
      expect(cloned_recipe.beerxml).to eq beerxml
    end
  end
end<commit_msg>Improve spec for clone recipe<commit_after>require 'rails_helper'

RSpec.describe CloneRecipeController, type: :controller do
  let(:other_user) {
    user = User.new(name: 'other user', email: '<EMAIL>', password: 'password')
    user.skip_confirmation!
    user.save!
    user
  }
  let(:recipe) { Recipe.create(recipe_attributes) }
  let(:beerxml) { file_fixture('beerxml.xml').read }
  let(:recipe_attributes) do
    {
      user: other_user,
      name: 'recipe test',
      beerxml: beerxml
    }
  end

  describe "GET #new" do
    login_user

    it "returns http success" do
      get :new, params: { id: recipe.id }
      expect(response).to have_http_status(:success)
    end
  end

  describe "POST #create" do
    login_user

    it "returns http success and clones recipe with new name" do
      post :create, params: { id: recipe.id, name: "foo bar" }
      cloned_recipe = Recipe.last
      expect(response).to redirect_to(cloned_recipe)
      expect(cloned_recipe.id).not_to eq recipe.id
      expect(cloned_recipe).to have_attributes(
        name: "<NAME>",
        beerxml: beerxml,
        user: user
      )
    end
  end
end
{'fraction_non_alphanumeric': 0.10627094303494496, 'fraction_numerical': 0.0, 'mean_word_length': 3.034749034749035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '2760275', 'n_tokens_mistral': 710, 'n_tokens_neox': 698, 'n_words': 178}