Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaned up specs, views and changed the .type_of method to the more s…

…pecific .commit?
  • Loading branch information...
commit e4afd6bcd667c8591a942abccd0c6ef8e8429936 1 parent c66a823
@rubiii authored
View
6 lib/git/store/engine.rb
@@ -39,11 +39,11 @@ def remove(key)
def revision(revision = nil)
revision ||= Revision.head
- Revision.new revision if revision
+ Revision.new revision if commit? revision
end
- def type_of(key)
- `git cat-file -t #{key}`.chomp
+ def commit?(key)
+ `git cat-file -t #{key}`.chomp == "commit"
end
# def parent(commit)
View
17 lib/git/store/front.rb
@@ -75,14 +75,19 @@ def highlight?(value)
# FRONT
- get "/" do
- @revision = git.revision
- haml :index
- end
+# get "/" do
+# @revision = git.revision
+# haml :index
+# end
- get "/:revision" do
+ get "/:revision?" do
@revision = git.revision params[:revision]
- haml :index
+
+ if @revision
+ haml :index
+ else
+ haml :not_found
+ end
end
post "/push" do
View
3  lib/git/store/front/views/_footer.haml
@@ -1,5 +1,4 @@
%h2 _why?
%ul
%li Born on whyday 2010
- %li
- %a{ :href => "http://github.com/rubiii/git_store" } http://github.com/rubiii/git_store
+ %li= link_to "http://github.com/rubiii/git_store", "http://github.com/rubiii/git_store"
View
5 lib/git/store/front/views/_getting_started.haml
@@ -1,7 +1,4 @@
%h2 Getting started
%ul
%li Create and update values using the interface below
- %li
- or explore and use the
- %a{ :href => "/api" } API
- to do it
+ %li or explore and use the #{link_to("API", "/api")} to do it
View
8 lib/git/store/front/views/not_found.haml
@@ -0,0 +1,8 @@
+- content_for :header do
+ %h1= link_to "Ups, <strong>#{params[:revision][0, 6]}</strong> not found", "/"
+ %p I looked everywhere and I just can't find that revision.
+
+%h2 So what now?
+%ul
+ %li Go back to the #{link_to("homepage", "/")}
+ %li or discover the #{link_to("API", "/api")}
View
35 spec/git/store/engine_spec.rb
@@ -30,20 +30,41 @@
key = git.push "something"
commit = git.update key, "else"
- git.type_of(commit).should == "commit"
+ git.commit?(commit).should be_true
end
it "should retrieve values for a given revision" do
key = git.push "something"
- revision1 = git.update key, "else"
- revision2 = git.update key, "whatever"
+ first_revision = git.update key, "else"
+ second_revision = git.update key, "whatever"
- git.pull(revision1, key).should == "else"
- git.pull(revision2, key).should == "whatever"
+ git.pull(first_revision, key).should == "else"
+ git.pull(second_revision, key).should == "whatever"
end
- it "should return a revision"
+ describe ".revision" do
+ it "should return a revision" do
+ key = git.push "something"
+ first_revision = git.update key, "else"
+ second_revision = git.update key, "whatever"
+
+ revision = git.revision first_revision
+
+ revision.should be_a(Git::Store::Revision)
+ revision.sha.should == first_revision
+ end
- it "should return nil if no revision exists"
+ it "should default to return the HEAD revision" do
+ key = git.push "something"
+ first_revision = git.update key, "else"
+ second_revision = git.update key, "whatever"
+
+ git.revision.sha.should == second_revision
+ end
+
+ it "should return +nil+ in case a given revision does not exist" do
+ git.revision("undefined").should be_nil
+ end
+ end
end
View
32 spec/git/store/front_spec.rb
@@ -19,50 +19,60 @@
# setup test data
@chunky = git.push "chunky"
@bacon = git.push "bacon"
- @rev1 = git.update @chunky, "hackety"
- @rev2 = git.update @chunky, "hack"
+ @first_revision = git.update @chunky, "hackety"
+ @second_revision = git.update @chunky, "hack"
end
def app
Git::Store::Front
end
- context "/api" do
+ context "GET /api/:key" do
it "should return a value" do
get "/api/#{@chunky}"
last_response.body.should == "hack"
end
+ it "should return 404 in case a value doesn't exist" do
+ get "/api/undefined"
+ last_response.status.should == 404
+ end
+ end
+
+ context "GET /api/:revision/:key" do
it "should return a value for a given revision" do
- get "/api/#{@rev1}/#{@chunky}"
+ get "/api/#{@first_revision}/#{@chunky}"
last_response.body.should == "hackety"
end
-
- it "should return a 404 in case a value doesn't exist" do
- get "/api/undefined"
- last_response.status.should == 404
-
+
+ it "should return 404 in case a value doesn't exist" do
get "/api/undefined/undefined"
last_response.status.should == 404
end
+ end
+ context "POST /api" do
it "should create a new value and return its hash" do
post "/api", :value => "whyday"
last_response.body.should == "63996f2ada7cfff6d0943ce0fd33460e159cfd10"
end
+ end
+ context "PUT /api/:key" do
it "should update a value and return the new revision" do
post "/api", :value => "trady"
put "/api/#{last_response.body}", :value => "blix"
- git.type_of(last_response.body).should == "commit"
+ git.commit?(last_response.body).should be_true
end
+ end
+ context "DELETE /api/:key" do
it "should delete a value and return the new revision" do
post "/api", :value => "_why"
delete "/api/#{last_response.body}"
- git.type_of(last_response.body).should == "commit"
+ git.commit?(last_response.body).should be_true
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.