<commit_before>require 'spec_helper'

describe Embeddable::MultipleChoiceAnswersController do
  before(:each) do
    stub_request(:any, "http://foo.bar.fake/baz")
  end
  let(:a_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:b_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:c_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:choices)  { [a_answer,b_answer,c_answer] }
  let(:question) { FactoryGirl.create(:multiple_choice, :prompt => "prompt", :choices => choices)}
  let(:endpoint) { "http://foo.bar.fake/baz"    }
  let(:run)      { FactoryGirl.create(:run)     }
  let(:answer)   { FactoryGirl.create(:multiple_choice_answer, :question => question, :run => run)}

  describe "#update" do
    describe "with a run initiated from remote portlal" do
      let(:run)  {
        FactoryGirl.create(
          :run,
          :remote_endpoint => endpoint
        )
      }
      describe "with valid params" do
        let(:new_answer) { "this answer has been changed "}
        it "should update the answer" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          answer.reload
          answer.answers.should == [a_answer]
        end
        it "should fire off a web request to update the portal" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          assert_requested :post, endpoint
        end
      end
    end<commit_msg>MCAnswersController Spec: Updates on answers post-back to portal …<commit_after>require 'spec_helper'

describe Embeddable::MultipleChoiceAnswersController do
  before(:each) do
    stub_request(:any, "http://foo.bar.fake/baz")
  end
  let(:a_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:b_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:c_answer) { FactoryGirl.create(:multiple_choice_choice, :choice => "a" )}
  let(:choices)  { [a_answer,b_answer,c_answer] }
  let(:question) { FactoryGirl.create(:multiple_choice, :prompt => "prompt", :choices => choices)}
  let(:endpoint) { "http://foo.bar.fake/baz"    }
  let(:run)      { FactoryGirl.create(:run)     }
  let(:answer)   { FactoryGirl.create(:multiple_choice_answer, :question => question, :run => run)}

  describe "#update" do
    describe "with a run initiated from remote portlal" do
      let(:run)  {
        FactoryGirl.create(
          :run,
          :remote_endpoint => endpoint
        )
      }
      describe "with valid params" do
        let(:new_answer) { "this answer has been changed "}
        it "should update the answer" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          answer.reload
          answer.answers.should == [a_answer]
        end
        it "should fire off a web request to update the portal" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          assert_requested :post, endpoint
        end
      end
    end
    describe "with a run without a remote endpoint (not run from portal)" do
      let(:run)  {
        FactoryGirl.create(
          :run,
          :remote_endpoint => nil
        )
      }
      describe "with valid params" do
        let(:new_answer) { "this answer has been changed "}
        it "should update the answer" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          answer.reload
          answer.answers.should == [a_answer]
        end
        it "should fire off a web request to update the portal" do
          post "update", :id => answer.id, :embeddable_multiple_choice_answer => {
            :answers => [a_answer.id]
          }
          assert_not_requested :post, endpoint
        end
      end
    end
{'fraction_non_alphanumeric': 0.12346888780009799, 'fraction_numerical': 0.0, 'mean_word_length': 2.5721784776902887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '6817544', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1224, 'n_words': 298}