<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

shared_examples_for "an ObservationsController" do

  describe "create" do
    it "should create" do
      expect {
        post :create, :format => :json, :observation => {:species_guess => "foo"}
      }.to change(Observation, :count).by(1)
      o = Observation.last
      expect(o.user_id).to eq(user.id)
      expect(o.species_guess).to eq ("foo")
    end

    it "should include private coordinates in create response" do
      post :create, :format => :json, :observation => {:latitude => 1.2345, :longitude => 1.2345, :geoprivacy => Observation::PRIVATE}
      o = Observation.last
      expect(o).to be_coordinates_obscured
      expect(response.body).to be =~ /#{o.private_latitude}/
      expect(response.body).to be =~ /#{o.private_longitude}/
    end

    it "should not fail if species_guess is a question mark" do
      post :create, :format => :json, :observation => {:species_guess => "?"}
      expect(response).to be_success
      o = Observation.last
      expect(o.species_guess).to eq('?')
    end

    it "should accept nested observation_field_values" do
      of = ObservationField.make!
      post :create, :format => :json, :observation => {
        :species_guess => "zomg", 
        :observation_field_values_attributes => [
          {
            :observation_field_id => of.id,
            :value => "foo"
          }
        ]
      }
      expect(response).to be_success
      o = Observation.last
      expect(o.observation_field_values.last.observation_field).to eq(of)
      expect(o.observation_field_values.last.value).to eq("foo")
    end

    it "should allow Google Street View photos" do<commit_msg>Sanity testing.<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

shared_examples_for "an ObservationsController" do

  describe "create" do
    it "should create" do
      expect {
        post :create, :format => :json, :observation => {:species_guess => "foo"}
      }.to change(Observation, :count).by(1)
      o = Observation.last
      expect(o.user_id).to eq(user.id)
      expect(o.species_guess).to eq ("foo")
    end

    it "should include coordinates in create response when geoprivacy is obscured" do
      post :create, format: :json, observation: {
        latitude: 1.2345,
        longitude: 1.2345,
        geoprivacy: Observation::OBSCURED
      }
      o = Observation.last
      expect(o).to be_coordinates_obscured
      expect(response.body).to be =~ /#{o.latitude}/
      expect(response.body).to be =~ /#{o.longitude}/
    end

    it "should include private coordinates in create response when geoprivacy is obscured" do
      post :create, format: :json, observation: {
        latitude: 1.2345,
        longitude: 1.2345,
        geoprivacy: Observation::OBSCURED
      }
      o = Observation.last
      expect( o ).to be_coordinates_obscured
      expect( response.body ).to be =~ /#{o.private_latitude}/
      expect( response.body ).to be =~ /#{o.private_longitude}/
    end

    it "should include private coordinates in create response when geoprivacy is private" do
      post :create, format: :json, observation: {
        latitude: 1.2345,
        longitude: 1.2345,
        geoprivacy: Observation::PRIVATE
      }
      o = Observation.last
      expect( o.latitude ).to be_blank
      expect( o.private_latitude ).not_to be_blank
      expect( response.body ).to be =~ /#{o.private_latitude}/
      expect( response.body ).to be =~ /#{o.private_longitude}/
    end

    it "should not fail if species_guess is a question mark" do
      post :create, :format => :json, :observation => {:species_guess => "?"}
      expect(response).to be_success
      o = Observation.last
      expect(o.species_guess).to eq('?')
    end

    it "should accept nested observation_field_values" do
      of = ObservationField.make!
      post :create, :format => :json, :observation => {
        :species_guess => "zomg", 
        :observation_field_values_attributes => [
          {
            :observation_field_id => of.id,
            :value => "foo"
          }
        ]
      }
      expect(response).to be_success
      o = Observation.last
      expect(o.observation_field_values.last.observation_field).to eq(of)
      expect(o.observation_field_values.last.value).to eq("foo")
    end

    it "should allow Google Street View photos" do
{'fraction_non_alphanumeric': 0.12104664391353812, 'fraction_numerical': 0.00955631399317406, 'mean_word_length': 2.669449081803005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '4549799', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1364, 'n_words': 339}