From 291e40f8590d031b4f317a3c25b574bbdd02a6fa Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 18 Oct 2014 02:34:58 -0700 Subject: [PATCH] put test repos in a better location, fix other bugs --- .gitignore | 2 +- Gemfile | 4 ++++ Gemfile.lock | 10 ++++++++++ Makefile | 5 ++++- bin/create-test-blog.sh | 2 +- server/harp_blog.rb | 2 +- server/server.rb | 2 +- server/spec/harp_blog_spec.rb | 5 +++-- server/spec/helpers.rb | 10 ++++++++-- 9 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d0143ca..57a5fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ node_modules public/feed.xml www server/auth.json -server/spec/test-blog* +server/test-blog* diff --git a/Gemfile b/Gemfile index 7028a61..6319f24 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,12 @@ source 'https://rubygems.org' gem 'builder' +gem 'css_parser' gem 'htmlentities' +gem 'mustache' +gem 'nokogiri' gem 'rdiscount' gem 'sinatra' + gem 'rspec' gem 'guard-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index f510b7c..2d24980 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,13 @@ GEM remote: https://rubygems.org/ specs: + addressable (2.3.6) builder (3.2.2) celluloid (0.16.0) timers (~> 4.0.0) coderay (1.1.0) + css_parser (1.3.5) + addressable diff-lcs (1.2.5) ffi (1.9.3) formatador (0.2.5) @@ -25,6 +28,10 @@ GEM rb-inotify (>= 0.9) lumberjack (1.0.9) method_source (0.8.2) + mini_portile (0.6.0) + mustache (0.99.6) + nokogiri (1.6.3.1) + mini_portile (= 0.6.0) pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -63,8 +70,11 @@ PLATFORMS DEPENDENCIES builder + css_parser guard-rspec htmlentities + mustache + nokogiri rdiscount rspec sinatra diff --git a/Makefile b/Makefile index 0122b63..7eb31c4 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,10 @@ publish_beta: compile ./bin/publish.sh --beta --delete test_blog: - ./bin/create-test-blog.sh server/spec/test-blog + ./bin/create-test-blog.sh server/test-blog + +clean: + rm -rf server/test-blog server/test-blog-origin.git spec: cd server && rspec -f documentation diff --git a/bin/create-test-blog.sh b/bin/create-test-blog.sh index 0bc0948..d36f529 100755 --- a/bin/create-test-blog.sh +++ b/bin/create-test-blog.sh @@ -9,7 +9,7 @@ if [[ -e "$BLOG_PATH" ]]; then else if [[ ! -e "$ORIGIN_BLOG_PATH" ]]; then echo ">>> Mirroring local origin..." - git clone --mirror https://github.com/samsonjs/samhuri.net.git "$ORIGIN_BLOG_PATH" + git clone --mirror . "$ORIGIN_BLOG_PATH" fi echo ">>> Cloning test blog from local origin..." git clone "$ORIGIN_BLOG_PATH" "$BLOG_PATH" diff --git a/server/harp_blog.rb b/server/harp_blog.rb index 6517674..3e26054 100644 --- a/server/harp_blog.rb +++ b/server/harp_blog.rb @@ -122,7 +122,7 @@ class HarpBlog def posts_for_month(year, month) post_dir = post_path(year, month) post_data = read_post_data(post_dir) - post_data.values.sort_by {|p| p['timestamp'] }.map {|p| Post.new(p) } + post_data.values.sort_by { |p| p['timestamp'] }.map { |p| Post.new(p) } end def get_post(year, month, slug) diff --git a/server/server.rb b/server/server.rb index 4dd1eca..e15ab73 100755 --- a/server/server.rb +++ b/server/server.rb @@ -11,7 +11,7 @@ require './harp_blog' $config = { auth: false, dry_run: false, - path: File.expand_path('../spec/test-blog', __FILE__), + path: File.expand_path('../test-blog', __FILE__), host: '127.0.0.1', port: 6706, } diff --git a/server/spec/harp_blog_spec.rb b/server/spec/harp_blog_spec.rb index 619ffac..6c492e5 100644 --- a/server/spec/harp_blog_spec.rb +++ b/server/spec/harp_blog_spec.rb @@ -2,8 +2,8 @@ require 'json' require_relative './helpers' require_relative '../harp_blog' -TEST_BLOG_PATH = File.expand_path('../test-blog', __FILE__) -TEST_BLOG_ORIGIN_PATH = File.expand_path('../test-blog-origin.git', __FILE__) +TEST_BLOG_PATH = File.expand_path('../../test-blog', __FILE__) +TEST_BLOG_ORIGIN_PATH = File.expand_path('../../test-blog-origin.git', __FILE__) RSpec.configure do |c| c.include Helpers @@ -238,6 +238,7 @@ RSpec.describe HarpBlog do blog = HarpBlog.new(TEST_BLOG_PATH, dry_run, TitleFinder.new) post = blog.create_post(nil, nil, 'http://samhuri.net') expect(post.title).to eq('fancy title') + blog.delete_post(post.time.year.to_s, post.padded_month, post.slug) post = blog.create_post(" \t\n", nil, 'http://samhuri.net') expect(post.title).to eq('fancy title') end diff --git a/server/spec/helpers.rb b/server/spec/helpers.rb index 32841e5..bf8f0f5 100644 --- a/server/spec/helpers.rb +++ b/server/spec/helpers.rb @@ -16,7 +16,13 @@ module Helpers end def git_bare?(dir) - !File.exist?(File.join(dir, '.git')) + if File.exist?(File.join(dir, '.git')) + false + elsif File.exist?(File.join(dir, 'HEAD')) + true + else + raise "what is this dir? #{dir} #{Dir[dir + '/*'].join(', ')}" + end end def git_sha(dir) @@ -29,7 +35,7 @@ module Helpers def git_reset_hard(dir, ref = nil) if git_bare?(dir) - raise 'git_reset_hard does not support bare repos' + raise 'git_reset_hard does not support bare repos ' + dir + ' -- ' + ref.to_s else args = ref ? "'#{ref}'" : '' `cd '#{dir}' && git reset --hard #{args}`