<commit_before>require File.expand_path('../../../spec_helper', __FILE__)

describe Embeddable::MultipleChoice do
  before(:each) do
    @page = FactoryGirl.create(:interactive_page)
    @multichoice = FactoryGirl.create(:multiple_choice)
    @multichoice.create_default_choices
    @multichoice.reload
    @page.add_embeddable(@multichoice)
    @page.reload
  end

  describe "a newly created MutipleChoiceQuestion" do    
    it "belongs to a page" do
      @page.embeddables.should_not be_nil
      @page.embeddables.should include(@multichoice)
    end
    
    it "has three initial default answers" do
      @multichoice.choices.should have(3).answers
    end

    it "has a self-generated storage key" do
      @multichoice.storage_key.should_not be_nil
    end
  end

  describe "adding a new choice" do
    before(:each) do
      @choice = @multichoice.add_choice("my choice")
      @multichoice.reload
    end
    
    it "should have the new choice" do
      @multichoice.choices.should include(@choice)
    end
  
    it "should update its choices when saved" do
      @choice.choice = "fooo"
      @choice.save
      @multichoice.reload
      @multichoice.choices[3].choice.should == "fooo"
    end
      
    describe '#to_hash' do
      it 'returns a hash with copied attributes' do
        expected = { name: @multichoice.name, prompt: @multichoice.prompt, custom: @multichoice.custom, enable_check_answer: @multichoice.enable_check_answer }
        @multichoice.to_hash.should == expected
      end
    end

    describe '#duplicate' do
      it 'returns a new instance with copied attributes' do
        @multichoice.duplicate.should be_a_new(Embeddable::MultipleChoice).with( name: @multichoice.name, prompt: @multichoice.prompt )
      end

      it 'copies choices' do
        c = @multichoice.choices.first
        c.duplicate.should be_a_new(Embeddable::MultipleChoiceChoice).with( choice: c.choice, prompt: c.prompt, is_correct: c.is_correct )
      end

      it 'has copied choices' do
        @multichoice.duplicate.choices.length.should be(@multichoice.choices.length)
      end
    end
  end

end<commit_msg>Refactoring MC question spec to use let<commit_after>require File.expand_path('../../../spec_helper', __FILE__)

describe Embeddable::MultipleChoice do
  let (:multichoice) do
    mc = FactoryGirl.create(:multiple_choice)
    mc.create_default_choices
    mc.reload
    mc
  end

  let (:page) do
    p = FactoryGirl.create(:interactive_page)
    p.add_embeddable(multichoice)
    p.reload
    p
  end

  describe "a newly created MutipleChoiceQuestion" do    
    it "belongs to a page" do
      page.embeddables.should include(multichoice)
    end
    
    it "has three initial default answers" do
      multichoice.choices.should have(3).answers
    end

    # it "has a self-generated storage key" do
    #   multichoice.storage_key.should_not be_nil
    # end
  end

  describe "adding a new choice" do
    let (:choice) { multichoice.add_choice("my choice") }
    
    it "should have the new choice" do
      multichoice.choices.should include(choice)
    end
  
    it "should update its choices when saved" do
      choice.choice = "fooo"
      choice.save
      multichoice.reload
      multichoice.choices[3].choice.should == "fooo"
    end
      
    describe '#to_hash' do
      it 'returns a hash with copied attributes' do
        expected = { name: multichoice.name, prompt: multichoice.prompt, custom: multichoice.custom, enable_check_answer: multichoice.enable_check_answer }
        multichoice.to_hash.should == expected
      end
    end

    describe '#duplicate' do
      it 'returns a new instance with copied attributes' do
        multichoice.duplicate.should be_a_new(Embeddable::MultipleChoice).with( name: multichoice.name, prompt: multichoice.prompt )
      end

      it 'copies choices' do
        c = multichoice.choices.first
        c.duplicate.should be_a_new(Embeddable::MultipleChoiceChoice).with( choice: c.choice, prompt: c.prompt, is_correct: c.is_correct )
      end

      it 'has copied choices' do
        multichoice.duplicate.choices.length.should be(multichoice.choices.length)
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.08969465648854962, 'fraction_numerical': 0.0009541984732824427, 'mean_word_length': 2.966887417218543, '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': '4260553', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1338, 'n_words': 331}