<commit_before>require 'rails_helper'

RSpec.describe UpdateItem::Movie, type: :service do
  let(:test_query) { TestQuery::Movie.new }

  before(:each) do
    expect(Immedialist::TMDB::Movie).
      to receive(:find).
      and_return(tmdb_movie)

    expect(Immedialist::RottenTomatoes::Movie).
      to receive(:find).
      and_return(rotten_tomatoes_movie)
  end

  context "movie with a valid imdb id" do
    let(:movie) { FactoryGirl.create(:real_movie,
                                     critics_score: nil,
                                     imdb_id: nil) }
    let(:tmdb_movie) {
      instance_double(Immedialist::TMDB::Movie,
                      attributes: {imdb_id: 1234},
                      genres: [ ],
                      imdb_id: "1234")
    }
    let(:rotten_tomatoes_movie) {
      instance_double(
        Immedialist::RottenTomatoes::Movie,
        attributes: {critics_score: 85}
      )
    }

    it 'saves more details onto the movie passed to it' do
      UpdateItem::Movie.call(movie)

      movie.reload
      expect(movie.critics_score).to_not be_nil
      expect(movie.imdb_id).to eq("1234")
    end
  end

  context "genres" do
    let(:movie) { FactoryGirl.create(:real_movie,
                                     critics_score: nil,
                                     imdb_id: nil) }
    let(:tmdb_movie) {
      instance_double(Immedialist::TMDB::Movie,
                      attributes: {imdb_id: 1234},
                      genres: [
                        Immedialist::TMDB::Genre.new(name: "Action")
                      ],
                      imdb_id: "1234")
    }
    let(:rotten_tomatoes_movie) {
      instance_double(
        Immedialist::RottenTomatoes::Movie,
        attributes: {critics_score: 85}
      )
    }

    it "saves new genres to the movie passed to it" do
      UpdateItem::Movie.call(movie)

      expect(movie.genres.first.name).to eq("Action")
    end
  end
end<commit_msg>Refactor UpdateItem::Movie Spec: extract lets up to higher context<commit_after>require 'rails_helper'

RSpec.describe UpdateItem::Movie, type: :service do
  let(:test_query) { TestQuery::Movie.new }
  let(:rotten_tomatoes_movie) {
    instance_double(
      Immedialist::RottenTomatoes::Movie,
      attributes: {critics_score: 85}
    )
  }
  let(:movie) {
    FactoryGirl.create(:real_movie,
                       critics_score: nil,
                       imdb_id: nil)
  }

  before(:each) do
    expect(Immedialist::TMDB::Movie).
      to receive(:find).
      and_return(tmdb_movie)

    expect(Immedialist::RottenTomatoes::Movie).
      to receive(:find).
      and_return(rotten_tomatoes_movie)
  end

  context "movie with a valid imdb id" do
    let(:tmdb_movie) {
      instance_double(Immedialist::TMDB::Movie,
                      attributes: {imdb_id: 1234},
                      genres: [ ],
                      imdb_id: "1234")
    }

    it 'saves more details onto the movie passed to it' do
      UpdateItem::Movie.call(movie)

      movie.reload
      expect(movie.critics_score).to_not be_nil
      expect(movie.imdb_id).to eq("1234")
    end
  end

  context "genres" do
    let(:tmdb_movie) {
      instance_double(Immedialist::TMDB::Movie,
                      attributes: {imdb_id: 1234},
                      genres: [
                        Immedialist::TMDB::Genre.new(name: "Action")
                      ],
                      imdb_id: "1234")
    }

    it "saves new genres to the movie passed to it" do
      UpdateItem::Movie.call(movie)

      expect(movie.genres.first.name).to eq("Action")
    end
  end
end
{'fraction_non_alphanumeric': 0.10637119113573407, 'fraction_numerical': 0.012742382271468145, 'mean_word_length': 1.9622641509433962, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1069206', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1107, 'n_words': 213}