<commit_before>require 'spec_helper'

describe Sendyr::Client do
	before do
		@base_url = 'http://localhost'
		@api_key  = '1234567890'
		@email    = '<EMAIL>'
		@list_id  = '1'

		Sendyr.configure do |c|
			c.url     = @base_url
			c.api_key = @api_key
		end
	end

	let(:client) { Sendyr::Client.new(@list_id) }

	describe ".initialize" do
	  it "should properly set instance variables" do
	  	client = Sendyr::Client.new(@list_id)
	  	client.list_id.should  == @list_id
	  	client.base_uri.should == @base_url
	  	client.api_key.should  == @api_key
	  end
	end

	describe "#subscribe" do
		it "raises exception if email is missing" do
			expect {
				client.subscribe(foo: @email)
			}.to raise_error(ArgumentError, 'You must specify :email.')
		end

		it "subscribes the email and passes the other arguments" do
			stub_request(:post, "#{@base_url}/subscribe").
			  with(:body => {"FirstName"=>"John",
			  							 "boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id,
			  							 "name"=>"<NAME>"}).
        to_return(:status => 200, :body => "true")

			client.subscribe(email: @email, name: '<NAME>', "FirstName" => "John").should == true
		end

		it "fails when the response message is an error" do
			stub_request(:post, "#{@base_url}/subscribe").
			  with(:body => {"FirstName"=>"John",
			  							 "boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id,
			  							 "name"=>"<NAME>"}).
        to_return(:status => 200, :body => "Already subscribed.")

			client.subscribe(email: @email, name: '<NAME>', "FirstName" => "John").should == false
		end
	end

	describe "#unsubscribe" do
		it "raises exception if email is missing" do
			expect {
				client.unsubscribe(foo: @email)
			}.to raise_error(ArgumentError, 'You must specify :email.')
		end

		it "unsubscribes the email" do
			stub_request(:post, "#{@base_url}/subscribe").
			  with(:body => {"boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id}).
        to_return(:status => 200, :body => "true")

			client.subscribe(email: @email).should == true
		end

		it "fails when the response message is an error" do
			stub_request(:post, "#{@base_url}/subscribe").
				with(:body => {"boolean"=>"true",
											 "email"=> @email,
											 "list"=>@list_id}).
        to_return(:status => 200, :body => "Invalid email address.")

			client.subscribe(email: @email).should == false<commit_msg>fixed specs for unsubscribe<commit_after>require 'spec_helper'

describe Sendyr::Client do
	before do
		@base_url = 'http://localhost'
		@api_key  = '1234567890'
		@email    = '<EMAIL>'
		@list_id  = '1'

		Sendyr.configure do |c|
			c.url     = @base_url
			c.api_key = @api_key
		end
	end

	let(:client) { Sendyr::Client.new(@list_id) }

	describe ".initialize" do
	  it "should properly set instance variables" do
	  	client = Sendyr::Client.new(@list_id)
	  	client.list_id.should  == @list_id
	  	client.base_uri.should == @base_url
	  	client.api_key.should  == @api_key
	  end
	end

	describe "#subscribe" do
		it "raises exception if email is missing" do
			expect {
				client.subscribe(foo: @email)
			}.to raise_error(ArgumentError, 'You must specify :email.')
		end

		it "subscribes the email and passes the other arguments" do
			stub_request(:post, "#{@base_url}/subscribe").
			  with(:body => {"FirstName"=>"John",
			  							 "boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id,
			  							 "name"=>"<NAME>"}).
        to_return(:status => 200, :body => "true")

			client.subscribe(email: @email, name: '<NAME>', "FirstName" => "John").should == true
		end

		it "fails when the response message is an error" do
			stub_request(:post, "#{@base_url}/subscribe").
			  with(:body => {"FirstName"=>"John",
			  							 "boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id,
			  							 "name"=>"<NAME>"}).
        to_return(:status => 200, :body => "Already subscribed.")

			client.subscribe(email: @email, name: '<NAME>', "FirstName" => "John").should == false
		end
	end

	describe "#unsubscribe" do
		it "raises exception if email is missing" do
			expect {
				client.unsubscribe(foo: @email)
			}.to raise_error(ArgumentError, 'You must specify :email.')
		end

		it "unsubscribes the email" do
			stub_request(:post, "#{@base_url}/unsubscribe").
			  with(:body => {"boolean"=>"true",
			  							 "email"=> @email,
			  							 "list"=>@list_id}).
        to_return(:status => 200, :body => "true")

			client.unsubscribe(email: @email).should == true
		end

		it "fails when the response message is an error" do
			stub_request(:post, "#{@base_url}/unsubscribe").
				with(:body => {"boolean"=>"true",
											 "email"=> @email,
											 "list"=>@list_id}).
        to_return(:status => 200, :body => "Invalid email address.")

			client.unsubscribe(email: @email).should == false
{'fraction_non_alphanumeric': 0.16727716727716727, 'fraction_numerical': 0.009361009361009361, 'mean_word_length': 2.9829821717990277, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 73, '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': '4901630', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1650, 'n_words': 398}