Sha256: c1b3011458e69f0876f897ab5f0cf8bf6dd597b8af1746a4854477a4d30a9b93

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
require 'celluloid'
require 'writefully/tools'

module Writefully
  module Tools
    describe Pencil do 
      fixtures :"writefully/sites"
      fixtures :"writefully/posts"

      let(:index)   { {site: 'codemy-net', resource: 'posts', slug: '1-hash-selector-pattern' } }
      let(:index_2)   { {site: 'codemy-net', resource: 'posts', slug: '2-rails-flash-partials' } }
      let(:computed_attributes) { 
        { 
          "title" => "Ruby Hash Selector Pattern",
          "tags" => ["Ruby"],
          "playlists" => ["A Shot of Ruby"],
          "position" => 1,
          "content" => "converted stuff",
          "details" => "converted stuff",
          "trashed" => false
        }
      }

      before do 
        $stdout.stub(:write)
        $stderr.stub(:write)
        Asset.any_instance.stub(:convert_for).and_return("converted stuff")
      end

      it "#computed_attributes" do 
        pencil = Pencil.new(index)
        expect(pencil.computed_attributes).to eq computed_attributes 
        pencil.terminate
      end

      describe "#write" do 
        it "should create new post" do 
          pencil = Pencil.new(index)
          expect { 
            pencil.write
          }.to change(Post, :count).by(0)
          pencil.terminate
        end

        it "should update existing post" do 
          pencil = Pencil.new(index_2)
          expect { 
            pencil.write
          }.to change(Post, :count).by(1)
          pencil.terminate
        end
      end

      describe "#can_update_db" do
        it "can update" do 
          pencil = Pencil.new(index) 
          expect(pencil.can_update_db?([true, true])).to be true
          pencil.terminate
        end

        it "can't update" do 
          pencil = Pencil.new(index) 
          expect { 
            pencil.can_update_db?([true])
          }.to raise_error Writefully::Tools::Pencil::SomeAssetsNotUploaded
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
writefully-0.8.2 spec/lib/writefully/tools/pencil_spec.rb
writefully-0.8.1 spec/lib/writefully/tools/pencil_spec.rb
writefully-0.8.0 spec/lib/writefully/tools/pencil_spec.rb