Permalink
Browse files

Multiple project support

  • Loading branch information...
1 parent d1bee1b commit 947cbc05375765b2d5bbc82ef77f0051d71131ed @AndrewVos AndrewVos committed Dec 16, 2011
View
@@ -1 +1,5 @@
require "bundler/gem_tasks"
+
+task :sample do
+ sh "bin/wally push http://localhost:4567/project features/"
+end
View
@@ -0,0 +1,12 @@
+Feature: Projects
+ In order to allow multiple projects
+ As a user
+ I want to be able to switch between projects
+
+ Scenario: Single project
+ Given a feature file on the project "project_name" with the contents:
+ """
+ Feature: Projects
+ """
+ And I visit the project page for "project_name"
+ Then I should see a link to the feature "Projects"
@@ -5,16 +5,16 @@ Feature: Push Features To Server
Scenario: Push features without authentication
Given I don't have a .wally authorisation file
- When I put data to /features with the authentication code
+ When I put data to /project/features with the authentication code
Then I should get a 403 http status
Scenario: Push features with authentication
Given I have a .wally authentication file
- When I put data to /features with the authentication code
+ When I put data to /project/features with the authentication code
Then I should get a 201 http status
Scenario: Pushed features show up on home page
Given I have a .wally authentication file
- When I put data to /features with the authentication code
+ When I put data to /project/features with the authentication code
And I visit the home page
Then I should see the uploaded feature
@@ -6,7 +6,7 @@
end
When /^I visit the sample feature page$/ do
- visit "/features/sample-feature"
+ visit "/project/features/sample-feature"
end
Then /^I should see the feature free\-form narrative$/ do
@@ -17,15 +17,14 @@
Then /^I should see Scenario headers as links$/ do
page.body.should have_content "Scenarios"
- page.should have_link "Sample Aidy", :href => "/features/sample-feature/scenario/sample-aidy"
- page.should have_link "Sample Andrew", :href => "/features/sample-feature/scenario/sample-andrew"
+ page.should have_link "Sample Aidy", :href => "/project/features/sample-feature/scenario/sample-aidy"
+ page.should have_link "Sample Andrew", :href => "/project/features/sample-feature/scenario/sample-andrew"
end
When /^click on a scenario header link$/ do
page.click_link "Sample Aidy"
end
-
Then /^a page appears with the scenario content$/ do
page.body.should have_content "Sample Aidy"
page.body.should have_content "Given my name is \"Aidy\""
@@ -3,7 +3,7 @@
1.upto(wip_tag_count.to_i) do |number|
contents += "@wip\nScenario: Scenario #{number}\n"
end
- create_feature("sample1.feature", contents)
+ create_feature("project", "sample1.feature", contents)
end
Then /^I should see a notification that says "([^"]*)"$/ do |text|
@@ -0,0 +1,11 @@
+Given /^a feature file on the project "([^"]*)" with the contents:$/ do |project, contents|
+ create_feature(project, "feature1.feature", contents)
+end
+
+Given /^I visit the project page for "([^"]*)"$/ do |project|
+ visit "/#{project}"
+end
+
+Then /^I should see a link to the feature "([^"]*)"$/ do |feature|
+ page.should have_link feature
+end
@@ -12,10 +12,10 @@
end
end
-When /^I put data to \/features with the authentication code$/ do
+When /^I put data to \/project\/features with the authentication code$/ do
gherkin = Wally::ParsesFeatures.new.parse("Feature: Feature Name")
data = [{:path => "feature-name.feature", :gherkin => gherkin}].to_json
- page.driver.put "/features?authentication_code=#{@authentication_code}", data
+ page.driver.put "/project/features?authentication_code=#{@authentication_code}", data
end
Then /^I should get a (\d+) http status$/ do |status|
@@ -1,5 +1,5 @@
Given /^I am on the search page$/ do
- visit "/search"
+ visit "/project/search"
end
When /^I search for "([^"]*)"$/ do |text|
@@ -1,10 +1,10 @@
Given /^a feature file named "([^"]*)" with the contents:$/ do |filename, contents|
@contents = contents
- create_feature(filename, @contents)
+ create_feature("project", filename, @contents)
end
When /^I visit the home page$/ do
- visit "/"
+ visit "/project"
end
Then /^I should see a link to "([^"]*)" with the url "([^"]*)"$/ do |text, url|
View
@@ -9,12 +9,20 @@
Capybara.app = Sinatra::Application
After do
- Wally::Feature.delete_all
+ Wally::Project.delete_all
end
-def create_feature path, content
- feature = Wally::Feature.new
- feature.path = path
- feature.gherkin = Wally::ParsesFeatures.new.parse(content)
- feature.save
+def project name
+ project = Wally::Project.first(:name => name)
+ unless project
+ project = Wally::Project.create(:name => name)
+ end
+ project
+end
+
+def create_feature project, path, content
+ project = project(project)
+ feature = Wally::Feature.new(:path => path, :gherkin => Wally::ParsesFeatures.new.parse(content))
+ project.features << feature
+ project.save
end
View
@@ -5,6 +5,3 @@
require "wally/version"
require "wally/application"
-require "wally/search_features"
-require "wally/counts_tags"
-require "wally/parses_features"
View
@@ -4,6 +4,10 @@
require "rdiscount"
require "mongo_mapper"
require "wally/feature"
+require "wally/project"
+require "wally/search_features"
+require "wally/counts_tags"
+require "wally/parses_features"
require "cgi"
configure do
@@ -19,18 +23,22 @@
MongoMapper.database = "wally"
end
+def current_project
+ Wally::Project.first(:name => params[:project])
+end
+
def tag_count
- Wally::CountsTags.new(Wally::Feature).count_tags
+ Wally::CountsTags.new(current_project).count_tags
end
def excessive_wip_tags
tag_count["@wip"] >= 10
end
def scenario_count
- Feature.all.inject(0) do |count, feature|
+ current_project.features.inject(0) do |count, feature|
if feature.gherkin["elements"]
- count += feature.gherkin["elements"].select { |e| e["type"] == "scenario" }
+ count += feature.gherkin["elements"].select { |e| e["type"] == "scenario" }.size
end
count
end
@@ -53,53 +61,52 @@ def highlighted_search_result_blurb search_result
highlighted
end
-put '/features/?' do
+put '/:project/features/?' do
if File.exist?(".wally") && params[:authentication_code] == File.read(".wally").strip
- Wally::Feature.delete_all
+ current_project.delete if current_project
+ project = Wally::Project.create(:name => "project")
JSON.parse(request.body.read).each do |json|
- feature = Wally::Feature.new
- feature.path = json["path"]
- feature.gherkin = json["gherkin"]
- feature.save
+ project.features << Wally::Feature.new(:path => json["path"], :gherkin => json["gherkin"])
end
+ project.save
halt 201
else
error 403
end
end
-get '/?' do
+get '/:project/?' do
haml :index
end
-get '/features/:feature/?' do |id|
- Wally::Feature.all.each do |feature|
- @feature = feature if feature.gherkin["id"] == id
+get '/:project/features/:feature/?' do
+ current_project.features.each do |feature|
+ @feature = feature if feature.gherkin["id"] == params[:feature]
end
haml :feature
end
-get '/progress/?' do
+get '/:project/progress/?' do
haml :progress
end
-get '/search/?' do
+get '/:project/search/?' do
if params[:q]
- @search_results = Wally::SearchFeatures.new(Wally::Feature).find(:query => params[:q])
+ @search_results = Wally::SearchFeatures.new(current_project).find(:query => params[:q])
end
haml :search
end
-get '/features/:feature/scenario/:scenario/?' do |feature_id, scenario_id|
- Wally::Feature.all.each do |feature|
- if feature.gherkin["id"] == feature_id
+get '/:project/features/:feature/scenario/:scenario/?' do
+ current_project.features.each do |feature|
+ if feature.gherkin["id"] == params[:feature]
@feature = feature
feature.gherkin["elements"].each do |element|
if element["type"] == "background"
@background = element
end
- if (element["type"] == "scenario" || element["type"] == "scenario_outline") && element["id"] == "#{feature_id};#{scenario_id}"
+ if (element["type"] == "scenario" || element["type"] == "scenario_outline") && element["id"] == "#{params[:feature]};#{params[:scenario]}"
@scenario = element
end
end
@@ -109,7 +116,7 @@ def highlighted_search_result_blurb search_result
end
def get_scenario_url(scenario)
- url = "/features/#{scenario["id"].gsub(";", "/scenario/")}"
+ url = "/#{current_project.name}/features/#{scenario["id"].gsub(";", "/scenario/")}"
end
def get_sorted_scenarios(feature)
View
@@ -1,11 +1,11 @@
module Wally
class CountsTags
- def initialize lists_features
- @lists_features = lists_features
+ def initialize project
+ @project = project
end
def count_tags
- @lists_features.all.inject(Hash.new(0)) do |tag_count, feature|
+ @project.features.inject(Hash.new(0)) do |tag_count, feature|
if feature.gherkin["tags"]
feature.gherkin["tags"].each do |tag|
tag_count[tag["name"].downcase] += 1
View
@@ -1,6 +1,6 @@
module Wally
class Feature
- include MongoMapper::Document
+ include MongoMapper::EmbeddedDocument
key :path, String
key :gherkin, Hash
View
@@ -0,0 +1,8 @@
+module Wally
+ class Project
+ include MongoMapper::Document
+
+ key :name, String
+ many :features, :class => Wally::Feature
+ end
+end
@@ -9,7 +9,7 @@ def initialize lists_features
def find(query)
searchables = []
- @lists_features.all.each do |feature|
+ @lists_features.features.each do |feature|
feature_text = feature.gherkin["name"]
if feature.gherkin["tags"]
feature_text += " " + feature.gherkin["tags"].map { |tag| tag["name"] }.join(" ")
@@ -1,5 +1,5 @@
%li
- %a{:href => "/features/#{feature.gherkin["id"]}"}
+ %a{:href => "/#{current_project.name}/features/#{feature.gherkin["id"]}"}
= feature.gherkin["name"]
- if feature.gherkin["tags"]
- tags = feature.gherkin["tags"]
@@ -10,29 +10,29 @@
%div.container-fluid
%div.logo
%h1
- %a{:href => "/"} Wally
+ %a{:href => "/#{current_project.name}/"} Wally
%div.search-bar
- %form{:method => "GET", :action => "/search", :id => "search"}
+ %form{:method => "GET", :action => "/#{current_project.name}/search", :id => "search"}
%input{:type => "text", :id => "q", :name => "q", :placeholder => 'text, @tags etc.', :value => @q }
%input.btn{:type => "submit", :id => "search", :value => "Search"}
%div.container-fluid
%div.sidebar
%ul
%li
- %a{:href => "/progress"}
+ %a{:href => "/#{current_project.name}/progress"}
Progress
%h2
- = "Features (#{Wally::Feature.all.count})"
+ = "Features (#{current_project.features.count})"
%ul
- - Wally::Feature.sort(:name).each do |feature|
+ - current_project.features.sort{|a,b| a.name <=> b.name}.each do |feature|
= haml :feature_link, {:locals => {:feature => feature}, :layout => false}
- if tag_count.any?
%h2
= "Tags (#{tag_count.values.sum})"
%ul
- tag_count.each do |tag, count|
%li
- %a{:href => "/search?q=#{tag}"}
+ %a{:href => "/#{current_project.name}/search?q=#{tag}"}
= "#{tag} (#{count})"
%div.content
- if excessive_wip_tags
@@ -5,13 +5,13 @@
- if @search_results.suggestion
%p
Did you mean
- %a{:href => "/search?q=#{@search_results.suggestion}"}
+ %a{:href => "/#{current_project.name}/search?q=#{@search_results.suggestion}"}
= @search_results.suggestion
%ul
- @search_results.items.map {|i| i.object.feature["id"] }.uniq.each do |current_feature_id|
- root_search_result = @search_results.items.find { |r| r.object.feature["id"] == current_feature_id }
%li
- %a{:href => "/features/#{root_search_result.object.feature["id"]}"}
+ %a{:href => "/#{current_project.name}/features/#{root_search_result.object.feature["id"]}"}
= root_search_result.object.feature["name"]
- if root_search_result.object.feature["tags"]
= haml :tag_links, {:locals => {:tags => root_search_result.object.feature["tags"]}, :layout => false}
@@ -21,7 +21,7 @@
- @search_results.items.select { |r| r.object.feature["id"] == current_feature_id }.each do |search_result|
- if search_result.object.scenario && search_result.object.scenario["id"]
%li
- %a{:href => "/features/#{search_result.object.scenario["id"].gsub(";", "/scenario/")}"}
+ %a{:href => "/#{current_project.name}/features/#{search_result.object.scenario["id"].gsub(";", "/scenario/")}"}
= search_result.object.scenario["name"]
- if search_result.object.scenario["tags"]
= haml :tag_links, {:locals => {:tags => search_result.object.scenario["tags"]}, :layout => false}
Oops, something went wrong.

0 comments on commit 947cbc0

Please sign in to comment.