<commit_before>require 'spec_helper'

describe Wp2tumblr do
  context "Dependencies" do
    it "depends on Nokogiri" do
      Nokogiri.should_not be_nil
    end

    it "depends on tumblr_client" do
      Tumblr.should_not be_nil
    end

    it "depends on oauth" do
      OAuth.should_not be_nil
    end
  end
end

describe Wp2tumblr::Wordpress do
  let(:file) { File.open(File.dirname(__FILE__) + "/wp2tumblr/wordpress_format.xml") }

  describe ".parse_xml" do
    it "delegates parsing of just post content" do
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :posts)
      parsed_params[0][:title].should eq("Post Title")
    end
  end

  describe ".parse_xml" do
    it "delegates parsing of just post categories" do
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :categories)
      parsed_params[0].should eq("Category 1")
    end
  end

  describe ".parse_xml" do 
    it "delegates parsing of just post tags" do 
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :tags)
      parsed_params[0].should eq("Tag 1")
    end
  end

  describe ".parse_xml" do 
    it "Parses posts, tags, categories, and comments together" do 
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :all)
      parsed_params[0][:title].should eq("Post Title")
      parsed_params[0][:tags][0].should eq("Tag 1")
      parsed_params[0][:categories][0].should eq("Category 1")
      parsed_params[0][:comments][0][:author].should eq("Test Commenter")
    end
  end

  describe ".parse_images" do
    it "Encodes images as base64" do
      posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
      post = Nokogiri::HTML(posts[0][:content].text)
      Wp2tumblr::Wordpress.parse_images(post).to_s.should include('base64')
    end
  end
end

describe Wp2tumblr::TumblrClient do
  # config.yml is excluded from this repo, you must provide your own keys for deveopment purposes.
  let(:config) { YAML.load_file(File.dirname(__FILE__) + "/wp2tumblr/config_spec.yml") }
  let(:client) { Wp2tumblr::TumblrClient.new(config["tumblr_consumer_key"], config["tumblr_secret_key"], config["oauth_token"], config["oauth_token_secret"]) }
  let(:file) { File.open(File.dirname(__FILE__) + "/wp2tumblr/wordpress_format.xml") }

  describe "initialize" do
    it "should return an instance of itself" do
      client.should_not be_nil<commit_msg>adjusted parse_images spec to look at :body instead of :content<commit_after>require 'spec_helper'

describe Wp2tumblr do
  context "Dependencies" do
    it "depends on Nokogiri" do
      Nokogiri.should_not be_nil
    end

    it "depends on tumblr_client" do
      Tumblr.should_not be_nil
    end

    it "depends on oauth" do
      OAuth.should_not be_nil
    end
  end
end

describe Wp2tumblr::Wordpress do
  let(:file) { File.open(File.dirname(__FILE__) + "/wp2tumblr/wordpress_format.xml") }

  describe ".parse_xml" do
    it "delegates parsing of just post content" do
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :posts)
      parsed_params[0][:title].should eq("Post Title")
    end
  end

  describe ".parse_xml" do
    it "delegates parsing of just post categories" do
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :categories)
      parsed_params[0].should eq("Category 1")
    end
  end

  describe ".parse_xml" do 
    it "delegates parsing of just post tags" do 
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :tags)
      parsed_params[0].should eq("Tag 1")
    end
  end

  describe ".parse_xml" do 
    it "Parses posts, tags, categories, and comments together" do 
      parsed_params = Wp2tumblr::Wordpress.parse_xml(file, :all)
      parsed_params[0][:title].should eq("Post Title")
      parsed_params[0][:tags][0].should eq("Tag 1")
      parsed_params[0][:categories][0].should eq("Category 1")
      parsed_params[0][:comments][0][:author].should eq("Test Commenter")
    end
  end

  describe ".parse_images" do
    it "Encodes images as base64" do
      posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
      posts[0][:body].should include('base64')
    end
  end
end

describe Wp2tumblr::TumblrClient do
  # config.yml is excluded from this repo, you must provide your own keys for deveopment purposes.
  let(:config) { YAML.load_file(File.dirname(__FILE__) + "/wp2tumblr/config_spec.yml") }
  let(:client) { Wp2tumblr::TumblrClient.new(config["tumblr_consumer_key"], config["tumblr_secret_key"], config["oauth_token"], config["oauth_token_secret"]) }
  let(:file) { File.open(File.dirname(__FILE__) + "/wp2tumblr/wordpress_format.xml") }

  describe "initialize" do
    it "should return an instance of itself" do
      client.should_not be_nil
{'fraction_non_alphanumeric': 0.11439588688946016, 'fraction_numerical': 0.013496143958868894, 'mean_word_length': 3.9355179704016914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '884110', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1569, 'n_words': 380}