<commit_before>require 'spec_helper'
describe OpenStreetMap do
  
  before(:each) do
    @base_url = "#{OpenStreetMapConfig.oauth_site}/api/0.6"
    @basic_auth_client = OpenStreetMap::BasicAuthClient.new('foo', 'bar')
    uri = URI.parse("#{OpenStreetMapConfig.oauth_site}/api/0.6")
    @basic_auth_url = "#{uri.scheme}://foo:bar@#{uri.host}#{uri.path}"
    
    FakeWeb.allow_net_connect = false
    @consumer = ::OAuth::Consumer.new(OpenStreetMapConfig.oauth_key, OpenStreetMapConfig.oauth_secret, :site => @base_url)
    @access_token = ::OAuth::AccessToken.new(@consumer, 'foo', 'bar')
    @oauth_client = OpenStreetMap::OauthClient.new(@access_token)
    @oauth_osm = OpenStreetMap.new(@client)
    @basic_auth_osm = OpenStreetMap.new(@client)
    
  end
  
  after(:each) do
    FakeWeb.clean_registry
  end
  
  describe 'method: get_node' do
  
    before(:each) do
      @full_url = "#{@base_url}/node/16581933"
    end

    it "should fetch node as xml data from API" do
      FakeWeb.register_uri(:get, @full_url, :body => "#{RAILS_ROOT}/spec/fixtures/node.xml", :content_type => 'text/xml')
      node = OpenStreetMap.get_node(16581933)
      node.class.should == OpenStreetMap::Node
    end
    
    it "should raise not found exception if API sends 404" do
      FakeWeb.register_uri(:get, @full_url, :status => 404, :body => "NOT FOUND", :content_type => 'text/plain')
      lambda{
        OpenStreetMap.get_node(16581933)
      }.should raise_error(OpenStreetMap::NotFound)
    end
    
    it "should raise gone exception if API sends 410" do
      FakeWeb.register_uri(:get, @full_url, :status => 410, :body => "Node has been deleted", :content_type => 'text/plain')
      lambda{
        OpenStreetMap.get_node(16581933)
      }.should raise_error(OpenStreetMap::Gone)
    end
  end
  
  describe "method: create_changeset" do
    before(:each) do
      @full_url = "#{@basic_auth_url}/changeset/create"
    end

    it "should create a new changeset" do
      FakeWeb.register_uri(:put, @full_url, :body => "12345", :content_type => 'text/plain', :basic_auth => @client.credentials)
      changeset_id = @osm.create_changeset
      changeset_id.should == 12345
    end
    
    it "should raise bad request when submitting malformed xml" do
      FakeWeb.register_uri(:put, @full_url, :status => 400, :body => "Could not parse xml", :content_type => 'text/plain')
      lambda{
        @osm.create_changeset
      }.should raise_error(OpenStreetMap::BadRequest)
    end
    
    it "should raise method not allowed exception when not using put request" do
      FakeWeb.register_uri(:put, @full_url, :status => 405, :body => "Just method put is supported", :content_type => 'text/plain')
      lambda{
        @osm.create_changeset
      }.should raise_error(OpenStreetMap::MethodNotAllowed)
    end
  end
  
  describe "method: save_changeset" do
  end
  <commit_msg>fixed specs<commit_after>require 'spec_helper'
describe OpenStreetMap do
  
  before(:each) do
    FakeWeb.allow_net_connect = false
    @base_url = "#{OpenStreetMapConfig.oauth_site}/api/0.6"
    uri = URI.parse("#{OpenStreetMapConfig.oauth_site}/api/0.6")

    @basic_auth_client = OpenStreetMap::BasicAuthClient.new('foo', 'bar')
    @basic_auth_url = "#{uri.scheme}://foo:bar@#{uri.host}#{uri.path}"
    
    @consumer = ::OAuth::Consumer.new(OpenStreetMapConfig.oauth_key, OpenStreetMapConfig.oauth_secret, :site => @base_url)
    @access_token = ::OAuth::AccessToken.new(@consumer, 'foo', 'bar')

    @oauth_client = OpenStreetMap::OauthClient.new(@access_token)
    @oauth_url = uri

    @osm = OpenStreetMap.new(@oauth_client)

    
  end
  
  after(:each) do
    FakeWeb.clean_registry
  end
  
  
  
  
  describe 'method: get_node' do
  
    before(:each) do
      @full_url = "#{@base_url}/node/16581933"
    end

    it "should fetch node as xml data from API" do
      FakeWeb.register_uri(:get, @full_url, :body => "#{RAILS_ROOT}/spec/fixtures/node.xml", :content_type => 'text/xml')
      node = OpenStreetMap.get_node(16581933)
      node.class.should == OpenStreetMap::Node
    end
    
    it "should raise not found exception if API sends 404" do
      FakeWeb.register_uri(:get, @full_url, :status => 404, :body => "NOT FOUND", :content_type => 'text/plain')
      lambda{
        OpenStreetMap.get_node(16581933)
      }.should raise_error(OpenStreetMap::NotFound)
    end
    
    it "should raise gone exception if API sends 410" do
      FakeWeb.register_uri(:get, @full_url, :status => 410, :body => "Node has been deleted", :content_type => 'text/plain')
      lambda{
        OpenStreetMap.get_node(16581933)
      }.should raise_error(OpenStreetMap::Gone)
    end
  end
  
  describe "method: create_changeset" do
    before(:each) do
      @full_url = "#{@oauth_url}/changeset/create"
    end

    it "should create a new changeset" do
      FakeWeb.register_uri(:put, @full_url, :body => "12345", :content_type => 'text/plain')
      changeset_id = @osm.create_changeset
      changeset_id.should == 12345
    end
    
    it "should raise bad request when submitting malformed xml" do
      FakeWeb.register_uri(:put, @full_url, :status => 400, :body => "Could not parse xml", :content_type => 'text/plain')
      lambda{
        @osm.create_changeset
      }.should raise_error(OpenStreetMap::BadRequest)
    end
    
    it "should raise method not allowed exception when not using put request" do
      FakeWeb.register_uri(:put, @full_url, :status => 405, :body => "Just method put is supported", :content_type => 'text/plain')
      lambda{
        @osm.create_changeset
      }.should raise_error(OpenStreetMap::MethodNotAllowed)
    end
  end
  
  describe "method: save_changeset" do
  end
  
{'fraction_non_alphanumeric': 0.1268787137364558, 'fraction_numerical': 0.0223698007689619, 'mean_word_length': 3.47109375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4422425', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1892, 'n_words': 421}