repo
string
commit
string
message
string
diff
string
KeithHanson/rmuddy
bb89742a021159b0834105991f7b2bab2b77cd23
Tweaked the README a bit and added an INSTALL.
diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..7536408 --- /dev/null +++ b/INSTALL @@ -0,0 +1,33 @@ +To Install: + +You will need the following: +--A Version of KMuddy that supports External Scripting +--Ruby 1.8 installed +--Ruby headers installed +--Git installed, to download and checkout the latest version. + +If you are on an Ubuntu box, you can do the following after installing KMuddy: +In a command prompt, type: + +sudo apt-get install ruby1.8 +sudo apt-get install ruby1.8-dev +sudo apt-get install git +git clone git://github.com/KeithHanson/rmuddy.git ~/RMuddy + +After doing the above, simply go to: +Profile-->Scripts +Add... + Script Name: RMuddy + Command to Execute: ~/RMuddy/init.rb + Working Directory: ~/RMuddy/ + Check Single-Instance Script + Check Enable Error Output + Check Disable Flow Control + Check Communicate Variables +Click Ok + +Type into KMuddy: +/exec RMuddy + +If you receive any errors during the output, please feel free +to e-mail them to me and I'll do my best to address them. \ No newline at end of file diff --git a/README b/README index c1a1c10..ba5c06b 100644 --- a/README +++ b/README @@ -1,36 +1,36 @@ RMuddy is a Ruby based Triggering system for the MUD client Kmuddy (http://www.kmuddy.com). It is essentially an easier, more powerful way (in my opinion, at least) to create complex triggering and tracking systems using the KMuddy client. -With RMuddy, you have the flexibility of Ruby, and the ease -of using a well-built framework. You'll have commands like: +With RMuddy, you have the flexibility of Ruby, and the ability +to communicate with KMuddy. You'll have commands like: trigger /regular_expression/, :action before PluginName, :plugin_action, :hook_action after PluginName, :plugin_action, :hook_action send_kmuddy_command("command text") get_kmuddy_variable("variable_name") set_kmuddy_variable("variable_name", value) All of the magic happens inside of the enabled-plugins folder, which has an included README for you to peruse. The README will give you a quick run-down of how to use the system and how to create your own Plugins. Currently, the plugins in the enabled-plugins directory are all -written with Achaea (http://www.achaea.com) in mind, but they are -all easily adaptible. +written with Achaea in mind (http://www.achaea.com), but they are +all easily adaptible to your MUD of choice. Though the author uses the plugins during every MUDing session, be warned: the state of RMuddy is very volatile. The author is in no way responsible for the death of your character, dry mana vials, or any other mishap that may happen from RMuddy crashing or going haywire. That being said, Enjoy! \ No newline at end of file
KeithHanson/rmuddy
118d0347de9532781c872bcf2855cb2558d26ea0
Removed the forced parameters on actions, added main README.
diff --git a/README b/README new file mode 100644 index 0000000..c1a1c10 --- /dev/null +++ b/README @@ -0,0 +1,36 @@ +RMuddy is a Ruby based Triggering system for the MUD client +Kmuddy (http://www.kmuddy.com). It is essentially an easier, +more powerful way (in my opinion, at least) to create complex +triggering and tracking systems using the KMuddy client. + +With RMuddy, you have the flexibility of Ruby, and the ease +of using a well-built framework. You'll have commands like: + +trigger /regular_expression/, :action + +before PluginName, :plugin_action, :hook_action + +after PluginName, :plugin_action, :hook_action + +send_kmuddy_command("command text") + +get_kmuddy_variable("variable_name") + +set_kmuddy_variable("variable_name", value) + +All of the magic happens inside of the enabled-plugins folder, +which has an included README for you to peruse. The README will +give you a quick run-down of how to use the system and how to +create your own Plugins. + +Currently, the plugins in the enabled-plugins directory are all +written with Achaea (http://www.achaea.com) in mind, but they are +all easily adaptible. + +Though the author uses the plugins during every MUDing session, +be warned: the state of RMuddy is very volatile. The author is in +no way responsible for the death of your character, dry mana vials, +or any other mishap that may happen from RMuddy crashing or going +haywire. + +That being said, Enjoy! \ No newline at end of file diff --git a/configs/README b/configs/README index 8967169..52a4294 100644 --- a/configs/README +++ b/configs/README @@ -1,7 +1,7 @@ This folder is for config.yaml files for each plugin. The configs should be named the same name as the particular plugin. So, for instance, a CuringSystem plugin named curing_system.rb should be named curing_system.yaml. The RMuddy system will then know to -automatically pick that up parse it. \ No newline at end of file +automatically pick that up and parse it. \ No newline at end of file diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb index 86e40c9..451085b 100644 --- a/enabled-plugins/character.rb +++ b/enabled-plugins/character.rb @@ -1,49 +1,49 @@ module Character attr_accessor :character_current_health, :character_current_mana attr_accessor :character_total_health, :character_total_mana attr_accessor :character_balanced def character_setup @character_balanced = true trigger /^(\d+)h, (\d+)m\s.*/, :character_set_current_stats trigger /^Health: \d*\/(\d*)\s\sMana: \d*\/(\d*)$/, :character_set_total_stats trigger /You have recovered balance on all limbs./, :character_is_balanced trigger /^\d+h, \d+m\se-/, :character_is_unbalanced trigger /You reach out and bop/, :character_is_unbalanced end def character_set_current_stats(match_object ) @character_current_health = match_object[1].to_i @character_current_mana = match_object[2].to_i debug("Character: Loaded Current Stats") set_kmuddy_variable("character_current_health", @character_current_health) set_kmuddy_variable("character_current_mana", @character_current_mana) end def character_set_total_stats(match_object) @character_total_health = match_object[1].to_i @character_total_mana = match_object[2].to_i debug("Character: Loaded Total Stats") set_kmuddy_variable("character_total_health", @character_total_health) set_kmuddy_variable("character_total_mana", @character_total_mana) end - def character_is_balanced(match_object) + def character_is_balanced @character_balanced = true end - def character_is_unbalanced(match_object) + def character_is_unbalanced @character_balanced = false end end debug("Character: Character file required.") \ No newline at end of file diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb index 4389cce..c173681 100644 --- a/enabled-plugins/ratter.rb +++ b/enabled-plugins/ratter.rb @@ -1,84 +1,84 @@ module Ratter def ratter_setup @ratter_enabled = false @available_rats = 0 @inventory_rats = 0 @rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35} @total_rat_money = 0 - trigger /With a squeak, an*(\s)*(\w)* rat darts into the room, looking about wildly./, :rat_is_available - trigger /Your eyes are drawn to an*(\s)*(\w)* rat that darts suddenly into view./, :rat_is_available - trigger /An*(\s)*(\w)* rat noses its way cautiously out of the shadows./, :rat_is_available - trigger /An*(\s)*(\w)* rat wanders into view, nosing about for food./, :rat_is_available + trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available + trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available + trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available + trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat - trigger /An*(\s)*(\w)* rat wanders back into its warren where you may not follow./, :rat_is_unavailable - trigger /With a flick of its small whiskers, an*(\s)*(\w)* rat dashes out of view./, :rat_is_unavailable - trigger /An*(\s)*(\w)* rat darts into the shadows and disappears./, :rat_is_unavailable + trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable + trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable + trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter trigger /You will no longer take notice of the movement of rats\./, :disable_ratter trigger /Liirup squeals with delight/, :reset_money after Character, :character_is_balanced, :should_i_attack_rat? end def ratter_enabled? @ratter_enabled end def rat_available? @available_rats > 0 end - def rat_is_available(match_object) + def rat_is_available @available_rats += 1 if rat_available? && @character_balanced send_kmuddy_command("bop rat") end end - def rat_is_unavailable(match_object) + def rat_is_unavailable @available_rats -= 1 unless @available_rats <= 0 end def killed_rat(match_object) @available_rats -= 1 unless @available_rats <= 0 @inventory_rats += 1 @total_rat_money += @rat_prices[match_object[1]] set_kmuddy_variable("current_rat_count", @inventory_rats) set_kmuddy_variable("total_rat_money", @total_rat_money) end - def enable_ratter(match_object) + def enable_ratter @ratter_enabled = true end - def disable_ratter(match_object) + def disable_ratter @ratter_enabled = false end - def reset_money(match_object) + def reset_money @total_rat_money = 0 set_kmuddy_variable("total_rat_money", 0) @inventory_rats = 0 set_kmuddy_variable("current_rat_count", 0) end def should_i_attack_rat? if rat_available? && @character_balanced send_kmuddy_command("bop rat") end end end \ No newline at end of file diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb index 4211e22..9e31ac8 100644 --- a/enabled-plugins/sipper.rb +++ b/enabled-plugins/sipper.rb @@ -1,56 +1,56 @@ module Sipper def sipper_enabled? @sipper_enabled end def health_below_threshold? (@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage end def mana_below_threshold? (@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage end def sipper_setup @sipper_enabled = true @health_threshold_percentage = 70 @mana_threshold_percentage = 70 after Character, :character_set_current_stats, :should_i_sip? trigger /^Your mind feels stronger and more alert\.$/, :disable_sip trigger /^The elixer heals and soothes you\.$/, :disable_sip trigger /^What is it that you wish to drink\?$/, :disable_sip trigger /^You are asleep and can do nothing\./, :disable_sip trigger /^The elixer flows down your throat without effect/, :disable_sip trigger /Wisely preparing yourself beforehand/, :disable_sip trigger /^You may drink another .*$/, :enable_sip trigger /You have successfully inscribed the image/, :enable_sip end def should_i_sip? if @character_total_mana.nil? || @character_total_health.nil? send_kmuddy_command("score") else if health_below_threshold? && sipper_enabled? send_kmuddy_command("drink health") end if mana_below_threshold? && sipper_enabled? send_kmuddy_command("drink mana") end end end - def disable_sip(match_object) + def disable_sip @sipper_enabled = false end - def enable_sip(match_object) + def enable_sip @sipper_enabled = true end end diff --git a/receiver.rb b/receiver.rb index 5e72266..a845373 100644 --- a/receiver.rb +++ b/receiver.rb @@ -1,81 +1,81 @@ class Receiver attr_accessor :varsock, :matches, :setups debug("Receiver: Loading Files...") #Load All Plugins - Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*")].each do |file| + Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file| debug("Receiver: Found #{file}") require file include module_eval(File.basename(file, ".rb").capitalize) end def initialize @triggers = {} @setups = [] Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file| @setups << File.basename(file, ".rb") + "_setup" end @setups.each {|setup_string| send(setup_string.to_sym)} end def receive(text) @triggers.each_pair do |regex, method| debug("Testing #{regex} against line: #{text}") match = regex.match(text) unless match.nil? unless match[1].nil? send(method.to_sym, match) else send(method.to_sym) end else debug("No match!") end end end def trigger(regex, method) @triggers[regex] = method end def set_kmuddy_variable(variable_name, variable_value) @varsock.set(variable_name, variable_value) end def get_kmuddy_variable(variable_name) @varsock.get(variable_name) end def send_kmuddy_command(command_text) @varsock.command(command_text) end def before(module_name, method_symbol, hook_symbol) method = Ruby2Ruby.translate(module_name, method_symbol.to_sym) new_method = method.split("\n") new_method.insert(1, "send(:#{hook_symbol.to_s})") module_name.module_eval(new_method.join("\n")) end def after(module_name, method_symbol, hook_symbol) method = Ruby2Ruby.translate(module_name, method_symbol.to_sym) new_method = method.split("\n") new_method.insert(-2, "send(:#{hook_symbol.to_s})") module_name.module_eval(new_method.join("\n")) end def to_s "Receiver Loaded" end end \ No newline at end of file
KeithHanson/rmuddy
d4a2e89a7dd8186a6cac155b9b3f1f8e2289f807
Added README's and modified Receiver to handle them.
diff --git a/configs/README b/configs/README new file mode 100644 index 0000000..8967169 --- /dev/null +++ b/configs/README @@ -0,0 +1,7 @@ +This folder is for config.yaml files for each plugin. + +The configs should be named the same name as the particular plugin. + +So, for instance, a CuringSystem plugin named curing_system.rb should +be named curing_system.yaml. The RMuddy system will then know to +automatically pick that up parse it. \ No newline at end of file diff --git a/disabled-plugins/README b/disabled-plugins/README new file mode 100644 index 0000000..5b54d9b --- /dev/null +++ b/disabled-plugins/README @@ -0,0 +1 @@ +Place the plugins you do not wish to load here. \ No newline at end of file diff --git a/enabled-plugins/README b/enabled-plugins/README new file mode 100644 index 0000000..7ccf376 --- /dev/null +++ b/enabled-plugins/README @@ -0,0 +1,63 @@ +Enabled Plugins should be dropped here. + +A Quick and Dirty tutorial on Plugins: + +Each and every plugin should be named the same name as +the module it represents. + +For example, the Ratter plugin is named ratter.rb. and is defined +as module Ratter. + +Inside of every Module, you should have an _setup method. This method +gets called automatically whenever the module is loaded. It is here that +you will define your triggers and before/after filters. + +You define a trigger like so: +trigger /REGEXHERE/, :action_on_match + +After defining your triggers, you'll want to create a method that receives +the matches from your regular expression. Like so: + +#Here is an example that has matches and uses them: +def action_on_match(matches) + #Do things here + #access the first and second matches like so: + matches[1] + matches[2] +end + +#Here is an example that does not have any matches: +def action_on_match + #Do things here +end + +A NOTE ABOUT TRIGGER ACTIONS: +If your trigger's regular expression has backreferences/matches, +RMuddy will send the match object as a parameter to your action. + +If your trigger's regular expressions does not have backreferences, then +RMuddy will not send the match object. + +Code responsibly ;) + +BEFORE AND AFTER FILTERS +You can create before and after filters for firing off events before or +after an action is fired. You must define these in your _setup method. + +before PluginName, :plugin_action, :hook_action +after PluginName, :plugin_action, :hook_action + +This will fire the action 'hook_action', passing it no parameters. + + +SENDING INFORMATION TO KMUDDY +You have three methods, all of them pretty self explanatory: + +#This will send "command text" to the MUD +send_kmuddy_command("command text") + +#This will set $variable_name to value +set_kmuddy_variable("variable_name", value) + +#This will return the value of the kmuddy variable $variable_name +get_kmuddy_variable("variable_name") \ No newline at end of file diff --git a/receiver.rb b/receiver.rb index 3c049a4..5e72266 100644 --- a/receiver.rb +++ b/receiver.rb @@ -1,77 +1,81 @@ class Receiver attr_accessor :varsock, :matches, :setups debug("Receiver: Loading Files...") #Load All Plugins Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*")].each do |file| debug("Receiver: Found #{file}") require file include module_eval(File.basename(file, ".rb").capitalize) end def initialize @triggers = {} @setups = [] - Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*")].each do |file| + Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file| @setups << File.basename(file, ".rb") + "_setup" end @setups.each {|setup_string| send(setup_string.to_sym)} end def receive(text) @triggers.each_pair do |regex, method| debug("Testing #{regex} against line: #{text}") match = regex.match(text) unless match.nil? - send(method.to_sym, match) + unless match[1].nil? + send(method.to_sym, match) + else + send(method.to_sym) + end else debug("No match!") end end end def trigger(regex, method) @triggers[regex] = method end def set_kmuddy_variable(variable_name, variable_value) @varsock.set(variable_name, variable_value) end def get_kmuddy_variable(variable_name) @varsock.get(variable_name) end def send_kmuddy_command(command_text) @varsock.command(command_text) end def before(module_name, method_symbol, hook_symbol) method = Ruby2Ruby.translate(module_name, method_symbol.to_sym) new_method = method.split("\n") new_method.insert(1, "send(:#{hook_symbol.to_s})") module_name.module_eval(new_method.join("\n")) end def after(module_name, method_symbol, hook_symbol) method = Ruby2Ruby.translate(module_name, method_symbol.to_sym) new_method = method.split("\n") new_method.insert(-2, "send(:#{hook_symbol.to_s})") module_name.module_eval(new_method.join("\n")) end def to_s "Receiver Loaded" end end \ No newline at end of file
peteonrails/my-rails-utils
945b115a38db19b5b21a31cc37fed75a3f235060
Initial cut of the Intridea template. Starting point only. not ready for you to use.
diff --git a/README b/README index 8dfd6bc..cb39ceb 100644 --- a/README +++ b/README @@ -1,16 +1,20 @@ If you were using "new_rails" before Rails 2.2 introduced the project templating DSL, you we a pretty smart developer. If you're STILL using new_rails, then you're missing out on a sweet project definition language. Check out the fasteragile.rb template for details. If you're doing this: -utils/new_rails myproject + utils/new_rails myproject STOP! Do this instead: -rails myproject -m utils/fasteragile.rb + rails myproject -m utils/fasteragile.rb + +Or, even better: + + rails myproject -m intridea.rb + -Thanks! \ No newline at end of file diff --git a/intridea.rb b/intridea.rb new file mode 100644 index 0000000..44b9c95 --- /dev/null +++ b/intridea.rb @@ -0,0 +1,583 @@ +# Run this template like this: +# rails <myproject> -m intridea.rb +# +# Or if you want to live on the bleeding edge you can use the gist-based template: +# rails <myproject> -m http://gist.github.com/gists/182433 +# +# Author: Peter Jackson +# License: MIT License +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +puts "Applying the Intreda template. Copyright 2012 Intridea, Inc." + +git :init +git :add => "." +git :commit => "-a -m 'Initial Commit -- Before template apply'" + +gem 'omniauth' +plugin 'hoptoad_notifier', :git => 'git://github.com/thoughtbot/hoptoad_notifier.git', :submodule => true +plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :submodule => true +plugin 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl', :submodule => true +# plugin 'limerick_rake', :git => 'git://github.com/thoughtbot/limerick_rake.git', :submodule => true +# plugin "peteonrails-seo-kit", :git => "git://github.com/peteonrails/seo-kit.git", :submodule => true + +git :submodule => "init" + +gem 'will_paginate' +gem 'haml' +gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on" +gem 'w3c_validators', :version => '0.9.3' +gem 'friendly_id' +gem "peteonrails-simple_tooltips", :lib => "simple_tooltips",:source => 'http://gems.github.com' +gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu" + +rake("gems:install", :sudo => true) +rake("gems:unpack") + +run("haml --rails .") + +run 'mkdir app/views/pages' +file 'app/views/pages/home.html.haml', +%q{.mouseover1 + This is the home page! + += tooltip_for "mouseover1", "Here's the hint!" +} + +file 'app/views/layouts/application.html.haml', +%q{%html + %head + %title= application_title("FasterAgile", controller.controller_name, controller.action_name) + = yield :head + = stylesheet_link_tag "application", "tooltip" + = javascript_include_tag :defaults + + %body + #flash= flash_notices + #header + #logo + = render :partial => "shared/logo" + .clearfix + #topnav + = render :partial => 'shared/topnav' + #outer-container + #main-content + = yield + .clearfloat + #footer + #footer-content.ctr + = render :partial => 'shared/footer' + = yield :javascript + = render :partial => 'shared/analytics' +} + +file 'app/helpers/application_helper.rb', +%q{# --- +module ApplicationHelper + def application_title(name, controller, action) + "#{name} #{controller} #{action}" + end + + def flash_notices + flash_types = [:error, :warning, :notice] + + messages = ((flash_types & flash.keys).collect do |key| + "$.jGrowl('#{flash[key]}', { header: '#{I18n.t(key, :default => key.to_s)}', theme: '#{key.to_s}'});" + end.join("\n")) + + if messages.size > 0 + content_tag(:script, :type => "text/javascript") do + "$(document).ready(function() { #{messages} });" + end + else + "" + end + end +end +} + +run 'mkdir -p public/stylesheets/sass' +file 'public/stylesheets/sass/util.sass', +%q{.clearfix + :clear both + :width 100% + :height 0 +} + +file 'public/stylesheets/sass/navigation.sass', +%q{@import colors.sass + +#topnav + :margin 0 auto + :width= !content_width + :height 100% + :padding 0px + + .lefttab + :width auto + :margin-right= !tabmargin + :padding= !tabpadding + :float left + :font-weight bold + + .righttab + :width auto + :margin-left= !tabmargin + :padding= !tabpadding + :float right + :font-weight bold + + .selected + :background-color= !white + :color= !black + a + :color= !black + :text-decoration none + + .unselected + :background-color= !black + :color= !white + a + :color= !white + :text-decoration none +} + +file 'public/stylesheets/sass/application.sass', +%q{@import colors.sass +@import navigation.sass +@import util.sass + +html, body + :height 100% + +body + :font 100% Arial, Verdana, sans-serif + :font-size 14px + :background-color= !white + :margin 0 + :padding 0 + :text-align center + :color= !textcolor + +#footer + :background url(../images/footer.jpg) repeat-x + :margin 0px + :width 100% + :height= !footer_height + :position relative + + #footer-content + :width= !content_width + :margin 0 auto + :padding-top 20px + +#header + :background url(../images/header.jpg) repeat-x + :height 99px + + #logo + :margin 0px auto + :width= !content_width + :font-size 3.0em + :font-weight bold + :height 65px + +#outer-container + :width= !content_width + :margin 0px auto + :background= !white + :text-align left + :min-height 70% + :position relative + +#main-content + :padding 10px + + #centerpanel + :margin-top 30px + :margin-left auto + :margin-right auto + :width 80% + :border #000 1px solid important + :color= !textcolor + :font-size 1.75em + + .headline + :width 80% + .sub-headline + :font-size 0.75em + :font-weight bold + .message + :margin-top 20px + :font-size 0.75em +} + +file 'public/robots.txt', +%q{# Ban all spiders from indeing the site until we are ready for SEO launch. +User-Agent: * +Disallow: / +} + +file 'config/deploy.rb', +%q{set :stages, %w(staging production) +set :default_stage, 'staging' +require 'capistrano/ext/multistage' + +before "deploy:setup", "db:password" + +namespace :deploy do + desc "Default deploy - updated to run migrations" + task :default do + set :migrate_target, :latest + update_code + migrate + symlink + restart + end + + desc "Run this after every successful deployment" + task :after_default do + cleanup + end + + before :deploy do + if real_revision.empty? + raise "The tag, revision, or branch #{revision} does not exist." + end + end +end + +namespace :db do + desc "Create database password in shared path" + task :password do + set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") } + run "mkdir -p #{shared_path}/config" + put db_password, "#{shared_path}/config/dbpassword" + end +end + +} + +run 'mkdir config/deploy' + +file 'config/deploy/staging.rb', +%q{# For migrations +set :rails_env, 'staging' + +default_run_options[:pty] = true + +# Who are we? +set :application, CHANGEME +set :repository, CHANGEME +set :scm, "git" +set :deploy_via, :remote_cache +set :branch, "staging" +set :group_writable, false + +# Where to deploy to? +role :web, "staging.CHANGEME.com" +role :app, "staging.CHANGEME.com" +role :db, "staging.CHANGEME.com", :primary => true + +# Deploy details +set :user, CHANGEME +set :deploy_to, "/home/#{user}/apps/#{application}" +set :use_sudo, false +set :checkout, 'export' + +# We need to know how to use mongrel +set :mongrel_rails, '/usr/local/bin/mongrel_rails' +set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_staging.yml" + +namespace :deploy do + after "deploy:restart", + "deploy:railsplayground:fix_permissions", + "deploy:railsplayground:set_production" , + "deploy:railsplayground:kill_dispatch_fcgi", + "deploy:railsplayground:copy_htaccess" + + desc "RailsPlayground version of restart task." + task :restart do + railsplayground::kill_dispatch_fcgi + end + + namespace :railsplayground do + + desc "Uncomment the RAILS_ENV setting" + task :set_production do + run "sed -i.cap.orig -e 's/^# ENV/ENV/' #{release_path}/config/environment.rb" + end + + desc "Kills Ruby instances on RailsPlayground" + task :kill_dispatch_fcgi do + run "pkill -9 -u #{user} -f dispatch.fcgi" + end + + desc "Fix g-w issues with RailsPlayground" + task :fix_permissions do + run "cd #{current_path}; chmod -R g-w *" + end + + desc "Copy over the RailsPlayground htaccess file" + task :copy_htaccess do + run "cp #{shared_path}/config/htaccess #{release_path}/public/.htaccess" + end + + end +end +} + +run "mkdir -p app/views/shared" +file "app/views/shared/_logo.html.haml", "#logo" +file "app/views/shared/_topnav.html.haml", "#topnav" +file "app/views/shared/_footer.html.haml", "#footer" +file "app/views/shared/_analytics.html.haml", +%q{%script{ :type => "text/javascript" } + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); + +%script{ :type => "text/javascript" } + try { + var pageTracker = _gat._getTracker("ENTER TRACKER ID"); + pageTracker._trackPageview(); + } catch(err) {}</script> +} + +file 'config/deploy/production.rb', +%q{# For migrations +set :rails_env, 'production' + +# Who are we? +set :application, CHANGEME +set :repository, CHANGEME +set :scm, "git" +set :deploy_via, :remote_cache +set :branch, "production" + +# Where to deploy to? +role :web, "www.CHANGEME.com" +role :app, "www.CHANGEME.com" +role :db, "www.CHANGEME.com", :primary => true + +# Deploy details +set :user, "#{application}" +set :deploy_to, "/home/#{user}/apps/#{application}" +set :use_sudo, false +set :checkout, 'export' + +# We need to know how to use mongrel +set :mongrel_rails, '/usr/local/bin/mongrel_rails' +set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_production.yml" +} + +# I still use the dispatchers and fast_cgi in my staging environment. :) +file 'public/.htaccess', +%q{# --- +Options +FollowSymLinks +ExecCGI +AddHandler cgi-script .cgi + +RewriteEngine On +RewriteRule ^$ index.html [QSA] +RewriteRule ^([^.]+)$ $1.html [QSA] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] +ErrorDocument 500 /500.html +} + +run 'mkdir -p "public/stylesheets/sass"' +file 'public/stylesheets/sass/application.sass', "@import colors.sass" + +file 'public/stylesheets/sass/colors.sass', +%q{!white = #f1f1f1 +!black = #000 +!blue = #cfe0f0 +} + +file 'config/initializers/hoptoad.rb', +%q{ +HoptoadNotifier.configure do |config| + config.api_key = '' +end +} + +file 'config/initializers/time_formats.rb', +%q[ +{ :short_date => "%x", # 01/03/74 + :long_date => "%a, %b %d, %Y", # Mon, Sep 7, 2009 + :header_date => "%A, %B %d, %Y", # Tuesday, Sep 07, 2009 + :ics => "%Y%m%dT%H%M%S", # 20090907T120000 (formatted for ICS / iCal / vCal) + :w3cdate => '%Y-%m-%d' +}.each do |k, v| + ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v) +end +] + +file 'config/initializers/array.rb', +%q{# --- +class Array + # If +number+ is greater than the size of the array, the method + # will simply return the array itself sorted randomly + def randomly_pick(number) + sort_by{ rand }.slice(0...number) + end +end +} + +file "lib/tasks/css.rake", +%q{# --- + require 'w3c_validators' + + def error_messages_for_results(results) + "Error details follow:" + + results.errors.inject("\n") do |memo, err| + memo += " * #{err.message.strip} at line #{err.line.to_s}" + end + end + + namespace :css do + include W3CValidators + desc "Validate all CSS as W3C compliant" + task :validate => :environment do + v = CSSValidator.new + v.set_profile!(:css3) + Dir.glob(File.join(RAILS_ROOT, 'public', 'stylesheets', '*.css')) do |file| + results = v.validate_file(file) + puts "CSS File: #{file}: " + ((results.errors.length == 0) ? "Valid!" : error_messages_for_results(results)) + end + end + end +} + +file 'config/environments/cucumber.rb', +%q{# --- +config.cache_classes = true # This must be true for Cucumber to operate correctly! + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_controller.perform_caching = false + +# Disable request forgery protection in test environment +config.action_controller.allow_forgery_protection = false + +# Tell Action Mailer not to deliver emails to the real world. +# The :test delivery method accumulates sent emails in the +# ActionMailer::Base.deliveries array. +config.action_mailer.delivery_method = :test + +config.gem 'thoughtbot-factory_girl', + :lib => 'factory_girl', + :source => 'http://gems.github.com', + :version => '>= 1.2.0' + +# Cucumber and dependencies +config.gem 'polyglot', + :version => '0.2.6', + :lib => false +config.gem 'treetop', + :version => '1.2.6', + :lib => false +config.gem 'term-ansicolor', + :version => '1.0.3', + :lib => false +config.gem 'diff-lcs', + :version => '1.1.2', + :lib => false +config.gem 'builder', + :version => '2.1.2', + :lib => false +config.gem 'cucumber', + :version => '0.3.11' + +# Webrat and dependencies +# NOTE: don't vendor nokogiri - it's a binary Gem +config.gem 'nokogiri', + :version => '1.3.3', + :lib => false +config.gem 'webrat', + :version => '0.4.4' + +HOST = 'localhost' +} + +file 'config/routes.rb', +%q{ActionController::Routing::Routes.draw do |map| + map.root :controller => "high_voltage/pages", :action => "show", :id => "home" + map.connect '/sitemap.xml', :controller => 'sitemap', :action => "sitemap", :format => "xml" + # Defaults routes have been removed: If you need them, uncomment these two lines + # map.connect ':controller/:action/:id' + # map.connect ':controller/:action/:id.:format' +end +} + + +run 'mkdir db/populate' +run 'mkdir db/populate/development' +run 'mkdir db/populate/staging' +run 'mkdir db/populate/production' + +inside 'public/javascripts' do + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/jquery.tooltip.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/jquery.formtooltip.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/lib/jquery.dimensions.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/checkboxes/jquery.checkboxes.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/autocomplete/jquery.autocomplete.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tablesorter/jquery.tablesorter.js' +end + +inside 'public/stylesheets' do + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/autocomplete/jquery.autocomplete.css' + run 'css2saas jquery.autocomplete.css sass/jquery.autocomplete.sass' +end + + +run 'rm public/index.html' +run 'rm public/javascripts/prototype.js' +run 'rm public/javascripts/effects.js' +run 'rm public/javascripts/controls.js' +run 'rm public/javascripts/dragdrop.js' +run 'rmdir test/fixtures' + +generate('tooltip') +generate('vote_fu') +generate('seo_kit') + +rake("db:migrate") +run('capify .') + +git :add => '.' +git :commit => '-a -m "After template application is complete."' + +# Start up VIM with the files I want to edit +run 'vim .' +run 'vim config/email.yml' +run 'vim app/views/layouts/application.html.haml' +run 'vim public/stylesheets/sass/colors.sass' +run 'vim public/stylesheets/sass/application.sass' +run 'vim config/database.yml' +run 'vim config/initializers/hoptoad.rb' +run 'vim config/routes.rb' + + diff --git a/new_rails b/new_rails deleted file mode 100755 index 58e16e9..0000000 --- a/new_rails +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -echo "new_rails is deprecated." -echo "Try this instead:" -echo "# rails $1 -m fasteragile.rb" \ No newline at end of file
peteonrails/my-rails-utils
23d7163c1220a5058519eea09f6085f4b41a06d0
Add readme
diff --git a/README b/README new file mode 100644 index 0000000..8dfd6bc --- /dev/null +++ b/README @@ -0,0 +1,16 @@ +If you were using "new_rails" before Rails 2.2 introduced the +project templating DSL, you we a pretty smart developer. If you're +STILL using new_rails, then you're missing out on a sweet project +definition language. + +Check out the fasteragile.rb template for details. + +If you're doing this: + +utils/new_rails myproject + +STOP! Do this instead: + +rails myproject -m utils/fasteragile.rb + +Thanks! \ No newline at end of file
peteonrails/my-rails-utils
f4d178a7d62309453377a1f4cee9cbdd8968a60d
Replace new_rails with a template using the DSL
diff --git a/fasteragile.rb b/fasteragile.rb new file mode 100644 index 0000000..602feb5 --- /dev/null +++ b/fasteragile.rb @@ -0,0 +1,610 @@ +# This template represents what FasterAgile believes to be the best mix +# of components for ab-initio Rails projects. It includes: +# Mocks with factory_girl instead of fixtures; cucumber and shoulda; friendly_ids +# and canonical links for SEO; HAML and SASS; the Clearance engine; basic sass +# and haml starter files; my favorite plugins and initializers; some utility +# methods that I always use. +# +# Run this template like this: +# rails <myproject> -m fasteragile.rb +# +# Or if you want to live on the bleeding edge you can use the gist-based template: +# rails <myproject> -m http://gist.github.com/gists/182433 +# +# Copyright 2009 Faster Agile, LLC +# Author: Peter Jackson +# http://www.fasteragile.com +# License: MIT License +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Faster Agile's Translation: You may copy, use, and extend this template for any purpose, +# including commercial purposes, but you must leave this comment intact. + +puts "Applying Faster Agile template. Copyright 2009 FasterAgile LLC." + +git :init +git :add => "." +git :commit => "-a -m 'Initial Commit -- Before template apply'" + +plugin 'acts_as_state_machine', :svn => 'http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk' +plugin 'jrails', :svn => 'http://ennerchi.googlecode.com/svn/trunk/plugins/jrails' +plugin 'yaml_mail_config', :svn => 'svn://rubyforge.org/var/svn/slantwise/yaml_mail_config/trunk yaml_mail_config' + +run 'cp vendor/plugins/yaml_mail_config/templates/email.example.yml config/email.yml' + +plugin 'hoptoad_notifier', :git => 'git://github.com/thoughtbot/hoptoad_notifier.git', :submodule => true +plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :submodule => true +plugin 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl', :submodule => true +plugin 'shoulda', :git => 'git://github.com/thoughtbot/shoulda.git', :submodule => true +plugin 'high_voltage', :git => 'git://github.com/thoughtbot/high_voltage.git', :submodule => true +plugin 'limerick_rake', :git => 'git://github.com/thoughtbot/limerick_rake.git', :submodule => true +plugin 'db_populate', :git => 'git://github.com/ffmike/db-populate.git', :submodule => true +plugin 'paperclippolymorph', :git => 'git://github.com/heavysixer/paperclippolymorph.git', :submodule => true +plugin 'growlr', :git => 'git://github.com/vanntastic/growlr.git', :submodule => true +plugin "peteonrails-seo-kit", :git => "git://github.com/peteonrails/seo-kit.git", :submodule => true + +git :submodule => "init" + +gem 'will_paginate' +gem 'haml', :version => ">= 2.2.5" +gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on" +gem "thoughtbot-clearance", :lib => 'clearance', :source => 'http://gems.github.com', :version => '0.8.2' +gem 'w3c_validators', :version => '0.9.3' +gem 'friendly_id' +gem 'fastercsv' +gem "peteonrails-simple_tooltips", :lib => "simple_tooltips",:source => 'http://gems.github.com' +gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu" + +rake("gems:install", :sudo => true) +rake("gems:unpack") + +run("haml --rails .") + +run 'mkdir app/views/pages' +file 'app/views/pages/home.html.haml', +%q{.mouseover1 + This is the home page! + += tooltip_for "mouseover1", "Here's the hint!" +} + +file 'app/views/layouts/application.html.haml', +%q{%html + %head + %title= application_title("FasterAgile", controller.controller_name, controller.action_name) + = yield :head + = stylesheet_link_tag "application", "tooltip" + = javascript_include_tag :defaults + + %body + #flash= flash_notices + #header + #logo + = render :partial => "shared/logo" + .clearfix + #topnav + = render :partial => 'shared/topnav' + #outer-container + #main-content + = yield + .clearfloat + #footer + #footer-content.ctr + = render :partial => 'shared/footer' + = yield :javascript + = render :partial => 'shared/analytics' +} + +file 'app/helpers/application_helper.rb', +%q{# --- +module ApplicationHelper + def application_title(name, controller, action) + "#{name} #{controller} #{action}" + end + + def flash_notices + flash_types = [:error, :warning, :notice] + + messages = ((flash_types & flash.keys).collect do |key| + "$.jGrowl('#{flash[key]}', { header: '#{I18n.t(key, :default => key.to_s)}', theme: '#{key.to_s}'});" + end.join("\n")) + + if messages.size > 0 + content_tag(:script, :type => "text/javascript") do + "$(document).ready(function() { #{messages} });" + end + else + "" + end + end +end +} + +run 'mkdir -p public/stylesheets/sass' +file 'public/stylesheets/sass/util.sass', +%q{.clearfix + :clear both + :width 100% + :height 0 +} + +file 'public/stylesheets/sass/navigation.sass', +%q{@import colors.sass + +#topnav + :margin 0 auto + :width= !content_width + :height 100% + :padding 0px + + .lefttab + :width auto + :margin-right= !tabmargin + :padding= !tabpadding + :float left + :font-weight bold + + .righttab + :width auto + :margin-left= !tabmargin + :padding= !tabpadding + :float right + :font-weight bold + + .selected + :background-color= !white + :color= !black + a + :color= !black + :text-decoration none + + .unselected + :background-color= !black + :color= !white + a + :color= !white + :text-decoration none +} + +file 'public/stylesheets/sass/application.sass', +%q{@import colors.sass +@import navigation.sass +@import util.sass + +html, body + :height 100% + +body + :font 100% Arial, Verdana, sans-serif + :font-size 14px + :background-color= !white + :margin 0 + :padding 0 + :text-align center + :color= !textcolor + +#footer + :background url(../images/footer.jpg) repeat-x + :margin 0px + :width 100% + :height= !footer_height + :position relative + + #footer-content + :width= !content_width + :margin 0 auto + :padding-top 20px + +#header + :background url(../images/header.jpg) repeat-x + :height 99px + + #logo + :margin 0px auto + :width= !content_width + :font-size 3.0em + :font-weight bold + :height 65px + +#outer-container + :width= !content_width + :margin 0px auto + :background= !white + :text-align left + :min-height 70% + :position relative + +#main-content + :padding 10px + + #centerpanel + :margin-top 30px + :margin-left auto + :margin-right auto + :width 80% + :border #000 1px solid important + :color= !textcolor + :font-size 1.75em + + .headline + :width 80% + .sub-headline + :font-size 0.75em + :font-weight bold + .message + :margin-top 20px + :font-size 0.75em +} + +file 'public/robots.txt', +%q{# Ban all spiders from indeing the site until we are ready for SEO launch. +User-Agent: * +Disallow: / +} + +file 'config/deploy.rb', +%q{set :stages, %w(staging production) +set :default_stage, 'staging' +require 'capistrano/ext/multistage' + +before "deploy:setup", "db:password" + +namespace :deploy do + desc "Default deploy - updated to run migrations" + task :default do + set :migrate_target, :latest + update_code + migrate + symlink + restart + end + + desc "Run this after every successful deployment" + task :after_default do + cleanup + end + + before :deploy do + if real_revision.empty? + raise "The tag, revision, or branch #{revision} does not exist." + end + end +end + +namespace :db do + desc "Create database password in shared path" + task :password do + set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") } + run "mkdir -p #{shared_path}/config" + put db_password, "#{shared_path}/config/dbpassword" + end +end + +} + +run 'mkdir config/deploy' + +file 'config/deploy/staging.rb', +%q{# For migrations +set :rails_env, 'staging' + +default_run_options[:pty] = true + +# Who are we? +set :application, CHANGEME +set :repository, CHANGEME +set :scm, "git" +set :deploy_via, :remote_cache +set :branch, "staging" +set :group_writable, false + +# Where to deploy to? +role :web, "staging.CHANGEME.com" +role :app, "staging.CHANGEME.com" +role :db, "staging.CHANGEME.com", :primary => true + +# Deploy details +set :user, CHANGEME +set :deploy_to, "/home/#{user}/apps/#{application}" +set :use_sudo, false +set :checkout, 'export' + +# We need to know how to use mongrel +set :mongrel_rails, '/usr/local/bin/mongrel_rails' +set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_staging.yml" + +namespace :deploy do + after "deploy:restart", + "deploy:railsplayground:fix_permissions", + "deploy:railsplayground:set_production" , + "deploy:railsplayground:kill_dispatch_fcgi", + "deploy:railsplayground:copy_htaccess" + + desc "RailsPlayground version of restart task." + task :restart do + railsplayground::kill_dispatch_fcgi + end + + namespace :railsplayground do + + desc "Uncomment the RAILS_ENV setting" + task :set_production do + run "sed -i.cap.orig -e 's/^# ENV/ENV/' #{release_path}/config/environment.rb" + end + + desc "Kills Ruby instances on RailsPlayground" + task :kill_dispatch_fcgi do + run "pkill -9 -u #{user} -f dispatch.fcgi" + end + + desc "Fix g-w issues with RailsPlayground" + task :fix_permissions do + run "cd #{current_path}; chmod -R g-w *" + end + + desc "Copy over the RailsPlayground htaccess file" + task :copy_htaccess do + run "cp #{shared_path}/config/htaccess #{release_path}/public/.htaccess" + end + + end +end +} + +run "mkdir -p app/views/shared" +file "app/views/shared/_logo.html.haml", "#logo" +file "app/views/shared/_topnav.html.haml", "#topnav" +file "app/views/shared/_footer.html.haml", "#footer" +file "app/views/shared/_analytics.html.haml", +%q{%script{ :type => "text/javascript" } + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); + +%script{ :type => "text/javascript" } + try { + var pageTracker = _gat._getTracker("ENTER TRACKER ID"); + pageTracker._trackPageview(); + } catch(err) {}</script> +} + +file 'config/deploy/production.rb', +%q{# For migrations +set :rails_env, 'production' + +# Who are we? +set :application, CHANGEME +set :repository, CHANGEME +set :scm, "git" +set :deploy_via, :remote_cache +set :branch, "production" + +# Where to deploy to? +role :web, "www.CHANGEME.com" +role :app, "www.CHANGEME.com" +role :db, "www.CHANGEME.com", :primary => true + +# Deploy details +set :user, "#{application}" +set :deploy_to, "/home/#{user}/apps/#{application}" +set :use_sudo, false +set :checkout, 'export' + +# We need to know how to use mongrel +set :mongrel_rails, '/usr/local/bin/mongrel_rails' +set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_production.yml" +} + +# I still use the dispatchers and fast_cgi in my staging environment. :) +file 'public/.htaccess', +%q{# --- +Options +FollowSymLinks +ExecCGI +AddHandler cgi-script .cgi + +RewriteEngine On +RewriteRule ^$ index.html [QSA] +RewriteRule ^([^.]+)$ $1.html [QSA] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] +ErrorDocument 500 /500.html +} + +run 'mkdir -p "public/stylesheets/sass"' +file 'public/stylesheets/sass/application.sass', "@import colors.sass" + +file 'public/stylesheets/sass/colors.sass', +%q{!white = #f1f1f1 +!black = #000 +!blue = #cfe0f0 +} + +file 'config/initializers/hoptoad.rb', +%q{ +HoptoadNotifier.configure do |config| + config.api_key = '' +end +} + +file 'config/initializers/time_formats.rb', +%q[ +{ :short_date => "%x", # 01/03/74 + :long_date => "%a, %b %d, %Y", # Mon, Sep 7, 2009 + :header_date => "%A, %B %d, %Y", # Tuesday, Sep 07, 2009 + :ics => "%Y%m%dT%H%M%S", # 20090907T120000 (formatted for ICS / iCal / vCal) + :w3cdate => '%Y-%m-%d' +}.each do |k, v| + ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v) +end +] + +file 'config/initializers/array.rb', +%q{# --- +class Array + # If +number+ is greater than the size of the array, the method + # will simply return the array itself sorted randomly + def randomly_pick(number) + sort_by{ rand }.slice(0...number) + end +end +} + +file "lib/tasks/css.rake", +%q{# --- + require 'w3c_validators' + + def error_messages_for_results(results) + "Error details follow:" + + results.errors.inject("\n") do |memo, err| + memo += " * #{err.message.strip} at line #{err.line.to_s}" + end + end + + namespace :css do + include W3CValidators + desc "Validate all CSS as W3C compliant" + task :validate => :environment do + v = CSSValidator.new + v.set_profile!(:css3) + Dir.glob(File.join(RAILS_ROOT, 'public', 'stylesheets', '*.css')) do |file| + results = v.validate_file(file) + puts "CSS File: #{file}: " + ((results.errors.length == 0) ? "Valid!" : error_messages_for_results(results)) + end + end + end +} + +file 'config/environments/cucumber.rb', +%q{# --- +config.cache_classes = true # This must be true for Cucumber to operate correctly! + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_controller.perform_caching = false + +# Disable request forgery protection in test environment +config.action_controller.allow_forgery_protection = false + +# Tell Action Mailer not to deliver emails to the real world. +# The :test delivery method accumulates sent emails in the +# ActionMailer::Base.deliveries array. +config.action_mailer.delivery_method = :test + +config.gem 'thoughtbot-factory_girl', + :lib => 'factory_girl', + :source => 'http://gems.github.com', + :version => '>= 1.2.0' + +# Cucumber and dependencies +config.gem 'polyglot', + :version => '0.2.6', + :lib => false +config.gem 'treetop', + :version => '1.2.6', + :lib => false +config.gem 'term-ansicolor', + :version => '1.0.3', + :lib => false +config.gem 'diff-lcs', + :version => '1.1.2', + :lib => false +config.gem 'builder', + :version => '2.1.2', + :lib => false +config.gem 'cucumber', + :version => '0.3.11' + +# Webrat and dependencies +# NOTE: don't vendor nokogiri - it's a binary Gem +config.gem 'nokogiri', + :version => '1.3.3', + :lib => false +config.gem 'webrat', + :version => '0.4.4' + +HOST = 'localhost' +} + +file 'config/routes.rb', +%q{ActionController::Routing::Routes.draw do |map| + map.root :controller => "high_voltage/pages", :action => "show", :id => "home" + map.connect '/sitemap.xml', :controller => 'sitemap', :action => "sitemap", :format => "xml" + # Defaults routes have been removed: If you need them, uncomment these two lines + # map.connect ':controller/:action/:id' + # map.connect ':controller/:action/:id.:format' +end +} + + +run 'mkdir db/populate' +run 'mkdir db/populate/development' +run 'mkdir db/populate/staging' +run 'mkdir db/populate/production' + +inside 'public/javascripts' do + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/jquery.tooltip.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/jquery.formtooltip.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tooltip/lib/jquery.dimensions.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/checkboxes/jquery.checkboxes.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/autocomplete/jquery.autocomplete.js' + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/tablesorter/jquery.tablesorter.js' +end + +inside 'public/stylesheets' do + run 'wget http://jqueryjs.googlecode.com/svn/trunk/plugins/autocomplete/jquery.autocomplete.css' + run 'css2saas jquery.autocomplete.css sass/jquery.autocomplete.sass' +end + + +run 'rm public/index.html' +run 'rm public/javascripts/prototype.js' +run 'rm public/javascripts/effects.js' +run 'rm public/javascripts/controls.js' +run 'rm public/javascripts/dragdrop.js' +run 'rmdir test/fixtures' + +generate("clearance") +generate('tooltip') +generate('vote_fu') +generate('polymorphic_paperclip') +generate('seo_kit') + +rake("db:migrate") +rake("growlr:install:all") +run('capify .') + +git :add => '.' +git :commit => '-a -m "After template application is complete."' + +# Start up TextMate with the files I want to edit +run 'mate .' +run 'mate config/email.yml' +run 'mate app/views/layouts/application.html.haml' +run 'mate public/stylesheets/sass/colors.sass' +run 'mate public/stylesheets/sass/application.sass' +run 'mate config/database.yml' +run 'mate config/initializers/hoptoad.rb' +run 'mate config/routes.rb' + + diff --git a/new_rails b/new_rails index d075c4a..58e16e9 100755 --- a/new_rails +++ b/new_rails @@ -1,80 +1,4 @@ -#!/bin/bash - -echo "************************************************" -echo " Creating New Rails Project: $1 " -echo "************************************************" -rails $1 - -echo "************************************************" -echo " Adding HAML" -echo "************************************************" -haml --rails $1 -cd $1 - -echo "************************************************" -echo " Installing Plugins " -echo "************************************************" -echo "****** RSpec " -script/plugin install git://github.com/dchelimsky/rspec.git -r 1.1.4 -echo "****** RSpec Rails " -script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 1.1.4 -echo "****** RSpec plugin generator" -script/plugin install git://github.com/pat-maddox/rspec-plugin-generator.git -echo "****** Jrails " -script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails -echo "****** Acts As State Machine " -script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk -echo "****** RESTful Auth " -script/plugin install git://github.com/technoweenie/restful-authentication.git -echo "****** YAML Mail Config " -script/plugin install svn://rubyforge.org/var/svn/slantwise/yaml_mail_config/trunk yaml_mail_config -cp vendor/plugins/yaml_mail_config/templates/email.example.yml config/email.yml - - -echo "************************************************" -echo " Adding Gem dependencies " -echo "************************************************" -sed -i.newrails.orig -e 's/^end//' config/environment.rb -echo "config.gem 'will_paginate'" >> config/environment.rb -echo "config.gem 'haml'" >> config/environment.rb -echo 'config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"' >> config/environment.rb -echo 'config.gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu"' >> config/environment.rb -echo "config.gem 'pager-exception_notification', :source => 'http://gems.github.com', :lib => 'exception_notification'" >> config/environment.rb -echo "end" >> config/environment.rb - - -echo "************************************************" -echo " Setting up SASS " -echo "************************************************" -mkdir -p "public/stylesheets/sass" -echo "@import colors.sass" >> public/stylesheets/sass/application.sass -echo "!white = #f1f1f1" >> public/stylesheets/sass/colors.sass -echo "!black = #000" >> public/stylesheets/sass/colors.sass -echo "!blue = #cfe0f0" >> public/stylesheets/sass/colors.sass - -echo "************************************************" -echo " Setting up some files you'll want" -echo "************************************************" -touch "app/views/layouts/application.haml" -rm public/index.html - -echo "************************************************" -echo " Unpacking Gems " -echo "************************************************" -rake gems:unpack - -echo "************************************************" -echo " Git " -echo "************************************************" -echo "config/database.yml" >> .gitignore -git init -git add . -git commit . -m"Initial Revision" - -mate . -mate config/email.yml -mate app/views/layouts/application.haml -mate public/stylesheets/sass/colors.sass -mate public/stylesheets/sass/application.sass -mate config/database.yml - +#!/bin/sh +echo "new_rails is deprecated." +echo "Try this instead:" +echo "# rails $1 -m fasteragile.rb" \ No newline at end of file
peteonrails/my-rails-utils
586027e55f265e588cc29b0000b6abf8700c4b4b
Adding rSpec plugin generator
diff --git a/new_rails b/new_rails index b57faa1..d075c4a 100755 --- a/new_rails +++ b/new_rails @@ -1,78 +1,80 @@ #!/bin/bash echo "************************************************" echo " Creating New Rails Project: $1 " echo "************************************************" rails $1 echo "************************************************" echo " Adding HAML" echo "************************************************" haml --rails $1 cd $1 echo "************************************************" echo " Installing Plugins " echo "************************************************" echo "****** RSpec " script/plugin install git://github.com/dchelimsky/rspec.git -r 1.1.4 echo "****** RSpec Rails " script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 1.1.4 +echo "****** RSpec plugin generator" +script/plugin install git://github.com/pat-maddox/rspec-plugin-generator.git echo "****** Jrails " script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails echo "****** Acts As State Machine " script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk echo "****** RESTful Auth " script/plugin install git://github.com/technoweenie/restful-authentication.git echo "****** YAML Mail Config " script/plugin install svn://rubyforge.org/var/svn/slantwise/yaml_mail_config/trunk yaml_mail_config cp vendor/plugins/yaml_mail_config/templates/email.example.yml config/email.yml echo "************************************************" echo " Adding Gem dependencies " echo "************************************************" sed -i.newrails.orig -e 's/^end//' config/environment.rb echo "config.gem 'will_paginate'" >> config/environment.rb echo "config.gem 'haml'" >> config/environment.rb echo 'config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"' >> config/environment.rb echo 'config.gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu"' >> config/environment.rb echo "config.gem 'pager-exception_notification', :source => 'http://gems.github.com', :lib => 'exception_notification'" >> config/environment.rb echo "end" >> config/environment.rb echo "************************************************" echo " Setting up SASS " echo "************************************************" mkdir -p "public/stylesheets/sass" echo "@import colors.sass" >> public/stylesheets/sass/application.sass echo "!white = #f1f1f1" >> public/stylesheets/sass/colors.sass echo "!black = #000" >> public/stylesheets/sass/colors.sass echo "!blue = #cfe0f0" >> public/stylesheets/sass/colors.sass echo "************************************************" echo " Setting up some files you'll want" echo "************************************************" touch "app/views/layouts/application.haml" rm public/index.html echo "************************************************" echo " Unpacking Gems " echo "************************************************" rake gems:unpack echo "************************************************" echo " Git " echo "************************************************" echo "config/database.yml" >> .gitignore git init git add . git commit . -m"Initial Revision" mate . mate config/email.yml mate app/views/layouts/application.haml mate public/stylesheets/sass/colors.sass mate public/stylesheets/sass/application.sass mate config/database.yml
peteonrails/my-rails-utils
a98c369b013a7ee40265906cd05daa9be3075ae7
Updating with some more files and commands I like.
diff --git a/new_rails b/new_rails index eb555ba..b57faa1 100755 --- a/new_rails +++ b/new_rails @@ -1,68 +1,78 @@ #!/bin/bash echo "************************************************" echo " Creating New Rails Project: $1 " echo "************************************************" rails $1 echo "************************************************" echo " Adding HAML" echo "************************************************" haml --rails $1 cd $1 echo "************************************************" echo " Installing Plugins " echo "************************************************" echo "****** RSpec " script/plugin install git://github.com/dchelimsky/rspec.git -r 1.1.4 echo "****** RSpec Rails " script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 1.1.4 echo "****** Jrails " script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails echo "****** Acts As State Machine " script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk echo "****** RESTful Auth " script/plugin install git://github.com/technoweenie/restful-authentication.git echo "****** YAML Mail Config " script/plugin install svn://rubyforge.org/var/svn/slantwise/yaml_mail_config/trunk yaml_mail_config cp vendor/plugins/yaml_mail_config/templates/email.example.yml config/email.yml echo "************************************************" echo " Adding Gem dependencies " echo "************************************************" sed -i.newrails.orig -e 's/^end//' config/environment.rb echo "config.gem 'will_paginate'" >> config/environment.rb echo "config.gem 'haml'" >> config/environment.rb echo 'config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"' >> config/environment.rb echo 'config.gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu"' >> config/environment.rb echo "config.gem 'pager-exception_notification', :source => 'http://gems.github.com', :lib => 'exception_notification'" >> config/environment.rb echo "end" >> config/environment.rb echo "************************************************" echo " Setting up SASS " echo "************************************************" mkdir -p "public/stylesheets/sass" echo "@import colors.sass" >> public/stylesheets/sass/application.sass echo "!white = #f1f1f1" >> public/stylesheets/sass/colors.sass echo "!black = #000" >> public/stylesheets/sass/colors.sass echo "!blue = #cfe0f0" >> public/stylesheets/sass/colors.sass +echo "************************************************" +echo " Setting up some files you'll want" +echo "************************************************" +touch "app/views/layouts/application.haml" +rm public/index.html + echo "************************************************" echo " Unpacking Gems " echo "************************************************" rake gems:unpack echo "************************************************" echo " Git " echo "************************************************" echo "config/database.yml" >> .gitignore git init git add . git commit . -m"Initial Revision" mate . +mate config/email.yml +mate app/views/layouts/application.haml +mate public/stylesheets/sass/colors.sass +mate public/stylesheets/sass/application.sass mate config/database.yml
peteonrails/my-rails-utils
576fd290fd03d5074f9ddc92457bdf8d9b1dc721
Initial Revision
diff --git a/new_rails b/new_rails new file mode 100755 index 0000000..eb555ba --- /dev/null +++ b/new_rails @@ -0,0 +1,68 @@ +#!/bin/bash + +echo "************************************************" +echo " Creating New Rails Project: $1 " +echo "************************************************" +rails $1 + +echo "************************************************" +echo " Adding HAML" +echo "************************************************" +haml --rails $1 +cd $1 + +echo "************************************************" +echo " Installing Plugins " +echo "************************************************" +echo "****** RSpec " +script/plugin install git://github.com/dchelimsky/rspec.git -r 1.1.4 +echo "****** RSpec Rails " +script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 1.1.4 +echo "****** Jrails " +script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails +echo "****** Acts As State Machine " +script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk +echo "****** RESTful Auth " +script/plugin install git://github.com/technoweenie/restful-authentication.git +echo "****** YAML Mail Config " +script/plugin install svn://rubyforge.org/var/svn/slantwise/yaml_mail_config/trunk yaml_mail_config +cp vendor/plugins/yaml_mail_config/templates/email.example.yml config/email.yml + + +echo "************************************************" +echo " Adding Gem dependencies " +echo "************************************************" +sed -i.newrails.orig -e 's/^end//' config/environment.rb +echo "config.gem 'will_paginate'" >> config/environment.rb +echo "config.gem 'haml'" >> config/environment.rb +echo 'config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"' >> config/environment.rb +echo 'config.gem "peteonrails-vote_fu", :source => "http://gems.github.com", :lib => "vote_fu"' >> config/environment.rb +echo "config.gem 'pager-exception_notification', :source => 'http://gems.github.com', :lib => 'exception_notification'" >> config/environment.rb +echo "end" >> config/environment.rb + + +echo "************************************************" +echo " Setting up SASS " +echo "************************************************" +mkdir -p "public/stylesheets/sass" +echo "@import colors.sass" >> public/stylesheets/sass/application.sass +echo "!white = #f1f1f1" >> public/stylesheets/sass/colors.sass +echo "!black = #000" >> public/stylesheets/sass/colors.sass +echo "!blue = #cfe0f0" >> public/stylesheets/sass/colors.sass + +echo "************************************************" +echo " Unpacking Gems " +echo "************************************************" +rake gems:unpack + +echo "************************************************" +echo " Git " +echo "************************************************" +echo "config/database.yml" >> .gitignore +git init +git add . +git commit . -m"Initial Revision" + +mate . +mate config/database.yml +
adiel/availabletopair
7b13923e0d6ad2a1086f30ccfc9710a76f9e8bde
Tags page restricted to future availabilities
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 2e64004..ab5c69a 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,25 +1,27 @@ class TagsController < ApplicationController public # GET /tags def index #Tag cloud? end # GET /tags/sometag # GET /tags/sometag.xml # GET /tags/sometag.js def show @tag = params[:id] - @availabilities = Availability.find(:all, :order => :start_time, :include => :tags, :conditions => ['tags.tag = :tag',{:tag => @tag}]) + @availabilities = Availability.find(:all, :order => :start_time, :include => :tags, + :conditions => ['tags.tag = :tag and end_time > :end_time', + {:tag => @tag,:end_time => Time.now.utc}]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availabilities.to_xml(Availability.render_args)} format.js { render :json => @availabilities.to_json(Availability.render_args)} format.atom end end end
adiel/availabletopair
298c17b4ea50cb32f279067bb203318cad02e59b
Make tags links
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 153f419..2e64004 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,24 +1,25 @@ class TagsController < ApplicationController public # GET /tags def index #Tag cloud? end # GET /tags/sometag # GET /tags/sometag.xml # GET /tags/sometag.js def show @tag = params[:id] @availabilities = Availability.find(:all, :order => :start_time, :include => :tags, :conditions => ['tags.tag = :tag',{:tag => @tag}]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availabilities.to_xml(Availability.render_args)} format.js { render :json => @availabilities.to_json(Availability.render_args)} + format.atom end end end diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 83750df..f630d7b 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,116 +1,126 @@ module AvailabilitiesHelper def link_to_http(text) http?(text) ? link_to(h(text)) : h(text) end def link_to_email_or_http(text) email?(text) ? mail_to(h(text)) : link_to_http(text) end def contact_link(availability) link_to_email_or_http( availability.contact) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability,pad_hours = false) format = pad_hours ? "%02dh %02dm" : "%dh %02dm" format % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) - "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)} GMT" + "#{display_date_time(availability.start_time)}-#{display_time(availability.end_time)} GMT" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end def pairs_updated(availability) availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at end def pair_status(pair) if (!pair.accepted && !pair.suggested) return :open elsif (pair.accepted && pair.suggested) return :paired else :suggested end end def build_suggested_status(pair) if (pair.accepted) user = current_user_accepted(pair) ? "You" : pair.availability.user.username else user = current_user_suggested(pair) ? "You" : pair.user.username end "#{user} suggested pairing" end def display_pair_status(pair) status = pair_status(pair) case(status) when :open "Open" when :paired "Paired" when :suggested build_suggested_status(pair) end end def button_to_suggest_accept(pair) if (pair.accepted) action = "cancel" text = pair.suggested ? "Cancel pairing" : "Cancel" else action = "suggest" text = pair.suggested ? "Accept" : "Suggest pairing" end button_to(text, {:controller => 'pairs', :action => action, :id => pair.id}, :method => :post) end def display_tags(availability) - availability.tags.length == 0 ? 'none' : availability.tags.sort_by{|t|t.tag}.join(', ') + if availability.tags.length == 0 + 'none' + else + tag_links = [] + tags = availability.tags.sort_by{|t|t.tag} + tags.each do|t| + tag_links << link_to(h(t.tag),"#{http_root}/tags/#{CGI::escape(t.tag)}") + end + tag_links.join(', ') + end + end private def current_user_accepted(pair) return (!current_user.nil? && pair.availability.user_id == current_user.id) end def current_user_suggested(pair) return (!current_user.nil? && pair.user_id == current_user.id) end end diff --git a/app/views/availabilities/_atom.erb b/app/views/availabilities/_atom.erb new file mode 100644 index 0000000..6e07a94 --- /dev/null +++ b/app/views/availabilities/_atom.erb @@ -0,0 +1,29 @@ + <author> + <name>Available To Pair</name> + <email>noreply@availabletopair.com</email> + </author> +<% unless @availabilities.length == 0 %> + <updated><%= pairs_updated(@availabilities[0]).xmlschema %></updated> +<%end%> + <% @availabilities.each do |availability| %> + <entry> + <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(pairs_updated(availability))%>)</title> + <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> + <published><%= pairs_updated(availability).xmlschema %></published> + <updated><%= pairs_updated(availability).xmlschema %></updated> + <id>http://availabletopair.com/<%=h availability.id %>/<%=h pairs_updated(availability).xmlschema %></id> + <content type="html"> + <![CDATA[ + <% if availability.pairs.length == 0 %> + No developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username%> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. + <% else %> + The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: + <ul> + <% availability.pairs.each do |pair| %> + <li><strong><%=h display_duration(pair,true) %></strong> from <strong><%=h display_when_time(pair) %></strong> - <strong><%= h pair.user.username %></strong> on <strong><%=h display_project(pair) %></strong> - Status: <strong><%= display_pair_status(pair) %></strong> - Tags: <strong><%= pair.tags %></strong> (updated: <%= display_date_time(pair.updated_at)%>)</li> + <% end %> + </ul> + <% end %> + ]]> + </content> + </entry><% end %> diff --git a/app/views/availabilities/_list.html.erb b/app/views/availabilities/_list.html.erb index 87c0414..2216705 100644 --- a/app/views/availabilities/_list.html.erb +++ b/app/views/availabilities/_list.html.erb @@ -1,13 +1,13 @@ <% @availabilities.each do |availability| %> <tr> <td><%= link_to(h(availability.user.username), "/" + h(availability.user.username)) %></td> <td><%= project_link(availability) %></td> - <td><%=h display_tags(availability) %></td> + <td><%= display_tags(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= display_date_time(availability.updated_at) %></td> <td><%= mine?(availability) ? link_to('Edit', edit_availability_path(availability)) : "" %></td> <td><%= mine?(availability) ? button_to('Delete', availability, :confirm => 'Are you sure?', :method => :delete) : "" %></td> </tr> <% end %> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 207eef9..6e15b97 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,46 +1,46 @@ <p> - <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) - Tags: <strong><%=h display_tags(@availability) %></strong> + <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%= display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) - Tags: <strong><%= display_tags(@availability) %></strong> <% if mine?(@availability) %> | <%= link_to 'Edit', edit_availability_path(@availability) %> <% end %> </p> <h2>Pairs available:</h2> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>Shared tags</th> <th>When</th> <th>Dev time</th> <th>Updated</th> <th>Contact</th> <th colspan="2">Status</th> </tr> <% @availability.pairs.each do |pair| %> <tr class="<%= pair_status(pair) %>"> <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> <td><%= project_link(pair) %></td> <td><%= pair.tags %></td> - <td><%=h display_when(pair) %></td> + <td><%= display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= display_date_time(pair.updated_at) %></td> <td><%= contact_link(pair.user) %></td> <td><%= display_pair_status(pair) %></td> <td><%= mine?(@availability) ? button_to_suggest_accept(pair) : "" %></td> </tr> <% end %> <% if @availability.pairs.length == 0 %> <tr> - <td colspan="8"> + <td colspan="9"> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. </td> </tr> <% end %> </table> <p>Subscribe to updates of <%=h @availability.user.username %>'s available pairs (<a href="/<%=h @availability.user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/tags/show.atom.erb b/app/views/tags/show.atom.erb new file mode 100644 index 0000000..45e045d --- /dev/null +++ b/app/views/tags/show.atom.erb @@ -0,0 +1,7 @@ +<feed xmlns="http://www.w3.org/2005/Atom" > + <title>Available To Pair - <%= h @tag%></title> + <id><%= http_root %>/<%= h @tag%></id> + <link href="<%= http_root %>/<%= CGI::escape(@tag)%>.atom" rel="self" /> + <link href="<%= http_root %>/<%= CGI::escape(@tag)%>" /> +<%= render :partial => 'availabilities/atom' %> +</feed> diff --git a/app/views/tags/show.html.erb b/app/views/tags/show.html.erb index 66d303c..36ab837 100644 --- a/app/views/tags/show.html.erb +++ b/app/views/tags/show.html.erb @@ -1,23 +1,23 @@ <% content_for :head_links do %> - <link href="<%=http_root%>/tags/<%=h @tag%>.atom" title="Available to Pair - Atom" type="application/atom+xml" rel="alternate"/> + <link href="<%=http_root%>/tags/<%=CGI::escape(@tag)%>.atom" title="Available to Pair - Atom" type="application/atom+xml" rel="alternate"/> <% end %> <h1>Availabilities for tag: <%=h @tag %></h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>Tags</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> <%= render :partial => '/availabilities/list' %> </table> -<p>Subscribe to available pairs for <%=h @tag %>(<a href="/tags/<%=@tag%>.atom">atom</a>)</p> +<p>Subscribe to available pairs for <%=h @tag %> (<a href="/tags/<%= CGI::escape(@tag)%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb index c515abe..e8b3531 100644 --- a/app/views/users/index.atom.erb +++ b/app/views/users/index.atom.erb @@ -1,35 +1,7 @@ <feed xmlns="http://www.w3.org/2005/Atom" > <title><%=h @user.username %> is Available To Pair</title> <id><%= http_root %>/<%= h @user.username%></id> - <link href="<%= http_root %>/<%= h @user.username%>.atom" rel="self" /> - <link href="<%= http_root %>/<%= h @user.username%>" /> - <author> - <name>Available To Pair</name> - <email>noreply@availabletopair.com</email> - </author> -<% unless @availabilities.length == 0 %> - <updated><%= pairs_updated(@availabilities[0]).xmlschema %></updated> -<%end%> - <% @availabilities.each do |availability| %> - <entry> - <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(pairs_updated(availability))%>)</title> - <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> - <published><%= pairs_updated(availability).xmlschema %></published> - <updated><%= pairs_updated(availability).xmlschema %></updated> - <id>http://availabletopair.com/<%=h availability.id %>/<%=h pairs_updated(availability).xmlschema %></id> - <content type="html"> - <![CDATA[ - <% if availability.pairs.length == 0 %> - No developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username%> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. - <% else %> - The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: - <ul> - <% availability.pairs.each do |pair| %> - <li><strong><%=h display_duration(pair,true) %></strong> from <strong><%=h display_when_time(pair) %></strong> - <strong><%= h pair.user.username %></strong> on <strong><%=h display_project(pair) %></strong> - Status: <strong><%= display_pair_status(pair) %></strong> - Tags: <strong><%= pair.tags %></strong> (updated: <%= display_date_time(pair.updated_at)%>)</li> - <% end %> - </ul> - <% end %> - ]]> - </content> - </entry><% end %> + <link href="<%= http_root %>/<%= CGI::escape(@user.username)%>.atom" rel="self" /> + <link href="<%= http_root %>/<%= CGI::escape(@user.username)%>" /> +<%= render :partial => 'availabilities/atom' %> </feed> diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index ce14720..42801a8 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,177 +1,177 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT. | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59-00:00 GMT. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00 GMT. | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59-00:00 GMT. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | seinfeld,nbc | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | seinfeld,nbc | | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | seinfeld,nbc | And "LarryDavid" has suggested pairing with "LarryCharles" where possible When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - Status: LarryDavid suggested pairing - Tags: nbc, seinfeld \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Status: Open - Tags: nbc, seinfeld \(updated: [^\)]*\)| + | Pairs available for Fri Dec 13, 2019 21:59-00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59-00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - Status: LarryDavid suggested pairing - Tags: nbc, seinfeld \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Status: Open - Tags: nbc, seinfeld \(updated: [^\)]*\)| Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id Scenario: Multiple availabilities are ordered by latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I reduce the end time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I extend the end time of the availability at position 1 of the feed by 1 min And I reduce the start time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | Scenario: Multiple availabilities have feed updated date as latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 13, 2019 23:00 | http://github.com/LarryDavid | | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 01:00 | http://github.com/LarryDavid | When I visit "/JeffGarlin.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | And the feed should show as updated at the published time of the entry at position 1 When I visit "/LarryCharles.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59-00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59-00:00 GMT | Then the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index 8da2795..7dcd21c 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,57 +1,57 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | + | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00-23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | - | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | - | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | + | Bender | futurama | Fri Nov 01, 2019 22:00-05:00 | 7h 00m | No | http://github.com/Bender | + | LarryDavid | curb | Fri Dec 13, 2019 21:59-00:00 | 2h 01m | No | http://github.com/LarryDavid | + | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00-23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | - | ProfFarnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | - | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | - | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | + | LarryDavid | Curb | Fri Dec 13, 2019 21:00-05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | + | ProfFarnsworth | anything | Fri Dec 13, 2019 21:15-01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30-02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | + | Bender | Futurama | Fri Dec 13, 2019 22:00-04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | | PhilipJFry | futurama | And the following availabilities in the system with an end time 1 minute in the future: | developer | project | | Bender | the thick of it | When I wait 2 seconds And I log out And I am on the list availabilities page Then I should see "Bender" But I should not see "PhilipJFry" diff --git a/features/List_tag_availabilities.feature b/features/List_tag_availabilities.feature index 6343ee3..902495d 100644 --- a/features/List_tag_availabilities.feature +++ b/features/List_tag_availabilities.feature @@ -1,17 +1,17 @@ Feature: List tag availabilities In order that I can see who want to pair on similar things to me As an open source developer I want to see all the availabilities with a specific tag listed Scenario: Only the specified user's availabilities are listed on the users' availabilities page last updated first Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | ruby,on,rails | | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | ruby | | LarryDavid | curb | December 13, 2019 23:00 | December 13, 2019 23:50 | http://github.com/LarryDavid | on,rails | And I visit "/tags/ruby" Then I should see "Availabilities for tag: ruby" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | tags | - | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | ruby | - | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | on, rails, ruby | + | LarryDavid | curb | Fri Dec 13, 2019 21:00-21:30 | 0h 30m | No | http://github.com/LarryDavid | ruby | + | LarryDavid | curb | Fri Dec 13, 2019 22:00-00:00 | 2h 00m | No | http://github.com/LarryDavid | on, rails, ruby | diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index 30408dd..23acb81 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,61 +1,61 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page last updated first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | - | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Fri Dec 13, 2019 21:00-21:30 | 0h 30m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Fri Dec 13, 2019 22:00-00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed Given a user "MarkKerrigan" When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 21:30 - 02:30" + And I follow "Fri Dec 13, 2019 21:30-02:30" And I follow "Bender" Then My path should be "/Bender" And I should see "All Bender's availability" Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | | PhilipJFry | futurama | When I wait 2 seconds When I visit "/PhilipJFry" Then I should not see "futurama" Scenario: Availabilities with end time just in future should show Given no availabilities in the system And the following availabilities in the system with an end time 1 minute in the future: | developer | project | | Bender | the thick of it | When I visit "/Bender" But I should see "the thick of it" \ No newline at end of file diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index 430c0f4..ee23520 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,136 +1,136 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system When I log out And I am on the homepage And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I fill in "Cucumber" for "Project" And I fill in "available,to,pair" for "Tags" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m) - Tags: available, pair, to" + Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00-12:30 GMT (2h 30m) - Tags: available, pair, to" Scenario: User cannot add a new availability with end date in the past Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select a time 5 mins in the past as the "Start time" date and time And I select a time 1 min in the past as the "End time" date and time And I press "Publish availability" And I should see "End time is in the past" Scenario: User cannot add a new availability with end date the same as the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 10:00" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability with end date before the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 09:59" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability longer than 12hrs Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 22:01" as the "End time" date and time And I press "Publish availability" And I should see "12hrs is the maximum for one availability (you have 12h 01m)" When I select "December 25, 2014 22:00" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:00 - 22:00 GMT (12h 00m)" + Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:00-22:00 GMT (12h 00m)" Scenario: User cannot add a new availability that overlaps at the start of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 08:00" as the "Start time" date and time And I select "December 25, 2014 10:01" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User cannot add a new availability that overlaps at the end of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:59" as the "Start time" date and time And I select "December 25, 2014 11:30" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User can add a new availability that has contiguous availabilities on either side Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:05 | December 25, 2014 10:15 | http://github.com/jeffosmith | | jeffosmith | | December 25, 2014 10:30 | December 25, 2014 11:45 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:15" as the "Start time" date and time And I select "December 25, 2014 10:30" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:15 - 10:30 GMT (0h 15m)" + Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:15-10:30 GMT (0h 15m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." Scenario: An availability can be deleted by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I press "Delete" And I should see the following availabilites listed in order: | developer | project | start time | end time | contact | Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" When I visit the edit page for the only availability in the system Then I should be on the homepage And I should not see "Availability was successfully updated." #TODO: post a save request with id nobbled Scenario: An availability cannot be deleted by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Delete" When I make a request to delete the only availability in the system And I should see the following availabilites listed in order: | who | what | when | dev time | pairs | contact | - | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | + | PhilipJFry | original proj | Wed Jan 01, 2020 22:00-23:00 | 1h 00m | No | http://github.com/philip_j_fry | diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index 50050bc..b975431 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,91 +1,91 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00-04:30" + Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00\-04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | + | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00-02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00-04:30" + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00\-04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00-02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00-04:30" + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00\-04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00-04:30" + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00\-04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | ProfFarnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | - | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | + | ProfFarnsworth | Futurama | Fri Dec 13, 2019 22:00-01:30 | 3h 30m | http://github.com/prof_farnsworth | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00-02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 22:00 - 04:30" + And I follow "Fri Dec 13, 2019 22:00-04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" Scenario: Pairs are ordered by most matching tags Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | Bender | | December 13, 2019 18:00 | December 14, 2019 00:00 | http://github.com/bender | rails,rspec,cucumber,css,javascript,jquery,html | | LarryDavid | | December 13, 2019 20:00 | December 14, 2019 00:00 | http://github.com/larry_david | sinatra,rails,rspec,ramaze | | MalcolmTucker | | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/malcolm_tucker | css,html,javascript,jquery | | PhilipJFry | | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/philip_j_fry | css,html,javascript,flash | | ProfFarnsworth | | December 13, 2019 23:00 | December 14, 2019 00:00 | http://github.com/prof_farnsworth | cucumber,zuchini,aubergine | When I am on the list availabilities page - And I follow "Fri Dec 13, 2019 18:00 - 00:00" + And I follow "Fri Dec 13, 2019 18:00-00:00" Then I should see the following matching pairs - | developer | project | when | dev time | contact | tags | - | MalcolmTucker | | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | http://github.com/malcolm_tucker | css, html, javascript, jquery | - | PhilipJFry | | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | http://github.com/philip_j_fry | css, html, javascript | - | LarryDavid | | Fri Dec 13, 2019 20:00 - 00:00 | 4h 00m | http://github.com/larry_david | rails, rspec | - | ProfFarnsworth | | Fri Dec 13, 2019 23:00 - 00:00 | 1h 00m | http://github.com/prof_farnsworth | cucumber | + | developer | project | when | dev time | contact | tags | + | MalcolmTucker | | Fri Dec 13, 2019 21:00-00:00 GMT | 3h 00m | http://github.com/malcolm_tucker | css, html, javascript, jquery | + | PhilipJFry | | Fri Dec 13, 2019 22:00-00:00 GMT | 2h 00m | http://github.com/philip_j_fry | css, html, javascript | + | LarryDavid | | Fri Dec 13, 2019 20:00-00:00 GMT | 4h 00m | http://github.com/larry_david | rails, rspec | + | ProfFarnsworth | | Fri Dec 13, 2019 23:00-00:00 GMT | 1h 00m | http://github.com/prof_farnsworth | cucumber | diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index ab92400..fd33dc1 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,181 +1,181 @@ class ApplicationController < ActionController::Base def current_user_session $webrat_user_session end end def ensure_user(username,contact = 'cucumber') user = User.find(:all, :conditions => ["username = :username", {:username => username}])[0] if user.nil? user = User.new(:username => username, :password => 'cucumber', :password_confirmation => 'cucumber', :contact => contact, :email => "#{username}@example.com", :openid_identifier => username) end user.contact = contact user.save! user end Given /^a user "([^\"]*)"$/ do |username| ensure_user(username) end When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end When /check the published date of the feed entry at position (\d*)$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should_not eql("") @published_dates ||= {} @published_dates[entry_position] = Time.parse(published_text) end When /^I log in as "([^\"]*)"$/ do |username| When "I am on the homepage" ensure_user(username) $webrat_user_session = UserSession.new(:username => username, :password => 'cucumber') $webrat_user_session.save When "I am on the homepage" end When /^I log out$/ do $webrat_user_session = nil end Then /^My path should be "([^\"]*)"$/ do |path| URI.parse(current_url).path.should == path end Then /^I (?:should )?see the following feed entries:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) end end Then /^I should see the following feed entries with content:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) content = entry.xpath("xmlns:content").text content_html = Nokogiri::HTML(content) content_html.text.should =~ /#{table.rows[index][1]}/ end end Then /^The only entry's content should link to availability page from time period$/ do doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') only_availability = Availability.find(:all)[0] - expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")} GMT" + expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")}-#{only_availability.end_time.strftime("%H:%M")} GMT" content = entries[0].xpath("xmlns:content").text content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) end Then /^the feed should have the following properties:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) end end Then /^the feed should have the following links:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") link.length.should eql(1) link.xpath("@rel").text.should eql(row[1]) end end Then /^the feed should have the following text nodes:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath(row[0]).text.should eql(row[1]) end end When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| id = AtomHelper.entry_id(response.body,entry_position) sleep 1 # to make sure the new updated_at is different Availability.find(id).touch end Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| published = Time.parse(AtomHelper.published_text(response.body,entry_position)) @published_dates[entry_position].should < published Time.now.should >= published end Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should eql(Time.parse(published_text).xmlschema) end Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| doc = Nokogiri::XML(response.body) published = AtomHelper.published_text(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:updated").text.should eql(published) end Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) end Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) end Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| doc = Nokogiri::XML(response.body) id = AtomHelper.entry_id(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) end Then /^I reduce the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I reduce the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end \ No newline at end of file
adiel/availabletopair
d3abd9ae32a4994309de010969407ac25e60caf1
Add whitespace between tag lists
diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 60e6dc8..83750df 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,116 +1,116 @@ module AvailabilitiesHelper def link_to_http(text) http?(text) ? link_to(h(text)) : h(text) end def link_to_email_or_http(text) email?(text) ? mail_to(h(text)) : link_to_http(text) end def contact_link(availability) link_to_email_or_http( availability.contact) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability,pad_hours = false) format = pad_hours ? "%02dh %02dm" : "%dh %02dm" format % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)} GMT" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end def pairs_updated(availability) availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at end def pair_status(pair) if (!pair.accepted && !pair.suggested) return :open elsif (pair.accepted && pair.suggested) return :paired else :suggested end end def build_suggested_status(pair) if (pair.accepted) user = current_user_accepted(pair) ? "You" : pair.availability.user.username else user = current_user_suggested(pair) ? "You" : pair.user.username end "#{user} suggested pairing" end def display_pair_status(pair) status = pair_status(pair) case(status) when :open "Open" when :paired "Paired" when :suggested build_suggested_status(pair) end end def button_to_suggest_accept(pair) if (pair.accepted) action = "cancel" text = pair.suggested ? "Cancel pairing" : "Cancel" else action = "suggest" text = pair.suggested ? "Accept" : "Suggest pairing" end button_to(text, {:controller => 'pairs', :action => action, :id => pair.id}, :method => :post) end def display_tags(availability) - availability.tags.length == 0 ? 'none' : availability.tags.sort_by{|t|t.tag}.join(',') + availability.tags.length == 0 ? 'none' : availability.tags.sort_by{|t|t.tag}.join(', ') end private def current_user_accepted(pair) return (!current_user.nil? && pair.availability.user_id == current_user.id) end def current_user_suggested(pair) return (!current_user.nil? && pair.user_id == current_user.id) end end diff --git a/app/models/pair_builder.rb b/app/models/pair_builder.rb index b452af4..b05cdf7 100644 --- a/app/models/pair_builder.rb +++ b/app/models/pair_builder.rb @@ -1,42 +1,42 @@ class PairBuilder private def latest_start_time (master_availability, pair_availability) pair_availability.start_time > master_availability.start_time ? pair_availability.start_time : master_availability.start_time end def earliest_end_time (master_availability, pair_availability) pair_availability.end_time < master_availability.end_time ? pair_availability.end_time : master_availability.end_time end def matching_tags_csv(master_availability, pair_availability) matching = [] master_availability.tags.each do |master_tag| if pair_availability.tags.any? {|pair_tag| master_tag.tag == pair_tag.tag} matching.push master_tag.clone end end - matching.sort_by{|t|t.tag}.join(',') + matching.sort_by{|t|t.tag}.join(', ') end public def create(master_availability,pair_availability) pair = Pair.new update(pair,master_availability,pair_availability) end def update(pair,master_availability,pair_availability) pair.availability_id = master_availability.id pair.available_pair_id = pair_availability.id pair.user_id = pair_availability.user_id pair.project = master_availability.project || pair_availability.project pair.start_time = latest_start_time(master_availability, pair_availability) pair.end_time = earliest_end_time(master_availability, pair_availability) pair.tags = matching_tags_csv(master_availability, pair_availability) pair.save pair end end diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index dd84178..ce14720 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,177 +1,177 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00 GMT. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | seinfeld,nbc | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | seinfeld,nbc | | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | seinfeld,nbc | And "LarryDavid" has suggested pairing with "LarryCharles" where possible When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - Status: LarryDavid suggested pairing - Tags: nbc,seinfeld \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Status: Open - Tags: nbc,seinfeld \(updated: [^\)]*\)| + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - Status: LarryDavid suggested pairing - Tags: nbc, seinfeld \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Status: Open - Tags: nbc, seinfeld \(updated: [^\)]*\)| Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id Scenario: Multiple availabilities are ordered by latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I reduce the end time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I extend the end time of the availability at position 1 of the feed by 1 min And I reduce the start time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 13, 2019 23:00 | http://github.com/LarryDavid | | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 01:00 | http://github.com/LarryDavid | When I visit "/JeffGarlin.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | And the feed should show as updated at the published time of the entry at position 1 When I visit "/LarryCharles.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Then the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/List_tag_availabilities.feature b/features/List_tag_availabilities.feature index a225a5b..6343ee3 100644 --- a/features/List_tag_availabilities.feature +++ b/features/List_tag_availabilities.feature @@ -1,17 +1,17 @@ Feature: List tag availabilities In order that I can see who want to pair on similar things to me As an open source developer I want to see all the availabilities with a specific tag listed Scenario: Only the specified user's availabilities are listed on the users' availabilities page last updated first Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | ruby,on,rails | | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | ruby | | LarryDavid | curb | December 13, 2019 23:00 | December 13, 2019 23:50 | http://github.com/LarryDavid | on,rails | And I visit "/tags/ruby" Then I should see "Availabilities for tag: ruby" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | tags | | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | ruby | - | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | on,rails,ruby | + | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | on, rails, ruby | diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index f961d7a..430c0f4 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,136 +1,136 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system When I log out And I am on the homepage And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I fill in "Cucumber" for "Project" And I fill in "available,to,pair" for "Tags" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m) - Tags: available,pair,to" + Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m) - Tags: available, pair, to" Scenario: User cannot add a new availability with end date in the past Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select a time 5 mins in the past as the "Start time" date and time And I select a time 1 min in the past as the "End time" date and time And I press "Publish availability" And I should see "End time is in the past" Scenario: User cannot add a new availability with end date the same as the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 10:00" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability with end date before the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 09:59" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability longer than 12hrs Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 22:01" as the "End time" date and time And I press "Publish availability" And I should see "12hrs is the maximum for one availability (you have 12h 01m)" When I select "December 25, 2014 22:00" as the "End time" date and time And I press "Publish availability" Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:00 - 22:00 GMT (12h 00m)" Scenario: User cannot add a new availability that overlaps at the start of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 08:00" as the "Start time" date and time And I select "December 25, 2014 10:01" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User cannot add a new availability that overlaps at the end of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:59" as the "Start time" date and time And I select "December 25, 2014 11:30" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User can add a new availability that has contiguous availabilities on either side Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:05 | December 25, 2014 10:15 | http://github.com/jeffosmith | | jeffosmith | | December 25, 2014 10:30 | December 25, 2014 11:45 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:15" as the "Start time" date and time And I select "December 25, 2014 10:30" as the "End time" date and time And I press "Publish availability" Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:15 - 10:30 GMT (0h 15m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." Scenario: An availability can be deleted by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I press "Delete" And I should see the following availabilites listed in order: | developer | project | start time | end time | contact | Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" When I visit the edit page for the only availability in the system Then I should be on the homepage And I should not see "Availability was successfully updated." #TODO: post a save request with id nobbled Scenario: An availability cannot be deleted by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Delete" When I make a request to delete the only availability in the system And I should see the following availabilites listed in order: | who | what | when | dev time | pairs | contact | | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index 61e24de..50050bc 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,91 +1,91 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | ProfFarnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" Scenario: Pairs are ordered by most matching tags Given only the following availabilities in the system | developer | project | start time | end time | contact | tags | | Bender | | December 13, 2019 18:00 | December 14, 2019 00:00 | http://github.com/bender | rails,rspec,cucumber,css,javascript,jquery,html | | LarryDavid | | December 13, 2019 20:00 | December 14, 2019 00:00 | http://github.com/larry_david | sinatra,rails,rspec,ramaze | | MalcolmTucker | | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/malcolm_tucker | css,html,javascript,jquery | | PhilipJFry | | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/philip_j_fry | css,html,javascript,flash | | ProfFarnsworth | | December 13, 2019 23:00 | December 14, 2019 00:00 | http://github.com/prof_farnsworth | cucumber,zuchini,aubergine | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 18:00 - 00:00" Then I should see the following matching pairs | developer | project | when | dev time | contact | tags | - | MalcolmTucker | | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | http://github.com/malcolm_tucker | css,html,javascript,jquery | - | PhilipJFry | | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | http://github.com/philip_j_fry | css,html,javascript | - | LarryDavid | | Fri Dec 13, 2019 20:00 - 00:00 | 4h 00m | http://github.com/larry_david | rails,rspec | + | MalcolmTucker | | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | http://github.com/malcolm_tucker | css, html, javascript, jquery | + | PhilipJFry | | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | http://github.com/philip_j_fry | css, html, javascript | + | LarryDavid | | Fri Dec 13, 2019 20:00 - 00:00 | 4h 00m | http://github.com/larry_david | rails, rspec | | ProfFarnsworth | | Fri Dec 13, 2019 23:00 - 00:00 | 1h 00m | http://github.com/prof_farnsworth | cucumber | diff --git a/spec/models/pair_builder_spec.rb b/spec/models/pair_builder_spec.rb index 23f85bd..23a0ad3 100644 --- a/spec/models/pair_builder_spec.rb +++ b/spec/models/pair_builder_spec.rb @@ -1,154 +1,154 @@ require 'spec_helper' describe PairBuilder do master_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) pair_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) describe "when creating a pair" do it "should set availability_id as master id and available_to_pair id as pair id" do master_availability.id = 543 pair_availability.id = 654 pair = PairBuilder.new.create(master_availability,pair_availability) pair.availability_id.should eql(master_availability.id) pair.available_pair_id.should eql(pair_availability.id) end it "should set developer as pair developer" do master_availability.user_id = 54321 pair_availability.user_id = 98765 pair = PairBuilder.new.create(master_availability,pair_availability) pair.user_id.should eql pair_availability.user_id end describe "and the start time of the pair is later than that of the master" do before do master_availability.start_time = Time.parse("2012-06-01 15:25") pair_availability.start_time = Time.parse("2012-06-01 15:26") end it "should use the pair's start time" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.start_time.should be(pair_availability.start_time) end end describe "and the start time of the pair is earlier than that of the master" do before do master_availability.start_time = Time.parse("2012-06-01 15:26") pair_availability.start_time = Time.parse("2012-06-01 15:25") end it "should use the master's start time" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.start_time.should be(master_availability.start_time) end end describe "and the end time of the pair is later than that of the master" do before do master_availability.end_time = Time.parse("2012-06-01 15:25") pair_availability.end_time = Time.parse("2012-06-01 15:26") end it "should use the masters's end time" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.end_time.should be(master_availability.end_time) end end describe "and the end time of the pair is earlier than that of the master" do before do master_availability.end_time = Time.parse("2012-06-01 15:26") pair_availability.end_time = Time.parse("2012-06-01 15:25") end it "should use the pair's end time" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.end_time.should be(pair_availability.end_time) end end describe "and a project is not specified on either" do before do master_availability.project = nil pair_availability.project = nil end it "should set the project nil" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql nil end end describe "and a project is specified on the master only" do before do master_availability.project = "someProj" pair_availability.project = nil end it "should use the master's project" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql(master_availability.project) end end describe "and a project is specified on the pair" do before do master_availability.project = nil pair_availability.project = "someProj" end it "should use the pair's project" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql(pair_availability.project) end end describe "and there are no matching tags" do before do master_availability.tags = [] pair_availability.tags = [] end it "should have empty tags" do pair = PairBuilder.new.create(master_availability,pair_availability) pair.tags.should eql("") end end describe "and only some tags match" do before do master_availability.tags = [Tag.new(:tag => "grub"),Tag.new(:tag => "cuthbert"),Tag.new(:tag => "dibble")] pair_availability.tags = [Tag.new(:tag => "dibble"),Tag.new(:tag => "cuthbert"),Tag.new(:tag => "dibble")] end it "should have the matching tags as csv in alphabetical order" do pair = PairBuilder.new.create(master_availability,pair_availability) - pair.tags.should eql("cuthbert,dibble") + pair.tags.should eql("cuthbert, dibble") end end end end
adiel/availabletopair
16512c975c6dc192a695544501585a822911bdf5
Page for each tag
diff --git a/features/List_tag_availabilities.feature b/features/List_tag_availabilities.feature new file mode 100644 index 0000000..a225a5b --- /dev/null +++ b/features/List_tag_availabilities.feature @@ -0,0 +1,17 @@ +Feature: List tag availabilities + In order that I can see who want to pair on similar things to me + As an open source developer + I want to see all the availabilities with a specific tag listed + + Scenario: Only the specified user's availabilities are listed on the users' availabilities page last updated first + Given only the following availabilities in the system + | developer | project | start time | end time | contact | tags | + | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | ruby,on,rails | + | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | ruby | + | LarryDavid | curb | December 13, 2019 23:00 | December 13, 2019 23:50 | http://github.com/LarryDavid | on,rails | + And I visit "/tags/ruby" + Then I should see "Availabilities for tag: ruby" + And I should see the following availabilites listed in order + | developer | project | when | dev time | pairs available | contact | tags | + | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | ruby | + | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | on,rails,ruby |
adiel/availabletopair
ea267286b383a233136627d1bace1f34a2977bf8
Tagging
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0250eae..6dfd790 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,54 +1,55 @@ # Filters added to this controller apply to all controllers in the application. +# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password filter_parameter_logging :password, :password_confirmation helper_method :current_user_session, :current_user private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user return @current_user if defined?(@current_user) return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.user end def require_user unless current_user store_location flash[:notice] = "You must be logged in to access this page" redirect_to new_user_session_url return false end true end def require_no_user if current_user store_location flash[:notice] = "You must be logged out to access this page" redirect_to account_url return false end true end def store_location session[:return_to] = request.request_uri end def redirect_back_or_default(default) redirect_to(session[:return_to] || default) session[:return_to] = nil end end diff --git a/app/controllers/availabilities_controller.rb b/app/controllers/availabilities_controller.rb index ed8bd08..3a853db 100644 --- a/app/controllers/availabilities_controller.rb +++ b/app/controllers/availabilities_controller.rb @@ -1,106 +1,103 @@ class AvailabilitiesController < ApplicationController + + public + # GET /availabilities # GET /availabilities.xml def index @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["end_time > :end_time", {:end_time => Time.now.utc}]) respond_to do |format| format.html # show.html.erb - format.xml { render :xml => @availabilities } + format.xml { render :xml => @availabilities.to_xml(Availability.render_args)} + format.js { render :json => @availabilities.to_json(Availability.render_args)} end end # GET /availabilities/1 # GET /availabilities/1.xml def show @availability = Availability.find(params[:id]) - @availability.pairs.sort! {|p1,p2| p1.updated_at <=> p2.updated_at}.reverse! + @availability.sort_pairs_by_matching_tag_count_and_updated_at_desc respond_to do |format| format.html # show.html.erb - format.xml { render :xml => @availability } + format.xml { render :xml => @availability.to_xml(Availability.render_args)} + format.js { render :json => @availability.to_json(Availability.render_args)} end end # GET /availabilities/new - # GET /availabilities/new.xml def new return unless require_user @availability = Availability.new - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @availability } - end end def check_user_edit if current_user.id != @availability.user_id redirect_to root_url return false end true end # GET /availabilities/1/edit def edit return unless require_user @availability = Availability.find(params[:id]) return unless check_user_edit end + #TODO: unit tests + def read_tags_from_params + tags = [] + params[:availability][:tags].split(',').each do |text| + existing_tag = Tag.find(:all, :conditions => {:tag => text})[0] + tags.push existing_tag || Tag.new(:tag => text.strip) + end + params[:availability][:tags] = tags + end + # POST /availabilities - # POST /availabilities.xml def create return unless require_user + read_tags_from_params @availability = Availability.new(params[:availability]) @availability.user_id = current_user.id - respond_to do |format| - if @availability.save - flash[:notice] = 'Availability was successfully created.' - format.html { redirect_to(@availability) } - format.xml { render :xml => @availability, :status => :created, :location => @availability } - else - format.html { render :action => "new" } - format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } - end + if @availability.save + flash[:notice] = 'Availability was successfully created.' + redirect_to(@availability) + else + render :action => "new" end end # PUT /availabilities/1 - # PUT /availabilities/1.xml def update return unless require_user @availability = Availability.find(params[:id]) return unless check_user_edit - respond_to do |format| - # todo, could you hack in a diff user id here? - if @availability.update_attributes(params[:availability]) - flash[:notice] = 'Availability was successfully updated.' - format.html { redirect_to(@availability) } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } - end + # todo, could you hack in a diff user id here? + read_tags_from_params + if @availability.update_attributes(params[:availability]) + flash[:notice] = 'Availability was successfully updated.' + redirect_to(@availability) + else + render :action => "edit" end end # DELETE /availabilities/1 - # - #DELETE /availabilities/1.xml def destroy return unless require_user @availability = Availability.find(params[:id]) return unless check_user_edit @availability.destroy - respond_to do |format| - format.html { redirect_to(availabilities_url) } - format.xml { head :ok } - end + redirect_to(availabilities_url) end + end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..153f419 --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,24 @@ +class TagsController < ApplicationController + + public + + # GET /tags + def index + #Tag cloud? + end + + # GET /tags/sometag + # GET /tags/sometag.xml + # GET /tags/sometag.js + def show + @tag = params[:id] + @availabilities = Availability.find(:all, :order => :start_time, :include => :tags, :conditions => ['tags.tag = :tag',{:tag => @tag}]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @availabilities.to_xml(Availability.render_args)} + format.js { render :json => @availabilities.to_json(Availability.render_args)} + end + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1e0028d..27bf7eb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,71 +1,73 @@ class UsersController < ApplicationController private + def sort_availabilities_and_pairs @availabilities.each do |availability| - availability.pairs.sort!{ |p1, p2| p1.updated_at <=> p2.updated_at}.reverse! + availability.sort_pairs_by_matching_tag_count_and_updated_at_desc end @availabilities.sort! do |a1, a2| a1_updated = a1.pairs.length == 0 ? a1.updated_at : a1.pairs[0].updated_at a2_updated = a2.pairs.length == 0 ? a2.updated_at : a2.pairs[0].updated_at a1_updated <=> a2_updated end.reverse! end public # GET /username # GET /username.atom def index @user = User.find(:all,:conditions => {:username => params[:id]})[0] if @user.nil? redirect_to root_url return end @availabilities = Availability.find(:all, - :order => "start_time", :conditions => ["user_id = :user_id and end_time > :end_time" , {:user_id => @user.id,:end_time => Time.now.utc}]) respond_to do |format| + sort_availabilities_and_pairs + render_args = Availability.render_args format.html # new.html.erb - format.atom do - sort_availabilities_and_pairs - end + format.xml {render :xml => @availabilities.to_xml(render_args)} + format.js {render :json => @availabilities.to_json(render_args)} + format.atom end end def new @user = User.new @user.openid_identifier = params[:openid_identifier] end def create @user = User.new(params[:user]) @user.save do |result| if result flash[:notice] = "Registration successful." redirect_to root_url else render :action => 'new' end end end def edit @user = current_user end def update @user = current_user username = current_user.username @user.attributes = params[:user] @user.username = username @user.save do |result| if result flash[:notice] = "Successfully updated profile." redirect_to root_url else render :action => 'edit' end end end end diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 98449e0..60e6dc8 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,96 +1,116 @@ module AvailabilitiesHelper def link_to_http(text) http?(text) ? link_to(h(text)) : h(text) end def link_to_email_or_http(text) email?(text) ? mail_to(h(text)) : link_to_http(text) end def contact_link(availability) link_to_email_or_http( availability.contact) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability,pad_hours = false) format = pad_hours ? "%02dh %02dm" : "%dh %02dm" format % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)} GMT" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end def pairs_updated(availability) availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at end def pair_status(pair) if (!pair.accepted && !pair.suggested) - return "Open" + return :open elsif (pair.accepted && pair.suggested) - return "Paired" + return :paired else - if (pair.accepted) - user = current_user_accepted(pair) ? "You" : pair.availability.user.username - else - user = current_user_suggested(pair) ? "You" : pair.user.username - end - return "#{user} suggested pairing" + :suggested + end + end + + def build_suggested_status(pair) + if (pair.accepted) + user = current_user_accepted(pair) ? "You" : pair.availability.user.username + else + user = current_user_suggested(pair) ? "You" : pair.user.username + end + "#{user} suggested pairing" + end + + def display_pair_status(pair) + status = pair_status(pair) + case(status) + when :open + "Open" + when :paired + "Paired" + when :suggested + build_suggested_status(pair) end end def button_to_suggest_accept(pair) if (pair.accepted) action = "cancel" text = pair.suggested ? "Cancel pairing" : "Cancel" else action = "suggest" text = pair.suggested ? "Accept" : "Suggest pairing" end button_to(text, {:controller => 'pairs', :action => action, :id => pair.id}, :method => :post) end + + def display_tags(availability) + availability.tags.length == 0 ? 'none' : availability.tags.sort_by{|t|t.tag}.join(',') + end private def current_user_accepted(pair) return (!current_user.nil? && pair.availability.user_id == current_user.id) end def current_user_suggested(pair) return (!current_user.nil? && pair.user_id == current_user.id) end end diff --git a/app/models/availabilities_tags_link.rb b/app/models/availabilities_tags_link.rb new file mode 100644 index 0000000..d028d47 --- /dev/null +++ b/app/models/availabilities_tags_link.rb @@ -0,0 +1,4 @@ +class AvailabilitiesTagsLink < ActiveRecord::Base + belongs_to :availability + belongs_to :tag +end diff --git a/app/models/availability.rb b/app/models/availability.rb index d404f99..f4c4688 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,71 +1,103 @@ class Availability < ActiveRecord::Base validates_presence_of :user_id,:start_time, :end_time belongs_to :user has_many :pairs + has_many :availabilities_tags_links, :dependent => :destroy + has_many :tags, :through => :availabilities_tags_links strip_attributes! MaxDurationHrs = 12 private def display_duration "%02dh %02dm" % [(duration_sec / 3600).floor, ((duration_sec % 3600) / 60).to_i] end - def existing_availabilities_for_user_dont_overlap? () + def existing_availabilities_for_user_dont_overlap? !user.availabilities.any? {|p| p != self && p.start_time < end_time && p.end_time > start_time} end - def validate_end_time_is_in_the_future () + def validate_end_time_is_in_the_future errors.add(:end_time, "is in the past") unless end_time > Time.now end - def validate_end_time_is_after_start_time() + def validate_end_time_is_after_start_time errors.add(:end_time, "must be after start time") unless end_time > start_time end def validate_for_overlapping_availabilities() unless existing_availabilities_for_user_dont_overlap? errors.add("You have already declared yourself available", "for some of this time") end end def validate_max_duration unless duration_sec <= MaxDurationHrs * 60 * 60 errors.add("#{MaxDurationHrs}hrs is the maximum for one availability","(you have #{display_duration})") end end def validate validate_end_time_is_in_the_future validate_end_time_is_after_start_time validate_for_overlapping_availabilities validate_max_duration end public def save(pair_synchronizer = PairSynchronizer.new) result = super() pair_synchronizer.synchronize_pairs(self) result end def destroy(pair_synchronizer = PairSynchronizer.new) result = super() pair_synchronizer.destroy_pairs(self) result end def duration_sec end_time - start_time end def has_accepted_pair? pairs.any? do |pair| pair.accepted && pair.suggested end end + def sort_pairs_by_matching_tag_count_and_updated_at_desc + self.pairs.sort! do |p1,p2| + tag_count_1 = p1.tags.split(',').length + tag_count_2 = p2.tags.split(',').length + if tag_count_1 != tag_count_2 + tag_count_1 <=> tag_count_2 + else + p1.updated_at <=> p2.updated_at + end + end.reverse! + end + + def self.render_args + {:include => {:tags => {:only => :tag}, + :user => { + :only => :username + }, + :pairs => { + :include => { + :user => { + :only => :username + }, + :tags => {:only => :tag} + } + } + } + } + end + + end diff --git a/app/models/pair_repository.rb b/app/models/pair_builder.rb similarity index 69% rename from app/models/pair_repository.rb rename to app/models/pair_builder.rb index d5b5bc4..b452af4 100644 --- a/app/models/pair_repository.rb +++ b/app/models/pair_builder.rb @@ -1,31 +1,42 @@ -class PairRepository +class PairBuilder private def latest_start_time (master_availability, pair_availability) pair_availability.start_time > master_availability.start_time ? pair_availability.start_time : master_availability.start_time end def earliest_end_time (master_availability, pair_availability) pair_availability.end_time < master_availability.end_time ? pair_availability.end_time : master_availability.end_time end + def matching_tags_csv(master_availability, pair_availability) + matching = [] + master_availability.tags.each do |master_tag| + if pair_availability.tags.any? {|pair_tag| master_tag.tag == pair_tag.tag} + matching.push master_tag.clone + end + end + matching.sort_by{|t|t.tag}.join(',') + end + public def create(master_availability,pair_availability) pair = Pair.new update(pair,master_availability,pair_availability) end def update(pair,master_availability,pair_availability) pair.availability_id = master_availability.id pair.available_pair_id = pair_availability.id pair.user_id = pair_availability.user_id pair.project = master_availability.project || pair_availability.project pair.start_time = latest_start_time(master_availability, pair_availability) pair.end_time = earliest_end_time(master_availability, pair_availability) + pair.tags = matching_tags_csv(master_availability, pair_availability) pair.save pair end end diff --git a/app/models/pair_synchronizer.rb b/app/models/pair_synchronizer.rb index 86129ec..eaa46cf 100644 --- a/app/models/pair_synchronizer.rb +++ b/app/models/pair_synchronizer.rb @@ -1,72 +1,72 @@ class PairSynchronizer def initialize(pair_matcher = nil, pair_repository = nil) @pair_matcher = pair_matcher || PairMatcher.new - @pair_repository = pair_repository || PairRepository.new + @pair_repository = pair_repository || PairBuilder.new end private def save_or_update (existing, master_availability, pair_availability) if existing.nil? @pair_repository.create(master_availability, pair_availability) else @pair_repository.update(existing, master_availability, pair_availability) end end def save_or_update_master(existing_pairs, availability, new_matching_availability) existing_master = existing_pairs.find do |pair| pair.available_pair_id == new_matching_availability.id end save_or_update(existing_master, availability, new_matching_availability) end def save_or_update_pair (existing_pairs, availability, new_matching_availability) existing_pair = existing_pairs.find do |pair| pair.availability_id == new_matching_availability.id end save_or_update(existing_pair, new_matching_availability, availability) end def find_existing_pairs(availability) conditions_clause = "availability_id = :availability_id or available_pair_id = :available_pair_id" conditions_params = {:availability_id => availability.id, :available_pair_id => availability.id} existing_pairs = Pair.find(:all, :conditions => [conditions_clause, conditions_params]) return existing_pairs end def save_or_update_existing_pairs(availability, existing_pairs, new_matching_availabilities) new_matching_availabilities.each do |new_matching_availability| save_or_update_master(existing_pairs, availability, new_matching_availability) save_or_update_pair(existing_pairs, availability, new_matching_availability) end end def destroy_obsolete_pairs(existing_pairs, new_matching_availabilities) existing_pairs.each do |existing| match = new_matching_availabilities.find {|a| a.id == existing.availability_id || a.id == existing.available_pair_id} existing.destroy if match.nil? end end public def destroy_pairs(availability) existing_pairs = find_existing_pairs(availability) destroy_obsolete_pairs(existing_pairs, []) end def synchronize_pairs(availability) existing_pairs = find_existing_pairs(availability) new_matching_availabilities = @pair_matcher.find_pairs(availability) save_or_update_existing_pairs(availability, existing_pairs, new_matching_availabilities) destroy_obsolete_pairs(existing_pairs, new_matching_availabilities) end end diff --git a/app/models/tag.rb b/app/models/tag.rb new file mode 100644 index 0000000..a3d35ee --- /dev/null +++ b/app/models/tag.rb @@ -0,0 +1,8 @@ +class Tag < ActiveRecord::Base + belongs_to :availability + + def to_s + self.tag + end + +end diff --git a/app/views/availabilities/_list.html.erb b/app/views/availabilities/_list.html.erb index ccac1d5..87c0414 100644 --- a/app/views/availabilities/_list.html.erb +++ b/app/views/availabilities/_list.html.erb @@ -1,12 +1,13 @@ <% @availabilities.each do |availability| %> <tr> <td><%= link_to(h(availability.user.username), "/" + h(availability.user.username)) %></td> <td><%= project_link(availability) %></td> + <td><%=h display_tags(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= display_date_time(availability.updated_at) %></td> <td><%= mine?(availability) ? link_to('Edit', edit_availability_path(availability)) : "" %></td> <td><%= mine?(availability) ? button_to('Delete', availability, :confirm => 'Are you sure?', :method => :delete) : "" %></td> </tr> <% end %> \ No newline at end of file diff --git a/app/views/availabilities/edit.html.erb b/app/views/availabilities/edit.html.erb index 160b7b5..fcd1fed 100644 --- a/app/views/availabilities/edit.html.erb +++ b/app/views/availabilities/edit.html.erb @@ -1,25 +1,29 @@ <h1>Editing availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> - <%= f.label :project, 'Project (optional)' %><br /> + <%= f.label :project, 'Project' %>(optional)<br /> <%= f.text_field :project %> </p> + <p> + <%= f.label :tags, 'Tags' %>(optional, comma seperated) - e.g. programming languages, spoken languages, interests, trends<br /> + <%= f.text_field(:tags, :value => @availability.tags.join(',')) %> + </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p class="submit"> <%= f.submit 'Update' %> </p> <% end %> <div class="nav"> <%= link_to 'Home', availabilities_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index e218f21..7c6d76d 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,18 +1,19 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> + <th>Tags</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> <%= render :partial => 'list' %> </table> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/new.html.erb b/app/views/availabilities/new.html.erb index 10a8f6b..3ac3a7f 100644 --- a/app/views/availabilities/new.html.erb +++ b/app/views/availabilities/new.html.erb @@ -1,24 +1,28 @@ <h1>New availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> - <%= f.label :project, 'Project (optional)' %><br /> + <%= f.label :project, 'Project' %>(optional) - e.g. project homepage on open source host<br /> <%= f.text_field :project %> </p> + <p> + <%= f.label :tags, 'Tags' %>(optional, comma seperated) - e.g. programming languages, spoken languages, interests, trends<br /> + <%= f.text_field(:tags, :value => @availability.tags.join(',')) %> + </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p class="submit"> <%= f.submit 'Publish availability' %> </p> <% end %> <div class="nav"> <%= link_to 'Home', availabilities_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 4c121ff..207eef9 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,44 +1,46 @@ <p> - <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) + <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) - Tags: <strong><%=h display_tags(@availability) %></strong> <% if mine?(@availability) %> | <%= link_to 'Edit', edit_availability_path(@availability) %> <% end %> </p> <h2>Pairs available:</h2> <table class="pairs"> <tr> <th>Who</th> <th>What</th> + <th>Shared tags</th> <th>When</th> <th>Dev time</th> <th>Updated</th> <th>Contact</th> <th colspan="2">Status</th> </tr> <% @availability.pairs.each do |pair| %> - <tr> + <tr class="<%= pair_status(pair) %>"> <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> <td><%= project_link(pair) %></td> + <td><%= pair.tags %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= display_date_time(pair.updated_at) %></td> <td><%= contact_link(pair.user) %></td> - <td><%= pair_status(pair) %></td> + <td><%= display_pair_status(pair) %></td> <td><%= mine?(@availability) ? button_to_suggest_accept(pair) : "" %></td> </tr> <% end %> <% if @availability.pairs.length == 0 %> <tr> <td colspan="8"> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. </td> </tr> <% end %> </table> <p>Subscribe to updates of <%=h @availability.user.username %>'s available pairs (<a href="/<%=h @availability.user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/tags/show.html.erb b/app/views/tags/show.html.erb new file mode 100644 index 0000000..66d303c --- /dev/null +++ b/app/views/tags/show.html.erb @@ -0,0 +1,23 @@ +<% content_for :head_links do %> + <link href="<%=http_root%>/tags/<%=h @tag%>.atom" title="Available to Pair - Atom" type="application/atom+xml" rel="alternate"/> +<% end %> + +<h1>Availabilities for tag: <%=h @tag %></h1> + +<table class="availabilities"> + <tr> + <th>Who</th> + <th>What</th> + <th>Tags</th> + <th>When</th> + <th>How long</th> + <th>Pairs available</th> + <th>Updated</th> + <th colspan="2">&nbsp;</th> + </tr> +<%= render :partial => '/availabilities/list' %> +</table> +<p>Subscribe to available pairs for <%=h @tag %>(<a href="/tags/<%=@tag%>.atom">atom</a>)</p> +<div class="nav"> + <%= link_to 'Make yourself available', new_availability_path %> +</div> \ No newline at end of file diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb index 8470d57..c515abe 100644 --- a/app/views/users/index.atom.erb +++ b/app/views/users/index.atom.erb @@ -1,35 +1,35 @@ <feed xmlns="http://www.w3.org/2005/Atom" > <title><%=h @user.username %> is Available To Pair</title> <id><%= http_root %>/<%= h @user.username%></id> <link href="<%= http_root %>/<%= h @user.username%>.atom" rel="self" /> <link href="<%= http_root %>/<%= h @user.username%>" /> <author> <name>Available To Pair</name> <email>noreply@availabletopair.com</email> </author> <% unless @availabilities.length == 0 %> <updated><%= pairs_updated(@availabilities[0]).xmlschema %></updated> <%end%> <% @availabilities.each do |availability| %> <entry> <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(pairs_updated(availability))%>)</title> <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> <published><%= pairs_updated(availability).xmlschema %></published> <updated><%= pairs_updated(availability).xmlschema %></updated> <id>http://availabletopair.com/<%=h availability.id %>/<%=h pairs_updated(availability).xmlschema %></id> <content type="html"> <![CDATA[ <% if availability.pairs.length == 0 %> No developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username%> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. <% else %> The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: <ul> <% availability.pairs.each do |pair| %> - <li><%=h display_duration(pair,true) %> from <%=h display_when_time(pair) %> - <strong><%= h pair.user.username %></strong> on <%=h display_project(pair) %> - <strong><%= pair_status(pair) %></strong> (updated: <%= display_date_time(pair.updated_at)%>)</li> + <li><strong><%=h display_duration(pair,true) %></strong> from <strong><%=h display_when_time(pair) %></strong> - <strong><%= h pair.user.username %></strong> on <strong><%=h display_project(pair) %></strong> - Status: <strong><%= display_pair_status(pair) %></strong> - Tags: <strong><%= pair.tags %></strong> (updated: <%= display_date_time(pair.updated_at)%>)</li> <% end %> </ul> <% end %> ]]> </content> </entry><% end %> </feed> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index cf9fceb..276199a 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,22 +1,23 @@ <% content_for :head_links do %> <link href="<%=http_root%>/<%=h @user.username%>.atom" title="Available to Pair - Atom" type="application/atom+xml" rel="alternate"/> <% end %> <h1>All <%= @user.username %>'s availability</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> + <th>Tags</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> <%= render :partial => '/availabilities/list' %> </table> <p>Subscribe to updates of <%=@user.username %>'s available pairs (<a href="/<%=@user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6d7f799..7d28841 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,12 @@ ActionController::Routing::Routes.draw do |map| map.root :controller => "availabilities" map.resources :availabilities map.resources :user_sessions map.resources :users + map.resources :tags map.login "login", :controller => "user_sessions", :action => "new" map.logout "logout", :controller => "user_sessions", :action => "destroy" map.connect ':id.:format', :controller => :users, :action => :index map.connect 'pairs/:id/:action', :controller => :pairs, :conditions => { :method => :post } end diff --git a/db/migrate/20091106231200_create_tags.rb b/db/migrate/20091106231200_create_tags.rb new file mode 100644 index 0000000..0262d4c --- /dev/null +++ b/db/migrate/20091106231200_create_tags.rb @@ -0,0 +1,21 @@ +class CreateTags < ActiveRecord::Migration + def self.up + create_table :tags do |t| + t.string :tag, :null => false, :unique => true + t.timestamps + end + + create_table :availabilities_tags_links do |t| + t.integer :availability_id, :null => false + t.integer :tag_id, :null => false + end + + add_column :pairs, :tags, :string + end + + def self.down + drop_table :tags + drop_table :availabilities_tags_links + remove_column :pairs, :tags + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e2c904..9a21d48 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,75 +1,87 @@ # This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20091102351300) do +ActiveRecord::Schema.define(:version => 20091106231200) do create_table "availabilities", :force => true do |t| t.datetime "start_time" t.datetime "end_time" t.datetime "created_at" t.datetime "updated_at" t.string "project" t.datetime "pairs_updated", :default => '2009-10-19 10:29:27' t.integer "user_id" end add_index "availabilities", ["start_time", "end_time"], :name => "availabilities_pair_search_index" + create_table "availabilities_tags_links", :force => true do |t| + t.integer "availability_id", :null => false + t.integer "tag_id", :null => false + end + create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" t.string "handle" t.string "assoc_type" t.binary "server_url" t.binary "secret" end create_table "open_id_authentication_nonces", :force => true do |t| t.integer "timestamp", :null => false t.string "server_url" t.string "salt", :null => false end create_table "pairs", :force => true do |t| t.integer "availability_id" t.integer "available_pair_id" t.datetime "created_at" t.datetime "updated_at" t.string "project" t.datetime "start_time" t.datetime "end_time" t.integer "user_id" t.boolean "accepted", :default => false, :null => false t.boolean "suggested", :default => false, :null => false + t.string "tags" end add_index "pairs", ["availability_id"], :name => "pairs_availability_id_index" + create_table "tags", :force => true do |t| + t.string "tag", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "crypted_password" t.string "password_salt" t.string "openid_identifier", :null => false t.string "persistence_token", :null => false t.string "single_access_token", :null => false t.string "perishable_token", :null => false t.integer "login_count", :default => 0, :null => false t.integer "failed_login_count", :default => 0, :null => false t.datetime "last_request_at" t.datetime "current_login_at" t.datetime "last_login_at" t.string "current_login_ip" t.string "last_login_ip" t.string "contact" end end diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 0790786..dd84178 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,177 +1,177 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00 GMT. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system - | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | - | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | - | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | + | developer | project | start time | end time | contact | tags | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | seinfeld,nbc | + | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | seinfeld,nbc | + | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | seinfeld,nbc | And "LarryDavid" has suggested pairing with "LarryCharles" where possible When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - LarryDavid suggested pairing \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Open \(updated: [^\)]*\)| + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - Status: LarryDavid suggested pairing - Tags: nbc,seinfeld \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Status: Open - Tags: nbc,seinfeld \(updated: [^\)]*\)| Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id Scenario: Multiple availabilities are ordered by latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I reduce the end time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I extend the end time of the availability at position 1 of the feed by 1 min And I reduce the start time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 13, 2019 23:00 | http://github.com/LarryDavid | | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 01:00 | http://github.com/LarryDavid | When I visit "/JeffGarlin.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | And the feed should show as updated at the published time of the entry at position 1 When I visit "/LarryCharles.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Then the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index eddb774..8da2795 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,56 +1,57 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | | ProfFarnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | | PhilipJFry | futurama | And the following availabilities in the system with an end time 1 minute in the future: | developer | project | | Bender | the thick of it | When I wait 2 seconds - When I am on the list availabilities page + And I log out + And I am on the list availabilities page Then I should see "Bender" But I should not see "PhilipJFry" diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index 8d8c018..30408dd 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,61 +1,61 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available - Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first + Scenario: Only the specified user's availabilities are listed on the users' availabilities page last updated first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed Given a user "MarkKerrigan" When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 21:30 - 02:30" And I follow "Bender" Then My path should be "/Bender" And I should see "All Bender's availability" Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | | PhilipJFry | futurama | When I wait 2 seconds When I visit "/PhilipJFry" Then I should not see "futurama" Scenario: Availabilities with end time just in future should show Given no availabilities in the system And the following availabilities in the system with an end time 1 minute in the future: | developer | project | | Bender | the thick of it | When I visit "/Bender" But I should see "the thick of it" \ No newline at end of file diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index 560bd69..f961d7a 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,135 +1,136 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system When I log out And I am on the homepage And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I fill in "Cucumber" for "Project" + And I fill in "available,to,pair" for "Tags" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m)" + Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m) - Tags: available,pair,to" Scenario: User cannot add a new availability with end date in the past Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select a time 5 mins in the past as the "Start time" date and time And I select a time 1 min in the past as the "End time" date and time And I press "Publish availability" And I should see "End time is in the past" Scenario: User cannot add a new availability with end date the same as the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 10:00" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability with end date before the start date Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 09:59" as the "End time" date and time And I press "Publish availability" And I should see "End time must be after start time" Scenario: User cannot add a new availability longer than 12hrs Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 22:01" as the "End time" date and time And I press "Publish availability" And I should see "12hrs is the maximum for one availability (you have 12h 01m)" When I select "December 25, 2014 22:00" as the "End time" date and time And I press "Publish availability" Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:00 - 22:00 GMT (12h 00m)" Scenario: User cannot add a new availability that overlaps at the start of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 08:00" as the "Start time" date and time And I select "December 25, 2014 10:01" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User cannot add a new availability that overlaps at the end of an existing availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:59" as the "Start time" date and time And I select "December 25, 2014 11:30" as the "End time" date and time And I press "Publish availability" And I should see "You have already declared yourself available for some of this time" Scenario: User can add a new availability that has contiguous availabilities on either side Given only the following availabilities in the system | developer | project | start time | end time | contact | | jeffosmith | | December 25, 2014 10:05 | December 25, 2014 10:15 | http://github.com/jeffosmith | | jeffosmith | | December 25, 2014 10:30 | December 25, 2014 11:45 | http://github.com/jeffosmith | When I log in as "jeffosmith" And I follow "Make yourself available" And I select "December 25, 2014 10:15" as the "Start time" date and time And I select "December 25, 2014 10:30" as the "End time" date and time And I press "Publish availability" Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:15 - 10:30 GMT (0h 15m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." Scenario: An availability can be deleted by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I press "Delete" And I should see the following availabilites listed in order: | developer | project | start time | end time | contact | Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" When I visit the edit page for the only availability in the system Then I should be on the homepage And I should not see "Availability was successfully updated." #TODO: post a save request with id nobbled Scenario: An availability cannot be deleted by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Delete" When I make a request to delete the only availability in the system And I should see the following availabilites listed in order: | who | what | when | dev time | pairs | contact | | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index 24de708..61e24de 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,72 +1,91 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | + | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | + | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | ProfFarnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" + Scenario: Pairs are ordered by most matching tags + Given only the following availabilities in the system + | developer | project | start time | end time | contact | tags | + | Bender | | December 13, 2019 18:00 | December 14, 2019 00:00 | http://github.com/bender | rails,rspec,cucumber,css,javascript,jquery,html | + | LarryDavid | | December 13, 2019 20:00 | December 14, 2019 00:00 | http://github.com/larry_david | sinatra,rails,rspec,ramaze | + | MalcolmTucker | | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/malcolm_tucker | css,html,javascript,jquery | + | PhilipJFry | | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/philip_j_fry | css,html,javascript,flash | + | ProfFarnsworth | | December 13, 2019 23:00 | December 14, 2019 00:00 | http://github.com/prof_farnsworth | cucumber,zuchini,aubergine | + When I am on the list availabilities page + And I follow "Fri Dec 13, 2019 18:00 - 00:00" + Then I should see the following matching pairs + | developer | project | when | dev time | contact | tags | + | MalcolmTucker | | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | http://github.com/malcolm_tucker | css,html,javascript,jquery | + | PhilipJFry | | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | http://github.com/philip_j_fry | css,html,javascript | + | LarryDavid | | Fri Dec 13, 2019 20:00 - 00:00 | 4h 00m | http://github.com/larry_david | rails,rspec | + | ProfFarnsworth | | Fri Dec 13, 2019 23:00 - 00:00 | 1h 00m | http://github.com/prof_farnsworth | cucumber | + + + diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index eafa9fc..eb3ade8 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,80 +1,91 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| user = ensure_user(row[0],row[4]) - Availability.create(:user_id => user.id, :project => row[1], :start_time => row[2], :end_time => row[3]) + tags = [] + unless row[5].nil? + row[5].split(',').each do |text| + existing_tag = Tag.find(:all,:conditions => {:tag => text})[0] + tags.push existing_tag || Tag.new(:tag => text.strip) + end + end + Availability.create(:user_id => user.id, :project => row[1], :start_time => row[2], :end_time => row[3], :tags => tags) + sleep 0.1 end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1], :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) - end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) seconds? in the future:$/ do |secs,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (secs.to_i)) end end When "I visit the edit page for the only availability in the system" do visit "/availabilities/#{Availability.find(:all)[0].id}/edit" end Then /^I should see the following availabilites listed in order:?$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" - Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" - Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" - Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" + Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(4)\"" + Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(5)\"" + Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(6)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" - Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" - Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" + Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(4)\"" + Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(5)\"" + Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(7)\"" + if !row[5].nil? + Then "I should see \"#{row[5]}\" within \"#{row_selector} td:nth-child(3)\"" + end end end When /^logged in as "([^\"]*)", I visit my only availability$/ do |username| When "I log in as \"#{username}\"" And "I visit \"/#{username}\"" And "I follow \"Yes\"" end When /^I select a time (\d*) mins? in the past as the "([^\"]*)" date and time$/ do |mins,datetime_label| When "I select \"#{Time.now - (mins.to_i * 60)}\" as the \"#{datetime_label}\" date and time" end When /^I wait (\d*) seconds$/ do |sec| sleep sec.to_i end diff --git a/features/step_definitions/pair_steps.rb b/features/step_definitions/pair_steps.rb index eaf8aa6..35932ee 100644 --- a/features/step_definitions/pair_steps.rb +++ b/features/step_definitions/pair_steps.rb @@ -1,55 +1,55 @@ Given /^"([^\"]*)" has suggested pairing with all available pairs$/ do |username| user = User.find(:all,:conditions => {:username => username})[0] user.availabilities.each do |availability| availability.pairs.each do |pair| pair.accepted = true pair.save reciprocal = pair.find_reciprocal_pair reciprocal.suggested = true reciprocal.save end end sleep 1 end Given /^"([^\"]*)" has suggested pairing with "([^\"]*)" where possible$/ do |username, pair_username| user = User.find(:all,:conditions => {:username => username})[0] pair_user = User.find(:all,:conditions => {:username => pair_username})[0] user.availabilities.each do |availability| availability.pairs.each do |pair| if (pair.user_id == pair_user.id) pair.accepted = true pair.save reciprocal = pair.find_reciprocal_pair reciprocal.suggested = true reciprocal.save end end end sleep 1 end Given /^"([^\"]*)" has suggested pairing with all available pairs except "([^\"]*)"$/ do |username, pair_username| user = User.find(:all,:conditions => {:username => username})[0] pair_user = User.find(:all,:conditions => {:username => pair_username})[0] user.availabilities.each do |availability| availability.pairs.each do |pair| if (pair.user_id != pair_user.id) pair.accepted = true pair.save reciprocal = pair.find_reciprocal_pair reciprocal.suggested = true reciprocal.save end end end sleep 1 end Then /^I should see the following pair statuses:$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" - Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(7)\"" + Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(8)\"" end end diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 827c51d..4b69e4a 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,140 +1,147 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; font-size:0.8em; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:0.9em; border-collapse: collapse; width:95%; } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.2em 1.0em 1em; } h1 { font-size:1.4em; margin:0.8em; } h2 { font-size:1.2em; margin:1.2em 0.8em 0.3em; } #header { font-size:2.5em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { font-size:1.3em; padding:0.2em; border:1px solid #999; margin:0.2em; } select { font-size:1.2em; } input { width:35em; } table input, .submit input { width:auto; } table input { font-size:1.1em; cursor:pointer; margin:-2px; padding:1px; } .username input, .email input{ width:15em; } -#availability_project { -width:22.4em; +#availability_project, #availability_tags { +width:35em; } #logo {float:left;} #how {float:right;} .clear{ clear:both; font-size:0; } #logo a { color:#000; text-decoration:none; } .nav{ margin:1.5em; } #tagline { font-style:italic; font-size:0.4em; margin-left:1em; float:left; } input#user_openid_identifier, input#user_session_openid_identifier { background: url(http://openid.net/images/login-bg.gif) no-repeat; background-color: #fff; background-position: 2px 50%; color: #000; padding-left: 20px; width:34.2em; } .fieldWithErrors { display:inline; margin:1em; } #user_nav { float:right; text-align:right; margin:.5em 0 0; font-size:0.4em; } form label { margin:0.2em; font-size:1.4em; } .errorExplanation { color:#cc0000; } .duration, .time, .project { font-weight:bold; } + +tr.paired, tr.paired td { + background-color:#66ff66; +} +tr.suggested, tr.suggested td { + background-color:#ffff66; +} diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index 5025b36..aea46f1 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' describe Availability do describe "when the start and end time are within the same day" do it "should calculate the duration as the difference between the end and start times in seconds" do start_time = Time.parse("2009-11-15 09:00") end_time = Time.parse("2009-11-15 17:35") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when the start and end time cross two days" do it "should calculate the duration as the difference between the end and start times" do start_time = Time.parse("2009-11-15 22:00") end_time = Time.parse("2009-11-15 00:15") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when saving" do it "should sync pairs" do - availability = Availability.new + availability = Availability.new(:user => User.new, :start_time => Time.now, :end_time => Time.now + 1000) pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:synchronize_pairs).with(availability) availability.save(pair_synchronizer) end end describe "when destroying" do it "should destroy pairs" do availability = Availability.new pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:destroy_pairs).with(availability) availability.destroy(pair_synchronizer) end end end diff --git a/spec/models/pair_repository_spec.rb b/spec/models/pair_builder_spec.rb similarity index 61% rename from spec/models/pair_repository_spec.rb rename to spec/models/pair_builder_spec.rb index 1eeec23..23f85bd 100644 --- a/spec/models/pair_repository_spec.rb +++ b/spec/models/pair_builder_spec.rb @@ -1,128 +1,154 @@ require 'spec_helper' -describe PairRepository do +describe PairBuilder do master_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) pair_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) describe "when creating a pair" do it "should set availability_id as master id and available_to_pair id as pair id" do master_availability.id = 543 pair_availability.id = 654 - pair = PairRepository.new.create(master_availability,pair_availability) + pair = PairBuilder.new.create(master_availability,pair_availability) pair.availability_id.should eql(master_availability.id) pair.available_pair_id.should eql(pair_availability.id) end it "should set developer as pair developer" do master_availability.user_id = 54321 pair_availability.user_id = 98765 - pair = PairRepository.new.create(master_availability,pair_availability) + pair = PairBuilder.new.create(master_availability,pair_availability) pair.user_id.should eql pair_availability.user_id end describe "and the start time of the pair is later than that of the master" do before do master_availability.start_time = Time.parse("2012-06-01 15:25") pair_availability.start_time = Time.parse("2012-06-01 15:26") end it "should use the pair's start time" do - pair = PairRepository.new.create(master_availability,pair_availability) - pair.start_time.should be (pair_availability.start_time) + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.start_time.should be(pair_availability.start_time) end end describe "and the start time of the pair is earlier than that of the master" do before do master_availability.start_time = Time.parse("2012-06-01 15:26") pair_availability.start_time = Time.parse("2012-06-01 15:25") end it "should use the master's start time" do - pair = PairRepository.new.create(master_availability,pair_availability) - pair.start_time.should be (master_availability.start_time) + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.start_time.should be(master_availability.start_time) end end describe "and the end time of the pair is later than that of the master" do before do master_availability.end_time = Time.parse("2012-06-01 15:25") pair_availability.end_time = Time.parse("2012-06-01 15:26") end it "should use the masters's end time" do - pair = PairRepository.new.create(master_availability,pair_availability) - pair.end_time.should be (master_availability.end_time) + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.end_time.should be(master_availability.end_time) end end describe "and the end time of the pair is earlier than that of the master" do before do master_availability.end_time = Time.parse("2012-06-01 15:26") pair_availability.end_time = Time.parse("2012-06-01 15:25") end it "should use the pair's end time" do - pair = PairRepository.new.create(master_availability,pair_availability) - pair.end_time.should be (pair_availability.end_time) + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.end_time.should be(pair_availability.end_time) end end describe "and a project is not specified on either" do before do master_availability.project = nil pair_availability.project = nil end it "should set the project nil" do - pair = PairRepository.new.create(master_availability,pair_availability) + pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql nil end end describe "and a project is specified on the master only" do before do master_availability.project = "someProj" pair_availability.project = nil end it "should use the master's project" do - pair = PairRepository.new.create(master_availability,pair_availability) + pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql(master_availability.project) end end describe "and a project is specified on the pair" do before do master_availability.project = nil pair_availability.project = "someProj" end it "should use the pair's project" do - pair = PairRepository.new.create(master_availability,pair_availability) + pair = PairBuilder.new.create(master_availability,pair_availability) pair.project.should eql(pair_availability.project) end end + + describe "and there are no matching tags" do + + before do + master_availability.tags = [] + pair_availability.tags = [] + end + + it "should have empty tags" do + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.tags.should eql("") + end + end + + describe "and only some tags match" do + + before do + master_availability.tags = [Tag.new(:tag => "grub"),Tag.new(:tag => "cuthbert"),Tag.new(:tag => "dibble")] + pair_availability.tags = [Tag.new(:tag => "dibble"),Tag.new(:tag => "cuthbert"),Tag.new(:tag => "dibble")] + end + + it "should have the matching tags as csv in alphabetical order" do + pair = PairBuilder.new.create(master_availability,pair_availability) + pair.tags.should eql("cuthbert,dibble") + end + end end end
adiel/availabletopair
370d04f28dab35e148af89f53d842737def65b23
Layout of no developers available message broken
diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index f9b6404..4c121ff 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,44 +1,44 @@ <p> <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) <% if mine?(@availability) %> | <%= link_to 'Edit', edit_availability_path(@availability) %> <% end %> </p> <h2>Pairs available:</h2> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Updated</th> <th>Contact</th> <th colspan="2">Status</th> </tr> <% @availability.pairs.each do |pair| %> <tr> <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= display_date_time(pair.updated_at) %></td> <td><%= contact_link(pair.user) %></td> <td><%= pair_status(pair) %></td> <td><%= mine?(@availability) ? button_to_suggest_accept(pair) : "" %></td> </tr> <% end %> <% if @availability.pairs.length == 0 %> <tr> - <td colspan="6"> + <td colspan="8"> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. </td> </tr> <% end %> </table> <p>Subscribe to updates of <%=h @availability.user.username %>'s available pairs (<a href="/<%=h @availability.user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div>
adiel/availabletopair
e58f190744d3901b8c7174444f5dad84675a0427
Validate start and end times
diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 66bbfc9..98449e0 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,95 +1,96 @@ module AvailabilitiesHelper def link_to_http(text) http?(text) ? link_to(h(text)) : h(text) end def link_to_email_or_http(text) email?(text) ? mail_to(h(text)) : link_to_http(text) end def contact_link(availability) link_to_email_or_http( availability.contact) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end - def display_duration(availability) - "%dh %02dm" % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] + def display_duration(availability,pad_hours = false) + format = pad_hours ? "%02dh %02dm" : "%dh %02dm" + format % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) - "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)}" + "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)} GMT" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end def pairs_updated(availability) availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at end def pair_status(pair) if (!pair.accepted && !pair.suggested) return "Open" elsif (pair.accepted && pair.suggested) return "Paired" else if (pair.accepted) user = current_user_accepted(pair) ? "You" : pair.availability.user.username else user = current_user_suggested(pair) ? "You" : pair.user.username end return "#{user} suggested pairing" end end def button_to_suggest_accept(pair) if (pair.accepted) action = "cancel" text = pair.suggested ? "Cancel pairing" : "Cancel" else action = "suggest" text = pair.suggested ? "Accept" : "Suggest pairing" end button_to(text, {:controller => 'pairs', :action => action, :id => pair.id}, :method => :post) end private def current_user_accepted(pair) return (!current_user.nil? && pair.availability.user_id == current_user.id) end def current_user_suggested(pair) return (!current_user.nil? && pair.user_id == current_user.id) end end diff --git a/app/models/availability.rb b/app/models/availability.rb index 5bee6a8..d404f99 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,27 +1,71 @@ class Availability < ActiveRecord::Base validates_presence_of :user_id,:start_time, :end_time belongs_to :user has_many :pairs strip_attributes! + MaxDurationHrs = 12 + + private + + def display_duration + "%02dh %02dm" % [(duration_sec / 3600).floor, ((duration_sec % 3600) / 60).to_i] + end + + def existing_availabilities_for_user_dont_overlap? () + !user.availabilities.any? {|p| p != self && p.start_time < end_time && p.end_time > start_time} + end + + def validate_end_time_is_in_the_future () + errors.add(:end_time, "is in the past") unless end_time > Time.now + end + + def validate_end_time_is_after_start_time() + errors.add(:end_time, "must be after start time") unless end_time > start_time + end + + def validate_for_overlapping_availabilities() + unless existing_availabilities_for_user_dont_overlap? + errors.add("You have already declared yourself available", "for some of this time") + end + end + + def validate_max_duration + unless duration_sec <= MaxDurationHrs * 60 * 60 + errors.add("#{MaxDurationHrs}hrs is the maximum for one availability","(you have #{display_duration})") + end + end + + def validate + validate_end_time_is_in_the_future + validate_end_time_is_after_start_time + validate_for_overlapping_availabilities + validate_max_duration + end + + + public + def save(pair_synchronizer = PairSynchronizer.new) - super() + result = super() pair_synchronizer.synchronize_pairs(self) + result end def destroy(pair_synchronizer = PairSynchronizer.new) - super() + result = super() pair_synchronizer.destroy_pairs(self) + result end def duration_sec end_time - start_time end def has_accepted_pair? pairs.any? do |pair| pair.accepted && pair.suggested end end end diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb index 2a61609..8470d57 100644 --- a/app/views/users/index.atom.erb +++ b/app/views/users/index.atom.erb @@ -1,35 +1,35 @@ <feed xmlns="http://www.w3.org/2005/Atom" > <title><%=h @user.username %> is Available To Pair</title> <id><%= http_root %>/<%= h @user.username%></id> <link href="<%= http_root %>/<%= h @user.username%>.atom" rel="self" /> <link href="<%= http_root %>/<%= h @user.username%>" /> <author> <name>Available To Pair</name> <email>noreply@availabletopair.com</email> </author> <% unless @availabilities.length == 0 %> <updated><%= pairs_updated(@availabilities[0]).xmlschema %></updated> <%end%> <% @availabilities.each do |availability| %> <entry> <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(pairs_updated(availability))%>)</title> <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> <published><%= pairs_updated(availability).xmlschema %></published> <updated><%= pairs_updated(availability).xmlschema %></updated> <id>http://availabletopair.com/<%=h availability.id %>/<%=h pairs_updated(availability).xmlschema %></id> <content type="html"> <![CDATA[ <% if availability.pairs.length == 0 %> No developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username%> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. <% else %> The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.user.username %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: <ul> <% availability.pairs.each do |pair| %> - <li><%=h display_duration(pair) %> from <%=h display_when_time(pair) %> - <%= h pair.user.username %> on <%=h display_project(pair) %> (updated: <%= display_date_time(pair.updated_at)%>)</li> + <li><%=h display_duration(pair,true) %> from <%=h display_when_time(pair) %> - <strong><%= h pair.user.username %></strong> on <%=h display_project(pair) %> - <strong><%= pair_status(pair) %></strong> (updated: <%= display_date_time(pair.updated_at)%>)</li> <% end %> </ul> <% end %> ]]> </content> </entry><% end %> </feed> diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 6988be2..0790786 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,176 +1,177 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email Given a user "LarryDavid" When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00. | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00. | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00 GMT. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | + And "LarryDavid" has suggested pairing with "LarryCharles" where possible When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00:(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on curb \(updated: [^\)]*\)(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb \(updated: [^\)]*\)| + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00 GMT:(\s*)00h 30m from 23:30 to 00:00 - LarryCharles on curb - LarryDavid suggested pairing \(updated: [^\)]*\)(\s*)01h 00m from 23:00 to 00:00 - JeffGarlin on curb - Open \(updated: [^\)]*\)| Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: - | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | title | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: - | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | title | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id Scenario: Multiple availabilities are ordered by latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I reduce the end time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I extend the end time of the availability at position 1 of the feed by 1 min And I reduce the start time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Scenario: Multiple availabilities have feed updated date as latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 13, 2019 23:00 | http://github.com/LarryDavid | - | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 23:00 | http://github.com/LarryDavid | + | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 01:00 | http://github.com/LarryDavid | When I visit "/JeffGarlin.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | And the feed should show as updated at the published time of the entry at position 1 When I visit "/LarryCharles.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 GMT | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 GMT | Then the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index b234f2b..eddb774 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,55 +1,56 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | | ProfFarnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system - And the following availabilities in the system with an end time 2 minutes in the past: + And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | - | PhilipJFry | futurama | - And the following availabilities in the system with an end time 2 minutes in the future: + | PhilipJFry | futurama | + And the following availabilities in the system with an end time 1 minute in the future: | developer | project | - | MalcolmTucker | the thick of it | + | Bender | the thick of it | + When I wait 2 seconds When I am on the list availabilities page - Then I should see "MalcolmTucker" + Then I should see "Bender" But I should not see "PhilipJFry" diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index a1fe882..8d8c018 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,56 +1,61 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | - | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:00 | December 13, 2019 21:30 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 21:30 | 0h 30m | No | http://github.com/LarryDavid | | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed Given a user "MarkKerrigan" When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 21:30 - 02:30" And I follow "Bender" Then My path should be "/Bender" And I should see "All Bender's availability" Scenario: Availabilities with end time in the past should not show Given no availabilities in the system - And the following availabilities in the system with an end time 2 minutes in the past: + And the following availabilities in the system with an end time 2 seconds in the future: | developer | project | | PhilipJFry | futurama | - And the following availabilities in the system with an end time 2 minutes in the future: - | developer | project | - | PhilipJFry | the thick of it | + When I wait 2 seconds When I visit "/PhilipJFry" - Then I should see "the thick of it" - But I should not see "futurama" \ No newline at end of file + Then I should not see "futurama" + + Scenario: Availabilities with end time just in future should show + Given no availabilities in the system + And the following availabilities in the system with an end time 1 minute in the future: + | developer | project | + | Bender | the thick of it | + When I visit "/Bender" + But I should see "the thick of it" \ No newline at end of file diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index 972e4b9..560bd69 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,62 +1,135 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system When I log out And I am on the homepage And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I fill in "Cucumber" for "Project" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time And I press "Publish availability" - Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 (2h 30m)" + Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 GMT (2h 30m)" + + Scenario: User cannot add a new availability with end date in the past + Given no availabilities in the system + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select a time 5 mins in the past as the "Start time" date and time + And I select a time 1 min in the past as the "End time" date and time + And I press "Publish availability" + And I should see "End time is in the past" + + Scenario: User cannot add a new availability with end date the same as the start date + Given no availabilities in the system + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 10:00" as the "Start time" date and time + And I select "December 25, 2014 10:00" as the "End time" date and time + And I press "Publish availability" + And I should see "End time must be after start time" + + Scenario: User cannot add a new availability with end date before the start date + Given no availabilities in the system + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 10:00" as the "Start time" date and time + And I select "December 25, 2014 09:59" as the "End time" date and time + And I press "Publish availability" + And I should see "End time must be after start time" + + Scenario: User cannot add a new availability longer than 12hrs + Given no availabilities in the system + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 10:00" as the "Start time" date and time + And I select "December 25, 2014 22:01" as the "End time" date and time + And I press "Publish availability" + And I should see "12hrs is the maximum for one availability (you have 12h 01m)" + When I select "December 25, 2014 22:00" as the "End time" date and time + And I press "Publish availability" + Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:00 - 22:00 GMT (12h 00m)" + + Scenario: User cannot add a new availability that overlaps at the start of an existing availability + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 08:00" as the "Start time" date and time + And I select "December 25, 2014 10:01" as the "End time" date and time + And I press "Publish availability" + And I should see "You have already declared yourself available for some of this time" + + Scenario: User cannot add a new availability that overlaps at the end of an existing availability + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | jeffosmith | | December 25, 2014 10:00 | December 25, 2014 11:00 | http://github.com/jeffosmith | + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 10:59" as the "Start time" date and time + And I select "December 25, 2014 11:30" as the "End time" date and time + And I press "Publish availability" + And I should see "You have already declared yourself available for some of this time" + + Scenario: User can add a new availability that has contiguous availabilities on either side + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | jeffosmith | | December 25, 2014 10:05 | December 25, 2014 10:15 | http://github.com/jeffosmith | + | jeffosmith | | December 25, 2014 10:30 | December 25, 2014 11:45 | http://github.com/jeffosmith | + When I log in as "jeffosmith" + And I follow "Make yourself available" + And I select "December 25, 2014 10:15" as the "Start time" date and time + And I select "December 25, 2014 10:30" as the "End time" date and time + And I press "Publish availability" + Then I should see "jeffosmith is available to pair on anything on Thu Dec 25, 2014 10:15 - 10:30 GMT (0h 15m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." Scenario: An availability can be deleted by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I press "Delete" And I should see the following availabilites listed in order: | developer | project | start time | end time | contact | Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" When I visit the edit page for the only availability in the system Then I should be on the homepage And I should not see "Availability was successfully updated." #TODO: post a save request with id nobbled Scenario: An availability cannot be deleted by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Delete" When I make a request to delete the only availability in the system And I should see the following availabilites listed in order: | who | what | when | dev time | pairs | contact | | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index b84e082..eafa9fc 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,65 +1,80 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| user = ensure_user(row[0],row[4]) Availability.create(:user_id => user.id, :project => row[1], :start_time => row[2], :end_time => row[3]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1], :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end +Given /^the following availabilities in the system with an end time (\d*) seconds? in the future:$/ do |secs,table| + table.rows.each do |row| + user = ensure_user(row[0],'asdf') + Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (secs.to_i)) + end +end + When "I visit the edit page for the only availability in the system" do visit "/availabilities/#{Availability.find(:all)[0].id}/edit" end Then /^I should see the following availabilites listed in order:?$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end When /^logged in as "([^\"]*)", I visit my only availability$/ do |username| When "I log in as \"#{username}\"" And "I visit \"/#{username}\"" And "I follow \"Yes\"" end + +When /^I select a time (\d*) mins? in the past as the "([^\"]*)" date and time$/ do |mins,datetime_label| + When "I select \"#{Time.now - (mins.to_i * 60)}\" as the \"#{datetime_label}\" date and time" +end + +When /^I wait (\d*) seconds$/ do |sec| + sleep sec.to_i +end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index d0c280e..ab92400 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,181 +1,181 @@ class ApplicationController < ActionController::Base def current_user_session $webrat_user_session end end def ensure_user(username,contact = 'cucumber') user = User.find(:all, :conditions => ["username = :username", {:username => username}])[0] if user.nil? user = User.new(:username => username, :password => 'cucumber', :password_confirmation => 'cucumber', :contact => contact, :email => "#{username}@example.com", :openid_identifier => username) end user.contact = contact user.save! user end Given /^a user "([^\"]*)"$/ do |username| ensure_user(username) end When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end When /check the published date of the feed entry at position (\d*)$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should_not eql("") @published_dates ||= {} @published_dates[entry_position] = Time.parse(published_text) end When /^I log in as "([^\"]*)"$/ do |username| When "I am on the homepage" ensure_user(username) $webrat_user_session = UserSession.new(:username => username, :password => 'cucumber') $webrat_user_session.save When "I am on the homepage" end When /^I log out$/ do $webrat_user_session = nil end Then /^My path should be "([^\"]*)"$/ do |path| URI.parse(current_url).path.should == path end Then /^I (?:should )?see the following feed entries:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) end end Then /^I should see the following feed entries with content:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) content = entry.xpath("xmlns:content").text content_html = Nokogiri::HTML(content) content_html.text.should =~ /#{table.rows[index][1]}/ end end Then /^The only entry's content should link to availability page from time period$/ do doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') only_availability = Availability.find(:all)[0] - expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")}" - + expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")} GMT" + content = entries[0].xpath("xmlns:content").text content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) end Then /^the feed should have the following properties:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) end end Then /^the feed should have the following links:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") link.length.should eql(1) link.xpath("@rel").text.should eql(row[1]) end end Then /^the feed should have the following text nodes:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath(row[0]).text.should eql(row[1]) end end When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| id = AtomHelper.entry_id(response.body,entry_position) sleep 1 # to make sure the new updated_at is different Availability.find(id).touch end Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| published = Time.parse(AtomHelper.published_text(response.body,entry_position)) @published_dates[entry_position].should < published Time.now.should >= published end Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should eql(Time.parse(published_text).xmlschema) end Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| doc = Nokogiri::XML(response.body) published = AtomHelper.published_text(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:updated").text.should eql(published) end Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) end Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) end Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| doc = Nokogiri::XML(response.body) id = AtomHelper.entry_id(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) end Then /^I reduce the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I reduce the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end \ No newline at end of file diff --git a/features/support/paths.rb b/features/support/paths.rb index dcaf67e..7f3b1b6 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -1,29 +1,31 @@ module NavigationHelpers # Maps a name to a path. Used by the # # When /^I go to (.+)$/ do |page_name| # # step definition in webrat_steps.rb # def path_to(page_name) case page_name when /the home\s?page/ '/' when /the list availabilities page/ '/availabilities' + when /the new availability page/ + '/availabilities/new' # Add more mappings here. # Here is a more fancy example: # # when /^(.*)'s profile page$/i # user_profile_path(User.find_by_login($1)) else raise "Can't find mapping from \"#{page_name}\" to a path.\n" + "Now, go and add a mapping in #{__FILE__}" end end end World(NavigationHelpers)
adiel/availabletopair
098a11c1e1b5efd2efe396163762bbb357d8f7a0
Rollback clearing other suggested pairs, actually want to allow more than one pair over an availability.
diff --git a/app/models/availability.rb b/app/models/availability.rb index 78c542b..5bee6a8 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,21 +1,27 @@ class Availability < ActiveRecord::Base validates_presence_of :user_id,:start_time, :end_time belongs_to :user has_many :pairs strip_attributes! def save(pair_synchronizer = PairSynchronizer.new) super() pair_synchronizer.synchronize_pairs(self) end def destroy(pair_synchronizer = PairSynchronizer.new) super() pair_synchronizer.destroy_pairs(self) end def duration_sec end_time - start_time end + def has_accepted_pair? + pairs.any? do |pair| + pair.accepted && pair.suggested + end + end + end diff --git a/app/models/pair.rb b/app/models/pair.rb index e6b5d49..aafd84f 100644 --- a/app/models/pair.rb +++ b/app/models/pair.rb @@ -1,13 +1,14 @@ class Pair < ActiveRecord::Base belongs_to :availability belongs_to :user def duration_sec end_time - start_time end def find_reciprocal_pair Pair.find(:all, :conditions => ["availability_id = :availability_id and available_pair_id = :available_pair_id", {:available_pair_id => self.availability_id, :availability_id => self.available_pair_id}])[0] end + end diff --git a/app/models/pair_connector.rb b/app/models/pair_connector.rb index 091efb4..e31721b 100644 --- a/app/models/pair_connector.rb +++ b/app/models/pair_connector.rb @@ -1,42 +1,21 @@ class PairConnector private - def other_suggestions_for_this_slot(pair,reciprocal_pair) - my_suggestions = Pair.find(:all, :conditions => {:availability_id => pair.available_pair_id}) - pairs_suggestions = Pair.find(:all, :conditions => {:availability_id => pair.availability_id}) - all_suggestions = my_suggestions + pairs_suggestions - other_suggestions = all_suggestions.find_all do |suggested_pair| - suggested_pair.id != pair.id && suggested_pair.id != reciprocal_pair.id - end - other_suggestions - end - - def clear_other_suggestions(pair,reciprocal_pair) - if (pair.accepted && pair.suggested) - other_suggestions_for_this_slot(pair,reciprocal_pair).each do |other_suggested_pair| - other_suggested_pair.accepted = false - other_suggested_pair.save - end - end - end - def update_pairing_status(pair,accepted) pair.accepted = accepted pair.save reciprocal_pair = pair.find_reciprocal_pair reciprocal_pair.suggested = accepted reciprocal_pair.save - - clear_other_suggestions(pair,reciprocal_pair) end public def accept_pairing(pair) update_pairing_status(pair,true) end def cancel_pairing(pair) update_pairing_status(pair,false) end end \ No newline at end of file diff --git a/features/Accept_pairings.feature b/features/Accept_pairings.feature index d53b1b2..52fff9c 100644 --- a/features/Accept_pairings.feature +++ b/features/Accept_pairings.feature @@ -1,91 +1,31 @@ Feature: Accept pairing In order to let a developer who has suggested pairing know I want to pair and to let others know I am taken As an open source developer to whom others have sugested pairing I want to be able to accept pairing with a suggested pair Scenario: User accepts suggested pairing Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When logged in as "Bender", I visit my only availability And I press "Suggest pairing" And logged in as "PhilipJFry", I visit my only availability Then I should see the following pair statuses: | developer | status | | Bender | Bender suggested pairing | When I press "Accept" Then I should see the following pair statuses: | developer | status | | Bender | Paired | When logged in as "Bender", I visit my only availability Then I should see the following pair statuses: | developer | status | | PhilipJFry | Paired | When I press "Cancel pairing" Then I should see the following pair statuses: | developer | status | | PhilipJFry | PhilipJFry suggested pairing | -#Post.update_all({:removed=>true}, {:id=>params[:posts]}) - Scenario: User accepts a suggested pairings and all other pairings suggested by the other user for the same avaialability are cleared - Given only the following availabilities in the system - | developer | project | start time | end time | contact | - | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | - | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | - And "PhilipJFry" has suggested pairing with all available pairs - When logged in as "PhilipJFry", I visit my only availability - Then I should see the following pair statuses: - | developer | status | - | DrZoidberg | You suggested pairing | - | Bender | You suggested pairing | - When logged in as "Bender", I visit my only availability - And I press "Accept" - When logged in as "PhilipJFry", I visit my only availability - Then I should see the following pair statuses: - | developer | status | - | DrZoidberg | Open | - | Bender | Paired | - - Scenario: User accepts a suggested pairings and all other pairings suggested same user for the same avaialability are cleared - Given only the following availabilities in the system - | developer | project | start time | end time | contact | - | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | - | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | - And "PhilipJFry" has suggested pairing with "Bender" where possible - And "Bender" has suggested pairing with all available pairs except "PhilipJFry" - When logged in as "Bender", I visit my only availability - Then I should see the following pair statuses: - | developer | status | - | DrZoidberg | You suggested pairing | - | PhilipJFry | PhilipJFry suggested pairing | - When I press "Accept" - Then I should see the following pair statuses: - | developer | status | - | DrZoidberg | Open | - | PhilipJFry | Paired | - - Scenario: User accepts one suggestion then accepts a different suggestion and the previous acceptance is cleared - Given only the following availabilities in the system - | developer | project | start time | end time | contact | - | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | - | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | - And "PhilipJFry" has suggested pairing with "Bender" where possible - When logged in as "Bender", I visit my only availability - And I press "Accept" - Then I should see the following pair statuses: - | developer | status | - | PhilipJFry | Paired | - | DrZoidberg | Open | - When "DrZoidberg" has suggested pairing with "Bender" where possible - And logged in as "Bender", I visit my only availability - And I press "Accept" - Then I should see the following pair statuses: - | developer | status | - | DrZoidberg | Paired | - | PhilipJFry | PhilipJFry suggested pairing | Scenario: User accepts a suggestion from looking at the pair's availability page diff --git a/spec/controllers/pairs_controller_spec.rb b/spec/controllers/pairs_controller_spec.rb index 362d725..c17c48d 100644 --- a/spec/controllers/pairs_controller_spec.rb +++ b/spec/controllers/pairs_controller_spec.rb @@ -1,219 +1,198 @@ require 'spec_helper' class FakePair - attr_accessor :id,:accepted, :suggested, :availability, :accept, :saved, :save_count, :reciprocal_pair, :availability_id, :available_pair_id + attr_accessor :id,:accepted, :suggested, :availability, :accept, :saved, :save_count, :reciprocal_pair def save @saved = self.clone @save_count ||= 0 @save_count += 1 end def find_reciprocal_pair @reciprocal_pair end end class FakeAvailability attr_accessor :id,:user_id end class FakeUserSession attr_accessor :user_id, :user end class FakeUser attr_accessor :id end describe PairsController do availability = nil pair = nil reciprocal_pair = nil user_session = nil user = nil other_user = nil before do availability = FakeAvailability.new - other_availability = FakeAvailability.new pair = FakePair.new reciprocal_pair = FakePair.new user_session = FakeUserSession.new user = FakeUser.new other_user = FakeUser.new pair.id = rand(100) reciprocal_pair.id = rand(100) user.id = rand(100) availability.id = rand(100) - other_availability.id = availability.id + 1 other_user.id = availability.id + 1 user_session.user = user user_session.user_id = user.id pair.availability = availability - pair.availability_id = availability.id - pair.available_pair_id = other_availability.id pair.reciprocal_pair = reciprocal_pair end describe "when suggesting pairing" do describe "and the user is not logged in" do before do UserSession.stub!(:find).and_return(nil) end it "should redirect to the login page" do post :suggest, :id => 1234 response.should redirect_to(new_user_session_url) end end describe "and the user is logged in" do before do UserSession.stub!(:find).and_return(user_session) Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) end describe "and the pair belongs to a different user" do before do availability.user_id = other_user.id end it "should redirect to the homepage" do post :suggest, :id => pair.id response.should redirect_to(root_url) end end describe "and the pair belongs to the current user" do before do availability.user_id = user.id end it "should redirect back to the show availability page" do post :suggest, :id => pair.id response.should redirect_to(availability_url(availability)) end describe "and the pairing has not been suggested" do before do pair.suggested = false pair.accepted = false end it "should save the pair as accepted" do post :suggest, :id => pair.id pair.saved.accepted.should be true pair.save_count.should be(1) end it "should save the reciprocal pair as suggested" do post :suggest, :id => pair.id reciprocal_pair.saved.suggested.should be true reciprocal_pair.save_count.should be(1) end end - describe "and the pairing has been suggested" do - - before do - pair.suggested = true - pair.accepted = true - end - - it "should clear all other suggested pairs for this availability" do - post :suggest, :id => pair.id - raise "TODO: missing test" - end - - it "should clear all other suggested pairs for the pair's availability" do - post :suggest, :id => pair.id - raise "TODO: missing test" - end - end end end end describe "when cancelling a suggested pairing" do describe "and the user is not logged in" do before do UserSession.stub!(:find).and_return(nil) end it "should redirect to the login page" do post :cancel, :id => 1234 response.should redirect_to(new_user_session_url) end end describe "and the user is logged in" do before do UserSession.stub!(:find).and_return(user_session) Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) end describe "and the pair belongs to a different user" do before do availability.user_id = other_user.id end it "should redirect to the homepage" do post :cancel, :id => pair.id response.should redirect_to(root_url) end end describe "and the pair belongs to the current user" do before do availability.user_id = user.id end it "should redirect back to the show availability page" do post :cancel, :id => pair.id response.should redirect_to(availability_url(availability)) end describe "and the pairing has been suggested" do before do pair.accepted = true reciprocal_pair.suggested = true end it "should save the pair as not accepted" do post :cancel, :id => pair.id pair.saved.accepted.should be false pair.save_count.should be(1) end it "should save the reciprocal pair as not suggested" do post :cancel, :id => pair.id reciprocal_pair.saved.suggested.should be false reciprocal_pair.save_count.should be(1) end end end end end end \ No newline at end of file
adiel/availabletopair
3b04f6a5171df7c07af803c232dd69ed17e1d7a9
Other suggestions are cleared when a suggestion to pair is accepted
diff --git a/app/controllers/pairs_controller.rb b/app/controllers/pairs_controller.rb index 05216cb..483daf2 100644 --- a/app/controllers/pairs_controller.rb +++ b/app/controllers/pairs_controller.rb @@ -1,58 +1,46 @@ class PairsController < ApplicationController + def initialize(pair_connector = PairConnector.new) + super() + @pair_connector = pair_connector + end + private def check_ownership(pair) if current_user.id != pair.availability.user_id redirect_to root_url return false end true end - - - def update_pairing_status(pair,accepted) - pair.accepted = accepted - pair.save - reciprocal_pair = pair.find_reciprocal_pair - reciprocal_pair.suggested = accepted - reciprocal_pair.save - end - - def cancel_pairing(pair) - update_pairing_status(pair, false) - end - - def accept_pairing(pair) - update_pairing_status(pair, true) - end public # POST /pairs/1/suggest def suggest return unless require_user pair = Pair.find(params[:id]) return unless check_ownership(pair) - accept_pairing(pair) + @pair_connector.accept_pairing(pair) redirect_to availability_url(pair.availability) end # POST /pairs/1/cancel def cancel return unless require_user pair = Pair.find(params[:id]) return unless check_ownership(pair) - cancel_pairing(pair) + @pair_connector.cancel_pairing(pair) redirect_to availability_url(pair.availability) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e78893b..1e0028d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,71 +1,71 @@ class UsersController < ApplicationController private def sort_availabilities_and_pairs @availabilities.each do |availability| availability.pairs.sort!{ |p1, p2| p1.updated_at <=> p2.updated_at}.reverse! end @availabilities.sort! do |a1, a2| a1_updated = a1.pairs.length == 0 ? a1.updated_at : a1.pairs[0].updated_at a2_updated = a2.pairs.length == 0 ? a2.updated_at : a2.pairs[0].updated_at a1_updated <=> a2_updated end.reverse! end public # GET /username # GET /username.atom def index - @user = User.find(:all,:conditions => ["username = :username",{:username => params[:id]}])[0] + @user = User.find(:all,:conditions => {:username => params[:id]})[0] if @user.nil? redirect_to root_url return end @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["user_id = :user_id and end_time > :end_time" , {:user_id => @user.id,:end_time => Time.now.utc}]) respond_to do |format| format.html # new.html.erb format.atom do sort_availabilities_and_pairs end end end def new @user = User.new @user.openid_identifier = params[:openid_identifier] end def create @user = User.new(params[:user]) @user.save do |result| if result flash[:notice] = "Registration successful." redirect_to root_url else render :action => 'new' end end end def edit @user = current_user end def update @user = current_user username = current_user.username @user.attributes = params[:user] @user.username = username @user.save do |result| if result flash[:notice] = "Successfully updated profile." redirect_to root_url else render :action => 'edit' end end end end diff --git a/app/models/pair.rb b/app/models/pair.rb index e04cc0d..e6b5d49 100644 --- a/app/models/pair.rb +++ b/app/models/pair.rb @@ -1,15 +1,13 @@ class Pair < ActiveRecord::Base belongs_to :availability belongs_to :user def duration_sec end_time - start_time end def find_reciprocal_pair Pair.find(:all, :conditions => ["availability_id = :availability_id and available_pair_id = :available_pair_id", {:available_pair_id => self.availability_id, :availability_id => self.available_pair_id}])[0] end - - end diff --git a/app/models/pair_connector.rb b/app/models/pair_connector.rb new file mode 100644 index 0000000..091efb4 --- /dev/null +++ b/app/models/pair_connector.rb @@ -0,0 +1,42 @@ +class PairConnector + private + + def other_suggestions_for_this_slot(pair,reciprocal_pair) + my_suggestions = Pair.find(:all, :conditions => {:availability_id => pair.available_pair_id}) + pairs_suggestions = Pair.find(:all, :conditions => {:availability_id => pair.availability_id}) + all_suggestions = my_suggestions + pairs_suggestions + other_suggestions = all_suggestions.find_all do |suggested_pair| + suggested_pair.id != pair.id && suggested_pair.id != reciprocal_pair.id + end + other_suggestions + end + + def clear_other_suggestions(pair,reciprocal_pair) + if (pair.accepted && pair.suggested) + other_suggestions_for_this_slot(pair,reciprocal_pair).each do |other_suggested_pair| + other_suggested_pair.accepted = false + other_suggested_pair.save + end + end + end + + def update_pairing_status(pair,accepted) + pair.accepted = accepted + pair.save + reciprocal_pair = pair.find_reciprocal_pair + reciprocal_pair.suggested = accepted + reciprocal_pair.save + + clear_other_suggestions(pair,reciprocal_pair) + end + + public + + def accept_pairing(pair) + update_pairing_status(pair,true) + end + + def cancel_pairing(pair) + update_pairing_status(pair,false) + end +end \ No newline at end of file diff --git a/features/Accept_pairings.feature b/features/Accept_pairings.feature index 011bc04..d53b1b2 100644 --- a/features/Accept_pairings.feature +++ b/features/Accept_pairings.feature @@ -1,31 +1,91 @@ Feature: Accept pairing In order to let a developer who has suggested pairing know I want to pair and to let others know I am taken As an open source developer to whom others have sugested pairing I want to be able to accept pairing with a suggested pair Scenario: User accepts suggested pairing - And only the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - When I log in as "Bender" - And I visit "/Bender" - And I follow "Yes" + When logged in as "Bender", I visit my only availability And I press "Suggest pairing" - And I log out - And I log in as "PhilipJFry" - And I visit "/PhilipJFry" - And I follow "Yes" - Then I should see "Bender suggested pairing" + And logged in as "PhilipJFry", I visit my only availability + Then I should see the following pair statuses: + | developer | status | + | Bender | Bender suggested pairing | When I press "Accept" - Then I should see "Paired" - When I log out - And I log in as "Bender" - And I visit "/Bender" - And I follow "Yes" - Then I should see "Paired" + Then I should see the following pair statuses: + | developer | status | + | Bender | Paired | + When logged in as "Bender", I visit my only availability + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | Paired | When I press "Cancel pairing" - Then I should see "PhilipJFry suggested pairing" + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | PhilipJFry suggested pairing | + +#Post.update_all({:removed=>true}, {:id=>params[:posts]}) + Scenario: User accepts a suggested pairings and all other pairings suggested by the other user for the same avaialability are cleared + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | + And "PhilipJFry" has suggested pairing with all available pairs + When logged in as "PhilipJFry", I visit my only availability + Then I should see the following pair statuses: + | developer | status | + | DrZoidberg | You suggested pairing | + | Bender | You suggested pairing | + When logged in as "Bender", I visit my only availability + And I press "Accept" + When logged in as "PhilipJFry", I visit my only availability + Then I should see the following pair statuses: + | developer | status | + | DrZoidberg | Open | + | Bender | Paired | + + Scenario: User accepts a suggested pairings and all other pairings suggested same user for the same avaialability are cleared + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | + And "PhilipJFry" has suggested pairing with "Bender" where possible + And "Bender" has suggested pairing with all available pairs except "PhilipJFry" + When logged in as "Bender", I visit my only availability + Then I should see the following pair statuses: + | developer | status | + | DrZoidberg | You suggested pairing | + | PhilipJFry | PhilipJFry suggested pairing | + When I press "Accept" + Then I should see the following pair statuses: + | developer | status | + | DrZoidberg | Open | + | PhilipJFry | Paired | - Scenario: User accepts one of many suggested pairings and all other outward suggestions are cleared Scenario: User accepts one suggestion then accepts a different suggestion and the previous acceptance is cleared + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | DrZoidberg | | December 13, 2019 20:30 | December 14, 2019 01:30 | http://github.com/Dr_Zoidberg | + And "PhilipJFry" has suggested pairing with "Bender" where possible + When logged in as "Bender", I visit my only availability + And I press "Accept" + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | Paired | + | DrZoidberg | Open | + When "DrZoidberg" has suggested pairing with "Bender" where possible + And logged in as "Bender", I visit my only availability + And I press "Accept" + Then I should see the following pair statuses: + | developer | status | + | DrZoidberg | Paired | + | PhilipJFry | PhilipJFry suggested pairing | + + Scenario: User accepts a suggestion from looking at the pair's availability page diff --git a/features/Suggest_pairings.feature b/features/Suggest_pairings.feature index c830b5b..36891c1 100644 --- a/features/Suggest_pairings.feature +++ b/features/Suggest_pairings.feature @@ -1,21 +1,26 @@ Feature: Suggest pairing In order to initiate pairing with any of the available pairs As an open source developer with available pairs I want to be able to suggest pairing with an available pair Scenario: User suggests and cancels pairing with matching developer Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" And I visit "/Bender" And I follow "Yes" - Then I should see "Open" - Then I should not see "Suggested" + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | Open | When I press "Suggest pairing" - Then I should see "You suggested pairing" + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | You suggested pairing | When I press "Cancel" - Then I should not see "You suggested pairing" - And I should see "Open" - + Then I should see the following pair statuses: + | developer | status | + | PhilipJFry | Open | + + Scenario: User suggests pairing from looking at the pair's availability page diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index a6fc4f0..b84e082 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,59 +1,65 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| user = ensure_user(row[0],row[4]) Availability.create(:user_id => user.id, :project => row[1], :start_time => row[2], :end_time => row[3]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1], :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end When "I visit the edit page for the only availability in the system" do visit "/availabilities/#{Availability.find(:all)[0].id}/edit" end Then /^I should see the following availabilites listed in order:?$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end +When /^logged in as "([^\"]*)", I visit my only availability$/ do |username| + When "I log in as \"#{username}\"" + And "I visit \"/#{username}\"" + And "I follow \"Yes\"" +end + diff --git a/features/step_definitions/pair_steps.rb b/features/step_definitions/pair_steps.rb new file mode 100644 index 0000000..eaf8aa6 --- /dev/null +++ b/features/step_definitions/pair_steps.rb @@ -0,0 +1,55 @@ +Given /^"([^\"]*)" has suggested pairing with all available pairs$/ do |username| + user = User.find(:all,:conditions => {:username => username})[0] + user.availabilities.each do |availability| + availability.pairs.each do |pair| + pair.accepted = true + pair.save + reciprocal = pair.find_reciprocal_pair + reciprocal.suggested = true + reciprocal.save + end + end + sleep 1 +end + +Given /^"([^\"]*)" has suggested pairing with "([^\"]*)" where possible$/ do |username, pair_username| + user = User.find(:all,:conditions => {:username => username})[0] + pair_user = User.find(:all,:conditions => {:username => pair_username})[0] + user.availabilities.each do |availability| + availability.pairs.each do |pair| + if (pair.user_id == pair_user.id) + pair.accepted = true + pair.save + reciprocal = pair.find_reciprocal_pair + reciprocal.suggested = true + reciprocal.save + end + end + end + sleep 1 +end + +Given /^"([^\"]*)" has suggested pairing with all available pairs except "([^\"]*)"$/ do |username, pair_username| + user = User.find(:all,:conditions => {:username => username})[0] + pair_user = User.find(:all,:conditions => {:username => pair_username})[0] + user.availabilities.each do |availability| + availability.pairs.each do |pair| + if (pair.user_id != pair_user.id) + pair.accepted = true + pair.save + reciprocal = pair.find_reciprocal_pair + reciprocal.suggested = true + reciprocal.save + end + end + end + sleep 1 +end + +Then /^I should see the following pair statuses:$/ do |table| + table.rows.each_with_index do |row,index| + row_selector = ".pairs tr:nth-child(#{index + 2})" + Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" + Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(7)\"" + end +end diff --git a/spec/controllers/pairs_controller_spec.rb b/spec/controllers/pairs_controller_spec.rb index 7fb94b4..362d725 100644 --- a/spec/controllers/pairs_controller_spec.rb +++ b/spec/controllers/pairs_controller_spec.rb @@ -1,197 +1,219 @@ require 'spec_helper' class FakePair - attr_accessor :id,:accepted, :suggested, :availability, :saved, :save_count, :reciprocal_pair + attr_accessor :id,:accepted, :suggested, :availability, :accept, :saved, :save_count, :reciprocal_pair, :availability_id, :available_pair_id def save @saved = self.clone @save_count ||= 0 - @save_count += 1 + @save_count += 1 end def find_reciprocal_pair @reciprocal_pair end end class FakeAvailability attr_accessor :id,:user_id end class FakeUserSession attr_accessor :user_id, :user end class FakeUser attr_accessor :id end describe PairsController do availability = nil pair = nil reciprocal_pair = nil user_session = nil user = nil other_user = nil before do availability = FakeAvailability.new + other_availability = FakeAvailability.new pair = FakePair.new reciprocal_pair = FakePair.new user_session = FakeUserSession.new user = FakeUser.new other_user = FakeUser.new pair.id = rand(100) reciprocal_pair.id = rand(100) user.id = rand(100) availability.id = rand(100) - other_user.id = availability.id * 2 + other_availability.id = availability.id + 1 + other_user.id = availability.id + 1 user_session.user = user user_session.user_id = user.id pair.availability = availability + pair.availability_id = availability.id + pair.available_pair_id = other_availability.id pair.reciprocal_pair = reciprocal_pair end describe "when suggesting pairing" do describe "and the user is not logged in" do before do UserSession.stub!(:find).and_return(nil) end it "should redirect to the login page" do post :suggest, :id => 1234 response.should redirect_to(new_user_session_url) end end describe "and the user is logged in" do before do UserSession.stub!(:find).and_return(user_session) Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) end describe "and the pair belongs to a different user" do before do availability.user_id = other_user.id end it "should redirect to the homepage" do post :suggest, :id => pair.id response.should redirect_to(root_url) end end describe "and the pair belongs to the current user" do before do availability.user_id = user.id end it "should redirect back to the show availability page" do post :suggest, :id => pair.id response.should redirect_to(availability_url(availability)) end describe "and the pairing has not been suggested" do before do + pair.suggested = false pair.accepted = false - pair.accepted = true end it "should save the pair as accepted" do post :suggest, :id => pair.id pair.saved.accepted.should be true pair.save_count.should be(1) end it "should save the reciprocal pair as suggested" do post :suggest, :id => pair.id reciprocal_pair.saved.suggested.should be true reciprocal_pair.save_count.should be(1) end end + + describe "and the pairing has been suggested" do + + before do + pair.suggested = true + pair.accepted = true + end + + it "should clear all other suggested pairs for this availability" do + post :suggest, :id => pair.id + raise "TODO: missing test" + end + + it "should clear all other suggested pairs for the pair's availability" do + post :suggest, :id => pair.id + raise "TODO: missing test" + end + end end end end describe "when cancelling a suggested pairing" do describe "and the user is not logged in" do before do UserSession.stub!(:find).and_return(nil) end it "should redirect to the login page" do post :cancel, :id => 1234 response.should redirect_to(new_user_session_url) end end describe "and the user is logged in" do before do UserSession.stub!(:find).and_return(user_session) Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) end describe "and the pair belongs to a different user" do before do availability.user_id = other_user.id end it "should redirect to the homepage" do post :cancel, :id => pair.id response.should redirect_to(root_url) end end describe "and the pair belongs to the current user" do before do availability.user_id = user.id end it "should redirect back to the show availability page" do post :cancel, :id => pair.id response.should redirect_to(availability_url(availability)) end describe "and the pairing has been suggested" do before do pair.accepted = true reciprocal_pair.suggested = true end it "should save the pair as not accepted" do post :cancel, :id => pair.id pair.saved.accepted.should be false pair.save_count.should be(1) end it "should save the reciprocal pair as not suggested" do post :cancel, :id => pair.id reciprocal_pair.saved.suggested.should be false reciprocal_pair.save_count.should be(1) end end end end end end \ No newline at end of file
adiel/availabletopair
38be5b6bcad0de779795e8f2af6ff4b018a820cb
Force log out at the start of anonymous user scenario
diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index 5a23b92..b234f2b 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,55 +1,55 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | - | Prof Farnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | + | ProfFarnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 minutes in the past: | developer | project | | PhilipJFry | futurama | And the following availabilities in the system with an end time 2 minutes in the future: | developer | project | | MalcolmTucker | the thick of it | When I am on the list availabilities page Then I should see "MalcolmTucker" But I should not see "PhilipJFry" diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index b66ced4..972e4b9 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,61 +1,62 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system - When I am on the homepage + When I log out + And I am on the homepage And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system When I log in as "jeffosmith" And I follow "Make yourself available" And I fill in "Cucumber" for "Project" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time And I press "Publish availability" Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 (2h 30m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." Scenario: An availability can be deleted by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I press "Delete" And I should see the following availabilites listed in order: | developer | project | start time | end time | contact | Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" When I visit the edit page for the only availability in the system Then I should be on the homepage And I should not see "Availability was successfully updated." #TODO: post a save request with id nobbled Scenario: An availability cannot be deleted by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Delete" When I make a request to delete the only availability in the system And I should see the following availabilites listed in order: | who | what | when | dev time | pairs | contact | | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry |
adiel/availabletopair
0982f5943d984853baae18ce36c9007d5bc7514e
Users can suggest and accept matching pairs (todo: prevent accepting more than one pair)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 745e205..0250eae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,53 +1,54 @@ # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password filter_parameter_logging :password, :password_confirmation helper_method :current_user_session, :current_user private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user + return @current_user if defined?(@current_user) return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.user end def require_user unless current_user store_location flash[:notice] = "You must be logged in to access this page" redirect_to new_user_session_url return false end true end def require_no_user if current_user store_location flash[:notice] = "You must be logged out to access this page" redirect_to account_url return false end true end def store_location session[:return_to] = request.request_uri end def redirect_back_or_default(default) redirect_to(session[:return_to] || default) session[:return_to] = nil end end diff --git a/app/controllers/pairs_controller.rb b/app/controllers/pairs_controller.rb new file mode 100644 index 0000000..05216cb --- /dev/null +++ b/app/controllers/pairs_controller.rb @@ -0,0 +1,58 @@ +class PairsController < ApplicationController + + private + + def check_ownership(pair) + if current_user.id != pair.availability.user_id + redirect_to root_url + return false + end + true + end + + + def update_pairing_status(pair,accepted) + pair.accepted = accepted + pair.save + reciprocal_pair = pair.find_reciprocal_pair + reciprocal_pair.suggested = accepted + reciprocal_pair.save + end + + def cancel_pairing(pair) + update_pairing_status(pair, false) + end + + def accept_pairing(pair) + update_pairing_status(pair, true) + end + + public + + # POST /pairs/1/suggest + def suggest + + return unless require_user + pair = Pair.find(params[:id]) + return unless check_ownership(pair) + + accept_pairing(pair) + + redirect_to availability_url(pair.availability) + + end + + # POST /pairs/1/cancel + def cancel + + return unless require_user + pair = Pair.find(params[:id]) + return unless check_ownership(pair) + + cancel_pairing(pair) + + redirect_to availability_url(pair.availability) + + end + +end diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 6c38409..01b7628 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -1,32 +1,42 @@ class UserSessionsController < ApplicationController def new @user_session = UserSession.new end def create @user_session = UserSession.new(params[:user_session]) @user_session.save do |result| if result flash[:notice] = "Successfully logged in." redirect_to root_url else - @user_session.errors.each do |attr,message| - puts "Error: #{attr.inspect}: #{message}" - if (attr == 'openid_identifier' and message == 'did not match any users in our database, have you set up your account to use OpenID?') - #@user_session.errors.clear - redirect_to new_user_url + "?openid_identifier=" + params["openid.identity"] - return - end + if check_errors_for_new_openid + redirect_to(new_user_url + "?openid_identifier=" + params["openid.identity"]) + return end render :action => 'new' end end end def destroy @user_session = UserSession.find @user_session.destroy flash[:notice] = "Successfully logged out." redirect_to root_url end -end \ No newline at end of file + + private + + def check_errors_for_new_openid() + new_open_id = false + @user_session.errors.each do |attr, message| + if (attr == 'openid_identifier' && + message == 'did not match any users in our database, have you set up your account to use OpenID?') + new_open_id = true + break + end + end + return new_open_id + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ff4af44..29b1512 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,12 +1,12 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper def http_root 'http://' + request.env["HTTP_HOST"] end - def mine?(availability) + def mine? (availability) !current_user.nil? && current_user.id == availability.user_id end end diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 311e32a..66bbfc9 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,59 +1,95 @@ module AvailabilitiesHelper def link_to_http(text) http?(text) ? link_to(h(text)) : h(text) end def link_to_email_or_http(text) email?(text) ? mail_to(h(text)) : link_to_http(text) end def contact_link(availability) link_to_email_or_http( availability.contact) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability) "%dh %02dm" % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)}" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end def pairs_updated(availability) availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at end + + def pair_status(pair) + if (!pair.accepted && !pair.suggested) + return "Open" + elsif (pair.accepted && pair.suggested) + return "Paired" + else + if (pair.accepted) + user = current_user_accepted(pair) ? "You" : pair.availability.user.username + else + user = current_user_suggested(pair) ? "You" : pair.user.username + end + return "#{user} suggested pairing" + end + end + + def button_to_suggest_accept(pair) + if (pair.accepted) + action = "cancel" + text = pair.suggested ? "Cancel pairing" : "Cancel" + else + action = "suggest" + text = pair.suggested ? "Accept" : "Suggest pairing" + end + button_to(text, {:controller => 'pairs', :action => action, :id => pair.id}, :method => :post) + end + + private + + def current_user_accepted(pair) + return (!current_user.nil? && pair.availability.user_id == current_user.id) + end + + def current_user_suggested(pair) + return (!current_user.nil? && pair.user_id == current_user.id) + end end diff --git a/app/models/pair.rb b/app/models/pair.rb index ed4197f..e04cc0d 100644 --- a/app/models/pair.rb +++ b/app/models/pair.rb @@ -1,8 +1,15 @@ class Pair < ActiveRecord::Base belongs_to :availability belongs_to :user def duration_sec end_time - start_time end + + def find_reciprocal_pair + Pair.find(:all, :conditions => ["availability_id = :availability_id and available_pair_id = :available_pair_id", + {:available_pair_id => self.availability_id, :availability_id => self.available_pair_id}])[0] + end + + end diff --git a/app/models/user.rb b/app/models/user.rb index 5f7c759..7c5cb65 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,10 +1,12 @@ class User < ActiveRecord::Base has_many :availabilities has_many :pairs validates_presence_of :contact +begin acts_as_authentic do |c| - c.openid_required_fields = [:nickname, :email] + #c.openid_required_fields = [:nickname, :email] end +end end diff --git a/app/views/availabilities/_list.html.erb b/app/views/availabilities/_list.html.erb new file mode 100644 index 0000000..ccac1d5 --- /dev/null +++ b/app/views/availabilities/_list.html.erb @@ -0,0 +1,12 @@ +<% @availabilities.each do |availability| %> + <tr> + <td><%= link_to(h(availability.user.username), "/" + h(availability.user.username)) %></td> + <td><%= project_link(availability) %></td> + <td><%= link_to(display_when(availability),availability) %></td> + <td><%=h display_duration(availability) %></td> + <td><%= pairs_link(availability) %></td> + <td><%= display_date_time(availability.updated_at) %></td> + <td><%= mine?(availability) ? link_to('Edit', edit_availability_path(availability)) : "" %></td> + <td><%= mine?(availability) ? button_to('Delete', availability, :confirm => 'Are you sure?', :method => :delete) : "" %></td> +</tr> +<% end %> \ No newline at end of file diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index 48b83d7..e218f21 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,30 +1,18 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> - -<% @availabilities.each do |availability| %> - <tr> - <td><%= link_to(h(availability.user.username), "/" + h(availability.user.username)) %></td> - <td><%= project_link(availability) %></td> - <td><%= link_to(display_when(availability),availability) %></td> - <td><%=h display_duration(availability) %></td> - <td><%= pairs_link(availability) %></td> - <td><%= display_date_time(availability.updated_at) %></td> - <td><%= mine?(availability) ? link_to('Edit', edit_availability_path(availability)) : "" %></td> - <td><%= mine?(availability) ? link_to('Delete', availability, :confirm => 'Are you sure?', :method => :delete) : "" %></td> - </tr> -<% end %> +<%= render :partial => 'list' %> </table> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 84dd9ef..f9b6404 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,41 +1,44 @@ <p> <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) <% if mine?(@availability) %> | <%= link_to 'Edit', edit_availability_path(@availability) %> <% end %> </p> <h2>Pairs available:</h2> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Updated</th> <th>Contact</th> + <th colspan="2">Status</th> </tr> <% @availability.pairs.each do |pair| %> <tr> <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= display_date_time(pair.updated_at) %></td> <td><%= contact_link(pair.user) %></td> + <td><%= pair_status(pair) %></td> + <td><%= mine?(@availability) ? button_to_suggest_accept(pair) : "" %></td> </tr> <% end %> <% if @availability.pairs.length == 0 %> <tr> <td colspan="6"> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. </td> </tr> <% end %> </table> <p>Subscribe to updates of <%=h @availability.user.username %>'s available pairs (<a href="/<%=h @availability.user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d59426a..db5450b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,45 +1,46 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>Available To Pair - <%= h(yield(:title) || "matchmaking for Extreme Programmers") %></title> <%= stylesheet_link_tag 'all' %> + <%= yield(:head_links) %> </head> <body> <div id="header"> <div id="logo"><a href="/">Available To Pair</a></div> <div id="how"> <a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a> </div> <div class="clear">&nbsp;</div> <div id="tagline"> - matchmaking for Extreme Programmers</div> <div id="user_nav"> <% if current_user %> <%=h(current_user.username) %> | - <%= link_to "Edit Profile", edit_user_path(:current) %> | + <%= link_to "Profile", edit_user_path(:current) %> | <%= link_to "Logout", logout_path %> <% else %> <%= link_to "Register", new_user_path %> | <%= link_to "Login", login_path %> <% end %> </div> <div class="clear">&nbsp;</div> </div> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> <% if ENV['RAILS_ENV'] == "production" %> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-11197967-1"); pageTracker._trackPageview(); } catch(err) {}</script> <% end %> </body> </html> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 942fd7f..cf9fceb 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,30 +1,22 @@ +<% content_for :head_links do %> + <link href="<%=http_root%>/<%=h @user.username%>.atom" title="Available to Pair - Atom" type="application/atom+xml" rel="alternate"/> +<% end %> + <h1>All <%= @user.username %>'s availability</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> - -<% @availabilities.each do |availability| %> - <tr> - <td><%=h availability.user.username %></td> - <td><%= project_link(availability) %></td> - <td><%= link_to(display_when(availability),availability) %></td> - <td><%=h display_duration(availability) %></td> - <td><%= pairs_link(availability) %></td> - <td><%= display_date_time(availability.updated_at) %></td> - <td><%= mine?(availability) ? link_to('Edit', edit_availability_path(availability)) : "" %></td> - <td><%= mine?(availability) ? link_to('Delete', availability, :confirm => 'Are you sure?', :method => :delete) : "" %></td> - </tr> -<% end %> +<%= render :partial => '/availabilities/list' %> </table> <p>Subscribe to updates of <%=@user.username %>'s available pairs (<a href="/<%=@user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b8700e2..6d7f799 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,11 @@ ActionController::Routing::Routes.draw do |map| map.root :controller => "availabilities" map.resources :availabilities map.resources :user_sessions map.resources :users map.login "login", :controller => "user_sessions", :action => "new" map.logout "logout", :controller => "user_sessions", :action => "destroy" - map.connect ':id.:format', :controller => :users, :action => :index + map.connect 'pairs/:id/:action', :controller => :pairs, :conditions => { :method => :post } end diff --git a/db/migrate/20091102210300_amend_pairs_add_accepted.rb b/db/migrate/20091102210300_amend_pairs_add_accepted.rb new file mode 100644 index 0000000..f6f1d1c --- /dev/null +++ b/db/migrate/20091102210300_amend_pairs_add_accepted.rb @@ -0,0 +1,9 @@ +class AmendPairsAddAccepted < ActiveRecord::Migration + def self.up + add_column :pairs, :accepted, :boolean, :default => false, :null => false + end + + def self.down + remove_column :pairs, :accepted + end +end diff --git a/db/migrate/20091102351300_amend_pairs_add_suggested.rb b/db/migrate/20091102351300_amend_pairs_add_suggested.rb new file mode 100644 index 0000000..0523fd5 --- /dev/null +++ b/db/migrate/20091102351300_amend_pairs_add_suggested.rb @@ -0,0 +1,9 @@ +class AmendPairsAddSuggested < ActiveRecord::Migration + def self.up + add_column :pairs, :suggested, :boolean, :default => false, :null => false + end + + def self.down + remove_column :pairs, :suggested + end +end diff --git a/db/schema.rb b/db/schema.rb index f38e20a..2e2c904 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,72 +1,75 @@ # This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20091027153900) do +ActiveRecord::Schema.define(:version => 20091102351300) do create_table "availabilities", :force => true do |t| t.datetime "start_time" t.datetime "end_time" t.datetime "created_at" t.datetime "updated_at" t.string "project" + t.datetime "pairs_updated", :default => '2009-10-19 10:29:27' t.integer "user_id" end add_index "availabilities", ["start_time", "end_time"], :name => "availabilities_pair_search_index" create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" t.string "handle" t.string "assoc_type" t.binary "server_url" t.binary "secret" end create_table "open_id_authentication_nonces", :force => true do |t| t.integer "timestamp", :null => false t.string "server_url" t.string "salt", :null => false end create_table "pairs", :force => true do |t| t.integer "availability_id" t.integer "available_pair_id" t.datetime "created_at" t.datetime "updated_at" t.string "project" t.datetime "start_time" t.datetime "end_time" t.integer "user_id" + t.boolean "accepted", :default => false, :null => false + t.boolean "suggested", :default => false, :null => false end add_index "pairs", ["availability_id"], :name => "pairs_availability_id_index" create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "crypted_password" t.string "password_salt" t.string "openid_identifier", :null => false t.string "persistence_token", :null => false t.string "single_access_token", :null => false t.string "perishable_token", :null => false t.integer "login_count", :default => 0, :null => false t.integer "failed_login_count", :default => 0, :null => false t.datetime "last_request_at" t.datetime "current_login_at" t.datetime "last_login_at" t.string "current_login_ip" t.string "last_login_ip" t.string "contact" end end diff --git a/features/Accept_pairings.feature b/features/Accept_pairings.feature new file mode 100644 index 0000000..011bc04 --- /dev/null +++ b/features/Accept_pairings.feature @@ -0,0 +1,31 @@ +Feature: Accept pairing + In order to let a developer who has suggested pairing know I want to pair and to let others know I am taken + As an open source developer to whom others have sugested pairing + I want to be able to accept pairing with a suggested pair + + Scenario: User accepts suggested pairing + And only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + When I log in as "Bender" + And I visit "/Bender" + And I follow "Yes" + And I press "Suggest pairing" + And I log out + And I log in as "PhilipJFry" + And I visit "/PhilipJFry" + And I follow "Yes" + Then I should see "Bender suggested pairing" + When I press "Accept" + Then I should see "Paired" + When I log out + And I log in as "Bender" + And I visit "/Bender" + And I follow "Yes" + Then I should see "Paired" + When I press "Cancel pairing" + Then I should see "PhilipJFry suggested pairing" + + Scenario: User accepts one of many suggested pairings and all other outward suggestions are cleared + Scenario: User accepts one suggestion then accepts a different suggestion and the previous acceptance is cleared diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index 65077fd..5a23b92 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,55 +1,55 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | + | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | | Prof Farnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system And the following availabilities in the system with an end time 2 minutes in the past: | developer | project | | PhilipJFry | futurama | And the following availabilities in the system with an end time 2 minutes in the future: | developer | project | | MalcolmTucker | the thick of it | When I am on the list availabilities page Then I should see "MalcolmTucker" But I should not see "PhilipJFry" diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index 79d0be0..b66ced4 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,46 +1,61 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance -# Need to automate / stub openID somehow to get the test back in Scenario: Anonymous user tries to add new availability and is redirected to login Given no availabilities in the system - And a user "jeffosmith" with openid url "http://someopenid.url" When I am on the homepage + And I follow "Make yourself available" Then I should see "You must be logged in to access this page" Scenario: User adds new availability Given no availabilities in the system - And a user "jeffosmith" with openid url "http://someopenid.url" - When I am on the homepage + When I log in as "jeffosmith" And I follow "Make yourself available" - And I fill in "OpenID URL" with "http://someopenid.url" - And I press "Login" + And I fill in "Cucumber" for "Project" And I select "December 25, 2014 10:00" as the "Start time" date and time And I select "December 25, 2014 12:30" as the "End time" date and time - And I fill in "contact" with "http://github.com/aslakhellesoy" And I press "Publish availability" - Then I should see /jeffosmith is available to pair on Cucumber for 2h 30m from Thu Dec 25, 2014 10:00 \- 12:30/ + Then I should see "jeffosmith is available to pair on Cucumber on Thu Dec 25, 2014 10:00 - 12:30 (2h 30m)" Scenario: An availability can be edited by its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | When I log in as "Bender" And I follow "Edit" And I fill in "project" with "updated by user" And I press "Update" Then I should see "Availability was successfully updated." + Scenario: An availability can be deleted by its owner + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + When I log in as "Bender" + And I press "Delete" + And I should see the following availabilites listed in order: + | developer | project | start time | end time | contact | + Scenario: An availability cannot be edited by a user other than its owner Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Philip.J.Fry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | PhilipJFry | original proj | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I log in as "Bender" Then I should not see "Edit" - And I visit the edit page for the only availability in the system - And I fill in "project" with "updated by user" - And I press "Update" - Then I should not see "Availability was successfully updated." - And I should see "original proj" \ No newline at end of file + When I visit the edit page for the only availability in the system + Then I should be on the homepage + And I should not see "Availability was successfully updated." +#TODO: post a save request with id nobbled + + Scenario: An availability cannot be deleted by a user other than its owner + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | PhilipJFry | original proj | January 01, 2020 21:30 | January 01, 2020 22:30 | http://github.com/philip_j_fry | + When I log in as "Bender" + Then I should not see "Delete" + When I make a request to delete the only availability in the system + And I should see the following availabilites listed in order: + | who | what | when | dev time | pairs | contact | + | PhilipJFry | original proj | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | diff --git a/features/Suggest_pairings.feature b/features/Suggest_pairings.feature new file mode 100644 index 0000000..c830b5b --- /dev/null +++ b/features/Suggest_pairings.feature @@ -0,0 +1,21 @@ +Feature: Suggest pairing + In order to initiate pairing with any of the available pairs + As an open source developer with available pairs + I want to be able to suggest pairing with an available pair + + Scenario: User suggests and cancels pairing with matching developer + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | PhilipJFry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + When I log in as "Bender" + And I visit "/Bender" + And I follow "Yes" + Then I should see "Open" + Then I should not see "Suggested" + When I press "Suggest pairing" + Then I should see "You suggested pairing" + When I press "Cancel" + Then I should not see "You suggested pairing" + And I should see "Open" + diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index b15ac91..24de708 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,72 +1,72 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | - | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | + | ProfFarnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Prof Farnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | + | ProfFarnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | - Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" - Then My path should be "/Bender.atom" \ No newline at end of file + Then My path should be "/Bender.atom" + diff --git a/features/ruby b/features/ruby deleted file mode 100644 index e69de29..0000000 diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index 2178a50..a6fc4f0 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,76 +1,59 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end -def ensure_user(username,contact = '') - user = Test::User.find(:all, :conditions => ["username = :username", {:username => username}])[0] - if user.nil? - user = Test::User.new(:username => username, - :openid_identifier => 'a', - :persistence_token => 's', - :single_access_token => 'd', - :perishable_token => 'f') - end - user.contact = contact - user.save! - user -end - -class Test::User < ActiveRecord::Base - # This is here to bypass authlogic and go direct to ActiveRecord - has_many :availabilities - has_many :pairs -end - Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| user = ensure_user(row[0],row[4]) Availability.create(:user_id => user.id, :project => row[1], :start_time => row[2], :end_time => row[3]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1], :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| user = ensure_user(row[0],'asdf') Availability.create(:user_id => user.id, :project => row[1],:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end +When "I visit the edit page for the only availability in the system" do + visit "/availabilities/#{Availability.find(:all)[0].id}/edit" +end -Then /^I should see the following availabilites listed in order$/ do |table| +Then /^I should see the following availabilites listed in order:?$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 422290d..d0c280e 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,147 +1,181 @@ +class ApplicationController < ActionController::Base + def current_user_session + $webrat_user_session + end +end + +def ensure_user(username,contact = 'cucumber') + user = User.find(:all, :conditions => ["username = :username", {:username => username}])[0] + if user.nil? + user = User.new(:username => username, + :password => 'cucumber', + :password_confirmation => 'cucumber', + :contact => contact, + :email => "#{username}@example.com", + :openid_identifier => username) + end + user.contact = contact + user.save! + user +end + Given /^a user "([^\"]*)"$/ do |username| ensure_user(username) end When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end +When /check the published date of the feed entry at position (\d*)$/ do |entry_position| + published_text = AtomHelper.published_text(response.body,entry_position) + published_text.should_not eql("") + @published_dates ||= {} + @published_dates[entry_position] = Time.parse(published_text) +end + + +When /^I log in as "([^\"]*)"$/ do |username| + When "I am on the homepage" + ensure_user(username) + $webrat_user_session = UserSession.new(:username => username, :password => 'cucumber') + $webrat_user_session.save + When "I am on the homepage" +end + +When /^I log out$/ do + $webrat_user_session = nil +end + Then /^My path should be "([^\"]*)"$/ do |path| URI.parse(current_url).path.should == path end Then /^I (?:should )?see the following feed entries:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) end end Then /^I should see the following feed entries with content:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) content = entry.xpath("xmlns:content").text content_html = Nokogiri::HTML(content) content_html.text.should =~ /#{table.rows[index][1]}/ end end Then /^The only entry's content should link to availability page from time period$/ do doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') only_availability = Availability.find(:all)[0] expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")}" content = entries[0].xpath("xmlns:content").text content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) end Then /^the feed should have the following properties:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) end end Then /^the feed should have the following links:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") link.length.should eql(1) - link.xpath("@rel").text.should eql(row[1]) + link.xpath("@rel").text.should eql(row[1]) end end Then /^the feed should have the following text nodes:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| - doc.xpath(row[0]).text.should eql(row[1]) + doc.xpath(row[0]).text.should eql(row[1]) end end -When /check the published date of the feed entry at position (\d*)$/ do |entry_position| - published_text = AtomHelper.published_text(response.body,entry_position) - published_text.should_not eql("") - @published_dates ||= {} - @published_dates[entry_position] = Time.parse(published_text) -end - When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| id = AtomHelper.entry_id(response.body,entry_position) sleep 1 # to make sure the new updated_at is different Availability.find(id).touch end Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| published = Time.parse(AtomHelper.published_text(response.body,entry_position)) @published_dates[entry_position].should < published Time.now.should >= published end Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should eql(Time.parse(published_text).xmlschema) end Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| doc = Nokogiri::XML(response.body) published = AtomHelper.published_text(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:updated").text.should eql(published) end Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) end Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) end Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| doc = Nokogiri::XML(response.body) id = AtomHelper.entry_id(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) end Then /^I reduce the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I reduce the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time -= (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time += (extend_by.to_i * 60) sleep 2 #make sure the updated_at is changed availabilty.save end \ No newline at end of file diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 77c40e5..827c51d 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,134 +1,140 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; font-size:0.8em; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:0.9em; border-collapse: collapse; width:95%; } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.2em 1.0em 1em; } h1 { font-size:1.4em; margin:0.8em; } h2 { font-size:1.2em; margin:1.2em 0.8em 0.3em; } #header { font-size:2.5em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { font-size:1.3em; padding:0.2em; border:1px solid #999; margin:0.2em; } select { font-size:1.2em; } input { width:35em; } -.submit input { +table input, .submit input { width:auto; } +table input { + font-size:1.1em; + cursor:pointer; + margin:-2px; + padding:1px; +} .username input, .email input{ width:15em; } #availability_project { width:22.4em; } #logo {float:left;} #how {float:right;} .clear{ clear:both; font-size:0; } #logo a { color:#000; text-decoration:none; } .nav{ margin:1.5em; } #tagline { font-style:italic; font-size:0.4em; margin-left:1em; float:left; } input#user_openid_identifier, input#user_session_openid_identifier { background: url(http://openid.net/images/login-bg.gif) no-repeat; background-color: #fff; background-position: 2px 50%; color: #000; padding-left: 20px; width:34.2em; } .fieldWithErrors { display:inline; margin:1em; } #user_nav { float:right; text-align:right; margin:.5em 0 0; font-size:0.4em; } form label { margin:0.2em; font-size:1.4em; } .errorExplanation { color:#cc0000; } .duration, .time, .project { font-weight:bold; } diff --git a/spec/controllers/pairs_controller_spec.rb b/spec/controllers/pairs_controller_spec.rb new file mode 100644 index 0000000..7fb94b4 --- /dev/null +++ b/spec/controllers/pairs_controller_spec.rb @@ -0,0 +1,197 @@ +require 'spec_helper' + +class FakePair + attr_accessor :id,:accepted, :suggested, :availability, :saved, :save_count, :reciprocal_pair + + def save + @saved = self.clone + @save_count ||= 0 + @save_count += 1 + end + + def find_reciprocal_pair + @reciprocal_pair + end + +end +class FakeAvailability + attr_accessor :id,:user_id +end +class FakeUserSession + attr_accessor :user_id, :user +end +class FakeUser + attr_accessor :id +end + +describe PairsController do + + availability = nil + pair = nil + reciprocal_pair = nil + user_session = nil + user = nil + other_user = nil + + before do + + availability = FakeAvailability.new + pair = FakePair.new + reciprocal_pair = FakePair.new + user_session = FakeUserSession.new + user = FakeUser.new + other_user = FakeUser.new + + pair.id = rand(100) + reciprocal_pair.id = rand(100) + user.id = rand(100) + availability.id = rand(100) + other_user.id = availability.id * 2 + user_session.user = user + user_session.user_id = user.id + pair.availability = availability + pair.reciprocal_pair = reciprocal_pair + + end + + describe "when suggesting pairing" do + + describe "and the user is not logged in" do + before do + UserSession.stub!(:find).and_return(nil) + end + + it "should redirect to the login page" do + post :suggest, :id => 1234 + response.should redirect_to(new_user_session_url) + end + end + + describe "and the user is logged in" do + + before do + UserSession.stub!(:find).and_return(user_session) + Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) + end + + describe "and the pair belongs to a different user" do + before do + availability.user_id = other_user.id + end + + it "should redirect to the homepage" do + post :suggest, :id => pair.id + response.should redirect_to(root_url) + end + end + + describe "and the pair belongs to the current user" do + before do + availability.user_id = user.id + end + + it "should redirect back to the show availability page" do + post :suggest, :id => pair.id + response.should redirect_to(availability_url(availability)) + end + + describe "and the pairing has not been suggested" do + + before do + pair.accepted = false + pair.accepted = true + end + + it "should save the pair as accepted" do + + post :suggest, :id => pair.id + + pair.saved.accepted.should be true + pair.save_count.should be(1) + + end + + it "should save the reciprocal pair as suggested" do + + post :suggest, :id => pair.id + + reciprocal_pair.saved.suggested.should be true + reciprocal_pair.save_count.should be(1) + + end + end + end + end + end + + describe "when cancelling a suggested pairing" do + + describe "and the user is not logged in" do + before do + UserSession.stub!(:find).and_return(nil) + end + + it "should redirect to the login page" do + post :cancel, :id => 1234 + response.should redirect_to(new_user_session_url) + end + end + + describe "and the user is logged in" do + + before do + UserSession.stub!(:find).and_return(user_session) + Pair.stub!(:find).with(pair.id.to_s).once.and_return(pair) + end + + describe "and the pair belongs to a different user" do + before do + availability.user_id = other_user.id + end + + it "should redirect to the homepage" do + post :cancel, :id => pair.id + response.should redirect_to(root_url) + end + end + + describe "and the pair belongs to the current user" do + before do + availability.user_id = user.id + end + + it "should redirect back to the show availability page" do + post :cancel, :id => pair.id + response.should redirect_to(availability_url(availability)) + end + + describe "and the pairing has been suggested" do + + before do + pair.accepted = true + reciprocal_pair.suggested = true + end + + it "should save the pair as not accepted" do + + post :cancel, :id => pair.id + + pair.saved.accepted.should be false + pair.save_count.should be(1) + + end + + it "should save the reciprocal pair as not suggested" do + + post :cancel, :id => pair.id + + reciprocal_pair.saved.suggested.should be false + reciprocal_pair.save_count.should be(1) + + end + end + end + end + end + +end \ No newline at end of file diff --git a/spec/helpers/availabilities_helper_spec.rb b/spec/helpers/availabilities_helper_spec.rb index 8806646..8bed65b 100644 --- a/spec/helpers/availabilities_helper_spec.rb +++ b/spec/helpers/availabilities_helper_spec.rb @@ -1,6 +1,42 @@ require 'spec_helper' +=begin + +class FakePair + attr_accessor :accepted + def accepted + @accepted + end +end + + +class AvailabilitiesHelperTester + include AvailabilitiesHelper +end describe AvailabilitiesHelper do + describe "when building suggest/accept pair links" do + + pair = FakePair.new + + describe "and the pairing has not been suggested" do + + before do + pair.accepted = false + end + + it "should build a link to the availability with action suggest and method post" do + + link = AvailabilitiesHelperTester.new.link_to_suggest_accept(pair) + + link.should_be "asdf" + + end + + end + + end end + +=end diff --git a/spec/models/pair_spec.rb b/spec/models/pair_spec.rb new file mode 100644 index 0000000..9c6078c --- /dev/null +++ b/spec/models/pair_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Pair do + + it "should find the reciprocal pair by reversing availability_id and available_pair_id" do + + pair = Pair.new + pair.availability_id = 112358 + pair.available_pair_id = 135711 + + expected_reciprocal_pair = Pair.new + + Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id and available_pair_id = :available_pair_id", + {:available_pair_id => pair.availability_id, :availability_id => pair.available_pair_id}]).and_return([expected_reciprocal_pair]) + + pair.find_reciprocal_pair.should be expected_reciprocal_pair + + end + +end \ No newline at end of file
adiel/availabletopair
977b173ec6b25d4699469c82e27998725d2139ac
Read openid.identity param to pass to registration
diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 1e66b00..6c38409 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -1,32 +1,32 @@ class UserSessionsController < ApplicationController def new @user_session = UserSession.new end def create @user_session = UserSession.new(params[:user_session]) @user_session.save do |result| if result flash[:notice] = "Successfully logged in." redirect_to root_url else @user_session.errors.each do |attr,message| puts "Error: #{attr.inspect}: #{message}" if (attr == 'openid_identifier' and message == 'did not match any users in our database, have you set up your account to use OpenID?') #@user_session.errors.clear - redirect_to new_user_url + "?openid_identifier=" + params["openid1_claimed_id"] + redirect_to new_user_url + "?openid_identifier=" + params["openid.identity"] return end end render :action => 'new' end end end def destroy @user_session = UserSession.find @user_session.destroy flash[:notice] = "Successfully logged out." redirect_to root_url end end \ No newline at end of file
adiel/availabletopair
a7319bfbd2ab43054a9e30d334cb2093b4e8a0d9
Rewording
diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index f771b56..b15ac91 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,72 +1,72 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ + Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Prof Farnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" \ No newline at end of file
adiel/availabletopair
2ee282c0ee3b4922715ca1327e3e8f1a01e87497
Tidied some layout
diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 790f691..84dd9ef 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,41 +1,41 @@ -<h1> - <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span> +<p> + <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> is available to pair on <span class="project"><%= project_link(@availability) %></span> on <span class="time"><%=h display_when(@availability) %></span> (<span class="duration"><%= display_duration(@availability) %></span>) <% if mine?(@availability) %> | <%= link_to 'Edit', edit_availability_path(@availability) %> <% end %> -</h1> +</p> - <h2>Pairs available:</h2> +<h2>Pairs available:</h2> - <table class="pairs"> - <tr> - <th>Who</th> - <th>What</th> - <th>When</th> - <th>Dev time</th> - <th>Updated</th> - <th>Contact</th> - </tr> +<table class="pairs"> + <tr> + <th>Who</th> + <th>What</th> + <th>When</th> + <th>Dev time</th> + <th>Updated</th> + <th>Contact</th> + </tr> - <% @availability.pairs.each do |pair| %> - <tr> - <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> - <td><%= project_link(pair) %></td> - <td><%=h display_when(pair) %></td> - <td><%=h display_duration(pair) %></td> - <td><%= display_date_time(pair.updated_at) %></td> - <td><%= contact_link(pair.user) %></td> - </tr> - <% end %> - <% if @availability.pairs.length == 0 %> - <tr> - <td colspan="6"> - No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. - </td> - </tr> - <% end %> - </table> +<% @availability.pairs.each do |pair| %> + <tr> + <td><%= link_to(h(pair.user.username),"/" + h(pair.user.username)) %></td> + <td><%= project_link(pair) %></td> + <td><%=h display_when(pair) %></td> + <td><%=h display_duration(pair) %></td> + <td><%= display_date_time(pair.updated_at) %></td> + <td><%= contact_link(pair.user) %></td> + </tr> +<% end %> +<% if @availability.pairs.length == 0 %> + <tr> + <td colspan="6"> + No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.user.username),"/" + h(@availability.user.username)) %> over this period. + </td> + </tr> +<% end %> +</table> <p>Subscribe to updates of <%=h @availability.user.username %>'s available pairs (<a href="/<%=h @availability.user.username%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index ba01f4b..f771b56 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,72 +1,72 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on anything for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ + Then I should see /Bender is available to pair on anything on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ + Then I should see /Bender is available to pair on Futurama on Fri Dec 13, 2019 22:00 \- 04:30 (6h 30m)/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Prof Farnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" \ No newline at end of file diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 6978c87..77c40e5 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,126 +1,134 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; font-size:0.8em; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:0.9em; border-collapse: collapse; width:95%; } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.2em 1.0em 1em; } h1 { font-size:1.4em; margin:0.8em; } h2 { font-size:1.2em; margin:1.2em 0.8em 0.3em; } #header { font-size:2.5em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { - font-size:1.5em; + font-size:1.3em; padding:0.2em; border:1px solid #999; margin:0.2em; } +select { + font-size:1.2em; +} + input { width:35em; } .submit input { width:auto; } .username input, .email input{ width:15em; } #availability_project { width:22.4em; } #logo {float:left;} #how {float:right;} .clear{ clear:both; font-size:0; } #logo a { color:#000; text-decoration:none; } .nav{ margin:1.5em; } #tagline { font-style:italic; font-size:0.4em; margin-left:1em; float:left; } input#user_openid_identifier, input#user_session_openid_identifier { background: url(http://openid.net/images/login-bg.gif) no-repeat; background-color: #fff; background-position: 2px 50%; color: #000; padding-left: 20px; width:34.2em; } .fieldWithErrors { display:inline; margin:1em; } #user_nav { float:right; text-align:right; margin:.5em 0 0; font-size:0.4em; } form label { margin:0.2em; font-size:1.4em; } .errorExplanation { color:#cc0000; } + +.duration, .time, .project { + font-weight:bold; +}
adiel/availabletopair
5bb50e5c925c9984d6c0552a3ae9ede5c75077a8
Gem manifest
diff --git a/.gems b/.gems new file mode 100644 index 0000000..bdf2fef --- /dev/null +++ b/.gems @@ -0,0 +1,2 @@ +authlogic +authlogic-oid \ No newline at end of file
adiel/availabletopair
f90d96a2964c3e22e37b88d6fd8a22536c067f26
Suggest registration when openid not recognised. Lock down username.
diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 6ea472e..1e66b00 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -1,24 +1,32 @@ class UserSessionsController < ApplicationController def new @user_session = UserSession.new end def create @user_session = UserSession.new(params[:user_session]) @user_session.save do |result| if result flash[:notice] = "Successfully logged in." redirect_to root_url else + @user_session.errors.each do |attr,message| + puts "Error: #{attr.inspect}: #{message}" + if (attr == 'openid_identifier' and message == 'did not match any users in our database, have you set up your account to use OpenID?') + #@user_session.errors.clear + redirect_to new_user_url + "?openid_identifier=" + params["openid1_claimed_id"] + return + end + end render :action => 'new' end end end def destroy @user_session = UserSession.find @user_session.destroy flash[:notice] = "Successfully logged out." redirect_to root_url end end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index abdd140..e78893b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,68 +1,71 @@ class UsersController < ApplicationController private def sort_availabilities_and_pairs @availabilities.each do |availability| availability.pairs.sort!{ |p1, p2| p1.updated_at <=> p2.updated_at}.reverse! end @availabilities.sort! do |a1, a2| a1_updated = a1.pairs.length == 0 ? a1.updated_at : a1.pairs[0].updated_at a2_updated = a2.pairs.length == 0 ? a2.updated_at : a2.pairs[0].updated_at a1_updated <=> a2_updated end.reverse! end public # GET /username # GET /username.atom def index @user = User.find(:all,:conditions => ["username = :username",{:username => params[:id]}])[0] if @user.nil? redirect_to root_url return end @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["user_id = :user_id and end_time > :end_time" , {:user_id => @user.id,:end_time => Time.now.utc}]) respond_to do |format| format.html # new.html.erb format.atom do sort_availabilities_and_pairs end end end def new @user = User.new + @user.openid_identifier = params[:openid_identifier] end def create @user = User.new(params[:user]) @user.save do |result| if result flash[:notice] = "Registration successful." redirect_to root_url else render :action => 'new' end end end def edit @user = current_user end def update @user = current_user + username = current_user.username @user.attributes = params[:user] + @user.username = username @user.save do |result| if result flash[:notice] = "Successfully updated profile." redirect_to root_url else render :action => 'edit' end end end end diff --git a/app/models/availability.rb b/app/models/availability.rb index d9014d8..78c542b 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,21 +1,21 @@ class Availability < ActiveRecord::Base validates_presence_of :user_id,:start_time, :end_time belongs_to :user has_many :pairs strip_attributes! - + def save(pair_synchronizer = PairSynchronizer.new) super() pair_synchronizer.synchronize_pairs(self) end def destroy(pair_synchronizer = PairSynchronizer.new) super() pair_synchronizer.destroy_pairs(self) end def duration_sec end_time - start_time end end diff --git a/app/models/user.rb b/app/models/user.rb index d5d8c25..5f7c759 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,9 +1,10 @@ class User < ActiveRecord::Base has_many :availabilities has_many :pairs + validates_presence_of :contact acts_as_authentic do |c| c.openid_required_fields = [:nickname, :email] end end diff --git a/app/models/user_session.rb b/app/models/user_session.rb index 8c19d19..81322fb 100644 --- a/app/models/user_session.rb +++ b/app/models/user_session.rb @@ -1,2 +1,3 @@ class UserSession < Authlogic::Session::Base + end \ No newline at end of file diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 122ede5..e43735d 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -1,23 +1,25 @@ <% form_for @user do |f| %> <%= f.error_messages %> + <p> + <%= f.label :openid_identifier, '<a href="http://openid.net/what/">OpenID</a> URL' %><br /> + <%= f.text_field :openid_identifier %> + </p> + <% if @user.id.nil? %> <p class="username"> <%= f.label :username %><br /> <%= f.text_field :username %> </p> + <% end %> <p class="email"> <%= f.label :email %> (private)<br /> <%= f.text_field :email %> </p> <p> <%= f.label :contact %> (public) - Could be your page on SourceForge, GitHub, bitbucket etc, or an email address if you prefer.<br /> <%= f.text_field :contact%> </p> - <p> - <%= f.label :openid_identifier, '<a href="http://openid.net/what/">OpenID</a> URL' %><br /> - <%= f.text_field :openid_identifier %> - </p> - <p class="submit"><%= f.submit "Save" %></p> + <p class="submit"><%= f.submit(@user.id.nil? ? "Register" : "Update") %></p> <% end %> <div class="nav"> <%= link_to 'Cancel', availabilities_path %> </div> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 8353b17..5bd8ef4 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1 +1,2 @@ +<h1>Edit <%=h current_user.username %>'s profile</h1> <%= render :partial => 'form' %> \ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 8353b17..31ab033 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1 +1,10 @@ +<h1>New user</h1> +<% if !params[:openid_identifier].nil? %> + <h2> + <p>It looks like this is your first time here, as I don't know that OpenID.</p> + <p> + Please complete the form below to complete your registration. Or <%= link_to "login", new_user_session_url%> with a different OpenID + </p> + </h2> +<% end %> <%= render :partial => 'form' %> \ No newline at end of file diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index d3eb347..6978c87 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,123 +1,126 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; font-size:0.8em; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:0.9em; border-collapse: collapse; width:95%; } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.2em 1.0em 1em; } h1 { font-size:1.4em; margin:0.8em; } h2 { font-size:1.2em; margin:1.2em 0.8em 0.3em; } #header { font-size:2.5em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { font-size:1.5em; padding:0.2em; border:1px solid #999; margin:0.2em; } input { width:35em; } .submit input { width:auto; } .username input, .email input{ width:15em; } #availability_project { width:22.4em; } #logo {float:left;} #how {float:right;} .clear{ clear:both; font-size:0; } #logo a { color:#000; text-decoration:none; } .nav{ margin:1.5em; } #tagline { font-style:italic; font-size:0.4em; margin-left:1em; float:left; } input#user_openid_identifier, input#user_session_openid_identifier { background: url(http://openid.net/images/login-bg.gif) no-repeat; background-color: #fff; background-position: 2px 50%; color: #000; padding-left: 20px; width:34.2em; } .fieldWithErrors { display:inline; margin:1em; } #user_nav { float:right; text-align:right; margin:.5em 0 0; font-size:0.4em; } form label { margin:0.2em; font-size:1.4em; } +.errorExplanation { + color:#cc0000; +}
adiel/availabletopair
fc455a0e0fb1e58a7a5eb8762bf3204ec06aee8c
Not testing for null project
diff --git a/spec/models/pair_matcher_spec.rb b/spec/models/pair_matcher_spec.rb index 51af0f5..2227a23 100644 --- a/spec/models/pair_matcher_spec.rb +++ b/spec/models/pair_matcher_spec.rb @@ -1,41 +1,41 @@ require 'spec_helper' describe PairMatcher do it "should find pairs as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end describe "when a project has been specified" do it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" availability.project = "some proj" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, - :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", + :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project is null)", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time, :project => availability.project}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end end end
adiel/availabletopair
ec3f53bdf356ecb4db4ada0b47824879aeacfcaf
Refactoring
diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index 1f1448b..0ea6f9a 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,52 +1,52 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| Availability.create(:developer => row[0], :project => row[1], :start_time => row[2], :end_time => row[3], :contact => row[4]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf', :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf',:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end Then /^I should see the following availabilites listed in order$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| - row_selector = ".pair tr:nth-child(#{index + 2})" + row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/spec/models/pair_matcher_spec.rb b/spec/models/pair_matcher_spec.rb index d985b6a..51af0f5 100644 --- a/spec/models/pair_matcher_spec.rb +++ b/spec/models/pair_matcher_spec.rb @@ -1,41 +1,41 @@ require 'spec_helper' describe PairMatcher do - it "should find pair as matching availabilities for different developers where times overlap" do + it "should find pairs as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end describe "when a project has been specified" do - it "should find pair as matching availabilities for different developers on the same project or anything where times overlap" do + it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" availability.project = "some proj" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time, :project => availability.project}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end end end diff --git a/spec/models/pair_synchronizer_spec.rb b/spec/models/pair_synchronizer_spec.rb index 229b639..29b3005 100644 --- a/spec/models/pair_synchronizer_spec.rb +++ b/spec/models/pair_synchronizer_spec.rb @@ -1,144 +1,144 @@ require 'spec_helper' describe PairSynchronizer do - describe "when syncing pair" do + describe "when syncing pairs" do describe "when there is a single new availability" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return([]) end - it "should create two pair for the new match, one in each direction" do + it "should create two pairs for the new match, one in each direction" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[0]) pair_repository.should_receive(:create).with(matching_availabilities[0],availability) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there some existing and some new availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5,6,7,8]) existing_pairs = [stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[0].id), stub(:availability_id => matching_availabilities[0].id, :available_pair_id => availability.id), stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[2].id), stub(:availability_id => matching_availabilities[2].id, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end it "should create any matching pair that doesn't exist" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[1]) pair_repository.should_receive(:create).with(matching_availabilities[1],availability) pair_repository.should_receive(:create).with(availability,matching_availabilities[3]) pair_repository.should_receive(:create).with(matching_availabilities[3],availability) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end it "should update the existing availabilities" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:update).with(existing_pairs[0],availability,matching_availabilities[0]) pair_repository.should_receive(:update).with(existing_pairs[1],matching_availabilities[0],availability) pair_repository.should_receive(:update).with(existing_pairs[2],availability,matching_availabilities[2]) pair_repository.should_receive(:update).with(existing_pairs[3],matching_availabilities[2],availability) pair_repository.stub!(:create) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there are missing availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [mock(:id => 99, :availability_id => availability.id, :available_pair_id => 5), mock(:id => 98, :availability_id => 5, :available_pair_id => availability.id), mock(:id => 97,:availability_id => availability.id, :available_pair_id => 102), mock(:id => 96,:availability_id => 102, :available_pair_id => availability.id), mock(:id => 95,:availability_id => availability.id, :available_pair_id => 103), mock(:id => 94,:availability_id => 103, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end - it "should destroy the missing pair" do + it "should destroy the missing pairs" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) existing_pairs[2].should_receive(:destroy) existing_pairs[3].should_receive(:destroy) existing_pairs[4].should_receive(:destroy) existing_pairs[5].should_receive(:destroy) pair_repository.stub!(:create) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end end end def create_test_availabilities(ids) availabilities = [] ids.each do |id| availability = Availability.new availability.id = id availabilities.push availability end availabilities end
adiel/availabletopair
fdfa7e16be839f013f3da90a4ab66f2b49b50bae
Refactoring
diff --git a/db/schema.rb b/db/schema.rb index e96cfd0..c2079a2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,56 +1,56 @@ # This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 20091023233000) do create_table "availabilities", :force => true do |t| t.string "developer" t.datetime "start_time" t.datetime "end_time" t.string "contact" t.datetime "created_at" t.datetime "updated_at" t.string "project" end add_index "availabilities", ["developer", "start_time", "end_time"], :name => "availabilities_pair_search_index" add_index "availabilities", ["developer"], :name => "availabilities_name_index" create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" t.string "handle" t.string "assoc_type" t.binary "server_url" t.binary "secret" end create_table "open_id_authentication_nonces", :force => true do |t| t.integer "timestamp", :null => false t.string "server_url" t.string "salt", :null => false end - create_table "pairing", :force => true do |t| + create_table "pair", :force => true do |t| t.integer "availability_id" t.integer "available_pair_id" t.datetime "created_at" t.datetime "updated_at" t.string "developer" t.string "project" t.datetime "start_time" t.datetime "end_time" t.string "contact" end - add_index "pairing", ["availability_id"], :name => "pairs_availability_id_index" + add_index "pair", ["availability_id"], :name => "pairs_availability_id_index" end diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index a8da2cd..1f1448b 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,52 +1,52 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| Availability.create(:developer => row[0], :project => row[1], :start_time => row[2], :end_time => row[3], :contact => row[4]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf', :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf',:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end Then /^I should see the following availabilites listed in order$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end -Then /^I should see the following matching pairing$/ do |table| +Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| - row_selector = ".pairing tr:nth-child(#{index + 2})" + row_selector = ".pair tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index 415a05b..27910ab 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,60 +1,60 @@ require 'spec_helper' describe Availability do describe "when the start and end time are within the same day" do it "should calculate the duration as the difference between the end and start times in seconds" do start_time = Time.parse("2009-11-15 09:00") end_time = Time.parse("2009-11-15 17:35") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when the start and end time cross two days" do it "should calculate the duration as the difference between the end and start times" do start_time = Time.parse("2009-11-15 22:00") end_time = Time.parse("2009-11-15 00:15") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when saving" do - it "should sync pairing" do + it "should sync pair" do availability = Availability.new pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:synchronize_pairs).with(availability) availability.pair_synchronizer = pair_synchronizer availability.save end end describe "when destroying" do - it "should sync pairing" do + it "should sync pair" do availability = Availability.new pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:synchronize_pairs).with(availability) availability.pair_synchronizer = pair_synchronizer availability.destroy end end end diff --git a/spec/models/pair_matcher_spec.rb b/spec/models/pair_matcher_spec.rb index a744976..d985b6a 100644 --- a/spec/models/pair_matcher_spec.rb +++ b/spec/models/pair_matcher_spec.rb @@ -1,41 +1,41 @@ require 'spec_helper' describe PairMatcher do - it "should find pairing as matching availabilities for different developers where times overlap" do + it "should find pair as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end describe "when a project has been specified" do - it "should find pairing as matching availabilities for different developers on the same project or anything where times overlap" do + it "should find pair as matching availabilities for different developers on the same project or anything where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" availability.project = "some proj" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time, :project => availability.project}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end end end diff --git a/spec/models/pair_synchronizer_spec.rb b/spec/models/pair_synchronizer_spec.rb index 7a7983f..229b639 100644 --- a/spec/models/pair_synchronizer_spec.rb +++ b/spec/models/pair_synchronizer_spec.rb @@ -1,144 +1,144 @@ require 'spec_helper' describe PairSynchronizer do - describe "when syncing pairing" do + describe "when syncing pair" do describe "when there is a single new availability" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return([]) end - it "should create two pairing for the new match, one in each direction" do + it "should create two pair for the new match, one in each direction" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[0]) pair_repository.should_receive(:create).with(matching_availabilities[0],availability) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there some existing and some new availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5,6,7,8]) existing_pairs = [stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[0].id), stub(:availability_id => matching_availabilities[0].id, :available_pair_id => availability.id), stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[2].id), stub(:availability_id => matching_availabilities[2].id, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end it "should create any matching pair that doesn't exist" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[1]) pair_repository.should_receive(:create).with(matching_availabilities[1],availability) pair_repository.should_receive(:create).with(availability,matching_availabilities[3]) pair_repository.should_receive(:create).with(matching_availabilities[3],availability) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end it "should update the existing availabilities" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:update).with(existing_pairs[0],availability,matching_availabilities[0]) pair_repository.should_receive(:update).with(existing_pairs[1],matching_availabilities[0],availability) pair_repository.should_receive(:update).with(existing_pairs[2],availability,matching_availabilities[2]) pair_repository.should_receive(:update).with(existing_pairs[3],matching_availabilities[2],availability) pair_repository.stub!(:create) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there are missing availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [mock(:id => 99, :availability_id => availability.id, :available_pair_id => 5), mock(:id => 98, :availability_id => 5, :available_pair_id => availability.id), mock(:id => 97,:availability_id => availability.id, :available_pair_id => 102), mock(:id => 96,:availability_id => 102, :available_pair_id => availability.id), mock(:id => 95,:availability_id => availability.id, :available_pair_id => 103), mock(:id => 94,:availability_id => 103, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end - it "should destroy the missing pairing" do + it "should destroy the missing pair" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) existing_pairs[2].should_receive(:destroy) existing_pairs[3].should_receive(:destroy) existing_pairs[4].should_receive(:destroy) existing_pairs[5].should_receive(:destroy) pair_repository.stub!(:create) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end end end def create_test_availabilities(ids) availabilities = [] ids.each do |id| availability = Availability.new availability.id = id availabilities.push availability end availabilities end
adiel/availabletopair
31555009e14ba83dab0d20d5d6de97e60dfe5d50
Refactoring
diff --git a/app/models/pair_matcher.rb b/app/models/pair_matcher.rb index c579af3..960e8f6 100644 --- a/app/models/pair_matcher.rb +++ b/app/models/pair_matcher.rb @@ -1,18 +1,19 @@ class PairMatcher def find_pairs(availability) conditions = "developer != :developer and start_time < :end_time and end_time > :start_time" condition_values = {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time} - if availability.project.to_s != "" - conditions += " and (project = :project or project = '')" + + if !availability.project.blank? + conditions += " and (project = :project or project is null)" condition_values[:project] = availability.project end pair_conditions = [conditions, condition_values] - pairs = Availability.find(:all, :conditions => pair_conditions) + Availability.find(:all, :conditions => pair_conditions) end end \ No newline at end of file diff --git a/app/models/pair_repository.rb b/app/models/pair_repository.rb index 48cb922..d498638 100644 --- a/app/models/pair_repository.rb +++ b/app/models/pair_repository.rb @@ -1,28 +1,32 @@ class PairRepository + private + def latest_start_time (master_availability, pair_availability) pair_availability.start_time > master_availability.start_time ? pair_availability.start_time : master_availability.start_time end def earliest_end_time (master_availability, pair_availability) pair_availability.end_time < master_availability.end_time ? pair_availability.end_time : master_availability.end_time end + public + def create(master_availability,pair_availability) pair = Pair.new update(pair,master_availability,pair_availability) end def update(pair,master_availability,pair_availability) pair.availability_id = master_availability.id pair.available_pair_id = pair_availability.id pair.developer = pair_availability.developer pair.contact = pair_availability.contact pair.project = master_availability.project || pair_availability.project pair.start_time = latest_start_time(master_availability, pair_availability) pair.end_time = earliest_end_time(master_availability, pair_availability) pair.save pair end end diff --git a/app/models/pair_synchronizer.rb b/app/models/pair_synchronizer.rb index e815343..8d6cfc0 100644 --- a/app/models/pair_synchronizer.rb +++ b/app/models/pair_synchronizer.rb @@ -1,53 +1,65 @@ class PairSynchronizer def initialize(pair_matcher = nil, pair_repository = nil) @pair_matcher = pair_matcher || PairMatcher.new @pair_repository = pair_repository || PairRepository.new end + private + def save_or_update (existing, master_availability, pair_availability) if existing.nil? @pair_repository.create(master_availability, pair_availability) else @pair_repository.update(existing, master_availability, pair_availability) end end def save_or_update_master(existing_pairs, availability, new_matching_availability) - existing_master = existing_pairs.find do |p| - p.available_pair_id == new_matching_availability.id + existing_master = existing_pairs.find do |pair| + pair.available_pair_id == new_matching_availability.id end save_or_update(existing_master, availability, new_matching_availability) end def save_or_update_pair (existing_pairs, availability, new_matching_availability) - existing_pair = existing_pairs.find do |p| - p.availability_id == new_matching_availability.id + existing_pair = existing_pairs.find do |pair| + pair.availability_id == new_matching_availability.id end save_or_update(existing_pair, new_matching_availability, availability) end - def synchronize_pairs(availability) + def find_existing_pairs(availability) conditions_clause = "availability_id = :availability_id or available_pair_id = :available_pair_id" - conditions_params = {:availability_id => availability.id,:available_pair_id => availability.id} + conditions_params = {:availability_id => availability.id, :available_pair_id => availability.id} - existing_pairs = Pair.find(:all,:conditions => [conditions_clause,conditions_params]) - new_matching_availabilities = @pair_matcher.find_pairs(availability) + existing_pairs = Pair.find(:all, :conditions => [conditions_clause, conditions_params]) + return existing_pairs + end + def save_or_update_existing_pairs(availability, existing_pairs, new_matching_availabilities) new_matching_availabilities.each do |new_matching_availability| save_or_update_master(existing_pairs, availability, new_matching_availability) save_or_update_pair(existing_pairs, availability, new_matching_availability) end + end + def destroy_obsolete_pairs(existing_pairs, new_matching_availabilities) existing_pairs.each do |existing| - match = new_matching_availabilities.find {|new_matching_availability| - new_matching_availability.id == existing.availability_id || - new_matching_availability.id == existing.available_pair_id - } + match = new_matching_availabilities.find {|a| a.id == existing.availability_id || a.id == existing.available_pair_id} existing.destroy if match.nil? end + end + + public + + def synchronize_pairs(availability) + existing_pairs = find_existing_pairs(availability) + new_matching_availabilities = @pair_matcher.find_pairs(availability) + save_or_update_existing_pairs(availability, existing_pairs, new_matching_availabilities) + destroy_obsolete_pairs(existing_pairs, new_matching_availabilities) end end diff --git a/db/schema.rb b/db/schema.rb index 189d2d2..e96cfd0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,56 +1,56 @@ # This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 20091023233000) do create_table "availabilities", :force => true do |t| t.string "developer" t.datetime "start_time" t.datetime "end_time" t.string "contact" t.datetime "created_at" t.datetime "updated_at" t.string "project" end add_index "availabilities", ["developer", "start_time", "end_time"], :name => "availabilities_pair_search_index" add_index "availabilities", ["developer"], :name => "availabilities_name_index" create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" t.string "handle" t.string "assoc_type" t.binary "server_url" t.binary "secret" end create_table "open_id_authentication_nonces", :force => true do |t| t.integer "timestamp", :null => false t.string "server_url" t.string "salt", :null => false end - create_table "pairs", :force => true do |t| + create_table "pairing", :force => true do |t| t.integer "availability_id" t.integer "available_pair_id" t.datetime "created_at" t.datetime "updated_at" t.string "developer" t.string "project" t.datetime "start_time" t.datetime "end_time" t.string "contact" end - add_index "pairs", ["availability_id"], :name => "pairs_availability_id_index" + add_index "pairing", ["availability_id"], :name => "pairs_availability_id_index" end diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index 0ea6f9a..a8da2cd 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,52 +1,52 @@ Given /^no availabilities in the system$/ do Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| Availability.create(:developer => row[0], :project => row[1], :start_time => row[2], :end_time => row[3], :contact => row[4]) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf', :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf',:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end Then /^I should see the following availabilites listed in order$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end -Then /^I should see the following matching pairs$/ do |table| +Then /^I should see the following matching pairing$/ do |table| table.rows.each_with_index do |row,index| - row_selector = ".pairs tr:nth-child(#{index + 2})" + row_selector = ".pairing tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index 9cab97a..415a05b 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,60 +1,60 @@ require 'spec_helper' describe Availability do describe "when the start and end time are within the same day" do it "should calculate the duration as the difference between the end and start times in seconds" do start_time = Time.parse("2009-11-15 09:00") end_time = Time.parse("2009-11-15 17:35") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when the start and end time cross two days" do it "should calculate the duration as the difference between the end and start times" do start_time = Time.parse("2009-11-15 22:00") end_time = Time.parse("2009-11-15 00:15") duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec duration_sec.should eql(end_time - start_time) end end describe "when saving" do - it "should sync pairs" do + it "should sync pairing" do availability = Availability.new pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:synchronize_pairs).with(availability) availability.pair_synchronizer = pair_synchronizer availability.save end end describe "when destroying" do - it "should sync pairs" do + it "should sync pairing" do availability = Availability.new pair_synchronizer = mock(:pair_synchronizer) pair_synchronizer.should_receive(:synchronize_pairs).with(availability) availability.pair_synchronizer = pair_synchronizer availability.destroy end end end diff --git a/spec/models/pair_matcher_spec.rb b/spec/models/pair_matcher_spec.rb index 51af0f5..a744976 100644 --- a/spec/models/pair_matcher_spec.rb +++ b/spec/models/pair_matcher_spec.rb @@ -1,41 +1,41 @@ require 'spec_helper' describe PairMatcher do - it "should find pairs as matching availabilities for different developers where times overlap" do + it "should find pairing as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end describe "when a project has been specified" do - it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do + it "should find pairing as matching availabilities for different developers on the same project or anything where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" availability.project = "some proj" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time, :project => availability.project}]).and_return(expected_pairs) actual_pairs = PairMatcher.new.find_pairs(availability) actual_pairs.should be(expected_pairs) end end end diff --git a/spec/models/pair_synchronizer_spec.rb b/spec/models/pair_synchronizer_spec.rb index 29b3005..7a7983f 100644 --- a/spec/models/pair_synchronizer_spec.rb +++ b/spec/models/pair_synchronizer_spec.rb @@ -1,144 +1,144 @@ require 'spec_helper' describe PairSynchronizer do - describe "when syncing pairs" do + describe "when syncing pairing" do describe "when there is a single new availability" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return([]) end - it "should create two pairs for the new match, one in each direction" do + it "should create two pairing for the new match, one in each direction" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[0]) pair_repository.should_receive(:create).with(matching_availabilities[0],availability) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there some existing and some new availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5,6,7,8]) existing_pairs = [stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[0].id), stub(:availability_id => matching_availabilities[0].id, :available_pair_id => availability.id), stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[2].id), stub(:availability_id => matching_availabilities[2].id, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end it "should create any matching pair that doesn't exist" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:create).with(availability,matching_availabilities[1]) pair_repository.should_receive(:create).with(matching_availabilities[1],availability) pair_repository.should_receive(:create).with(availability,matching_availabilities[3]) pair_repository.should_receive(:create).with(matching_availabilities[3],availability) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end it "should update the existing availabilities" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) pair_repository.should_receive(:update).with(existing_pairs[0],availability,matching_availabilities[0]) pair_repository.should_receive(:update).with(existing_pairs[1],matching_availabilities[0],availability) pair_repository.should_receive(:update).with(existing_pairs[2],availability,matching_availabilities[2]) pair_repository.should_receive(:update).with(existing_pairs[3],matching_availabilities[2],availability) pair_repository.stub!(:create) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end describe "when there are missing availabilities" do availability = Availability.new matching_availabilities = [] existing_pairs = [] before do availability.id = 321 matching_availabilities = create_test_availabilities([5]) existing_pairs = [mock(:id => 99, :availability_id => availability.id, :available_pair_id => 5), mock(:id => 98, :availability_id => 5, :available_pair_id => availability.id), mock(:id => 97,:availability_id => availability.id, :available_pair_id => 102), mock(:id => 96,:availability_id => 102, :available_pair_id => availability.id), mock(:id => 95,:availability_id => availability.id, :available_pair_id => 103), mock(:id => 94,:availability_id => 103, :available_pair_id => availability.id)] Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) end - it "should destroy the missing pairs" do + it "should destroy the missing pairing" do pair_matcher = mock(:pair_matcher) pair_repository = mock(:pair_matcher) pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) existing_pairs[2].should_receive(:destroy) existing_pairs[3].should_receive(:destroy) existing_pairs[4].should_receive(:destroy) existing_pairs[5].should_receive(:destroy) pair_repository.stub!(:create) pair_repository.stub!(:update) PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) end end end end def create_test_availabilities(ids) availabilities = [] ids.each do |id| availability = Availability.new availability.id = id availabilities.push availability end availabilities end
adiel/availabletopair
a3af63091f2dc3b772951b53026635036d4daee9
Removed model validation on contact
diff --git a/app/models/availability.rb b/app/models/availability.rb index 601d53c..191a2d9 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,28 +1,28 @@ class Availability < ActiveRecord::Base - validates_presence_of :developer, :contact, :start_time, :end_time + validates_presence_of :developer, :start_time, :end_time has_many :pairs strip_attributes! def pair_synchronizer @pair_synchronizer ||= PairSynchronizer.new end def pair_synchronizer=(pair_synchronizer) @pair_synchronizer = pair_synchronizer end def save super() pair_synchronizer.synchronize_pairs(self) end def destroy super() pair_synchronizer.synchronize_pairs(self) end def duration_sec end_time - start_time end end
adiel/availabletopair
87b46fd5e6962e0945027121d9f001801b78582c
User atom feed updates when an available pair changes. Now calculating pairs when changes are made. (Didn't add vendor dir)
diff --git a/vendor/plugins/open_id_authentication/CHANGELOG b/vendor/plugins/open_id_authentication/CHANGELOG new file mode 100644 index 0000000..7349bd3 --- /dev/null +++ b/vendor/plugins/open_id_authentication/CHANGELOG @@ -0,0 +1,35 @@ +* Fake HTTP method from OpenID server since they only support a GET. Eliminates the need to set an extra route to match the server's reply. [Josh Peek] + +* OpenID 2.0 recommends that forms should use the field name "openid_identifier" rather than "openid_url" [Josh Peek] + +* Return open_id_response.display_identifier to the application instead of .endpoints.claimed_id. [nbibler] + +* Add Timeout protection [Rick] + +* An invalid identity url passed through authenticate_with_open_id will no longer raise an InvalidOpenId exception. Instead it will return Result[:missing] to the completion block. + +* Allow a return_to option to be used instead of the requested url [Josh Peek] + +* Updated plugin to use Ruby OpenID 2.x.x [Josh Peek] + +* Tied plugin to ruby-openid 1.1.4 gem until we can make it compatible with 2.x [DHH] + +* Use URI instead of regexps to normalize the URL and gain free, better matching #8136 [dkubb] + +* Allow -'s in #normalize_url [Rick] + +* remove instance of mattr_accessor, it was breaking tests since they don't load ActiveSupport. Fix Timeout test [Rick] + +* Throw a InvalidOpenId exception instead of just a RuntimeError when the URL can't be normalized [DHH] + +* Just use the path for the return URL, so extra query parameters don't interfere [DHH] + +* Added a new default database-backed store after experiencing trouble with the filestore on NFS. The file store is still available as an option [DHH] + +* Added normalize_url and applied it to all operations going through the plugin [DHH] + +* Removed open_id? as the idea of using the same input box for both OpenID and username has died -- use using_open_id? instead (which checks for the presence of params[:openid_url] by default) [DHH] + +* Added OpenIdAuthentication::Result to make it easier to deal with default situations where you don't care to do something particular for each error state [DHH] + +* Stop relying on root_url being defined, we can just grab the current url instead [DHH] \ No newline at end of file diff --git a/vendor/plugins/open_id_authentication/README b/vendor/plugins/open_id_authentication/README new file mode 100644 index 0000000..807cdc7 --- /dev/null +++ b/vendor/plugins/open_id_authentication/README @@ -0,0 +1,231 @@ +OpenIdAuthentication +==================== + +Provides a thin wrapper around the excellent ruby-openid gem from JanRan. Be sure to install that first: + + gem install ruby-openid + +To understand what OpenID is about and how it works, it helps to read the documentation for lib/openid/consumer.rb +from that gem. + +The specification used is http://openid.net/specs/openid-authentication-2_0.html. + + +Prerequisites +============= + +OpenID authentication uses the session, so be sure that you haven't turned that off. It also relies on a number of +database tables to store the authentication keys. So you'll have to run the migration to create these before you get started: + + rake open_id_authentication:db:create + +Or, use the included generators to install or upgrade: + + ./script/generate open_id_authentication_tables MigrationName + ./script/generate upgrade_open_id_authentication_tables MigrationName + +Alternatively, you can use the file-based store, which just relies on on tmp/openids being present in RAILS_ROOT. But be aware that this store only works if you have a single application server. And it's not safe to use across NFS. It's recommended that you use the database store if at all possible. To use the file-based store, you'll also have to add this line to your config/environment.rb: + + OpenIdAuthentication.store = :file + +This particular plugin also relies on the fact that the authentication action allows for both POST and GET operations. +If you're using RESTful authentication, you'll need to explicitly allow for this in your routes.rb. + +The plugin also expects to find a root_url method that points to the home page of your site. You can accomplish this by using a root route in config/routes.rb: + + map.root :controller => 'articles' + +This plugin relies on Rails Edge revision 6317 or newer. + + +Example +======= + +This example is just to meant to demonstrate how you could use OpenID authentication. You might well want to add +salted hash logins instead of plain text passwords and other requirements on top of this. Treat it as a starting point, +not a destination. + +Note that the User model referenced in the simple example below has an 'identity_url' attribute. You will want to add the same or similar field to whatever +model you are using for authentication. + +Also of note is the following code block used in the example below: + + authenticate_with_open_id do |result, identity_url| + ... + end + +In the above code block, 'identity_url' will need to match user.identity_url exactly. 'identity_url' will be a string in the form of 'http://example.com' - +If you are storing just 'example.com' with your user, the lookup will fail. + +There is a handy method in this plugin called 'normalize_url' that will help with validating OpenID URLs. + + OpenIdAuthentication.normalize_url(user.identity_url) + +The above will return a standardized version of the OpenID URL - the above called with 'example.com' will return 'http://example.com/' +It will also raise an InvalidOpenId exception if the URL is determined to not be valid. +Use the above code in your User model and validate OpenID URLs before saving them. + +config/routes.rb + + map.root :controller => 'articles' + map.resource :session + + +app/views/sessions/new.erb + + <% form_tag(session_url) do %> + <p> + <label for="name">Username:</label> + <%= text_field_tag "name" %> + </p> + + <p> + <label for="password">Password:</label> + <%= password_field_tag %> + </p> + + <p> + ...or use: + </p> + + <p> + <label for="openid_identifier">OpenID:</label> + <%= text_field_tag "openid_identifier" %> + </p> + + <p> + <%= submit_tag 'Sign in', :disable_with => "Signing in&hellip;" %> + </p> + <% end %> + +app/controllers/sessions_controller.rb + class SessionsController < ApplicationController + def create + if using_open_id? + open_id_authentication + else + password_authentication(params[:name], params[:password]) + end + end + + + protected + def password_authentication(name, password) + if @current_user = @account.users.authenticate(params[:name], params[:password]) + successful_login + else + failed_login "Sorry, that username/password doesn't work" + end + end + + def open_id_authentication + authenticate_with_open_id do |result, identity_url| + if result.successful? + if @current_user = @account.users.find_by_identity_url(identity_url) + successful_login + else + failed_login "Sorry, no user by that identity URL exists (#{identity_url})" + end + else + failed_login result.message + end + end + end + + + private + def successful_login + session[:user_id] = @current_user.id + redirect_to(root_url) + end + + def failed_login(message) + flash[:error] = message + redirect_to(new_session_url) + end + end + + + +If you're fine with the result messages above and don't need individual logic on a per-failure basis, +you can collapse the case into a mere boolean: + + def open_id_authentication + authenticate_with_open_id do |result, identity_url| + if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url) + successful_login + else + failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})") + end + end + end + + +Simple Registration OpenID Extension +==================================== + +Some OpenID Providers support this lightweight profile exchange protocol. See more: http://www.openidenabled.com/openid/simple-registration-extension + +You can support it in your app by changing #open_id_authentication + + def open_id_authentication(identity_url) + # Pass optional :required and :optional keys to specify what sreg fields you want. + # Be sure to yield registration, a third argument in the #authenticate_with_open_id block. + authenticate_with_open_id(identity_url, + :required => [ :nickname, :email ], + :optional => :fullname) do |result, identity_url, registration| + case result.status + when :missing + failed_login "Sorry, the OpenID server couldn't be found" + when :invalid + failed_login "Sorry, but this does not appear to be a valid OpenID" + when :canceled + failed_login "OpenID verification was canceled" + when :failed + failed_login "Sorry, the OpenID verification failed" + when :successful + if @current_user = @account.users.find_by_identity_url(identity_url) + assign_registration_attributes!(registration) + + if current_user.save + successful_login + else + failed_login "Your OpenID profile registration failed: " + + @current_user.errors.full_messages.to_sentence + end + else + failed_login "Sorry, no user by that identity URL exists" + end + end + end + end + + # registration is a hash containing the valid sreg keys given above + # use this to map them to fields of your user model + def assign_registration_attributes!(registration) + model_to_registration_mapping.each do |model_attribute, registration_attribute| + unless registration[registration_attribute].blank? + @current_user.send("#{model_attribute}=", registration[registration_attribute]) + end + end + end + + def model_to_registration_mapping + { :login => 'nickname', :email => 'email', :display_name => 'fullname' } + end + +Attribute Exchange OpenID Extension +=================================== + +Some OpenID providers also support the OpenID AX (attribute exchange) protocol for exchanging identity information between endpoints. See more: http://openid.net/specs/openid-attribute-exchange-1_0.html + +Accessing AX data is very similar to the Simple Registration process, described above -- just add the URI identifier for the AX field to your :optional or :required parameters. For example: + + authenticate_with_open_id(identity_url, + :required => [ :email, 'http://schema.openid.net/birthDate' ]) do |result, identity_url, registration| + +This would provide the sreg data for :email, and the AX data for 'http://schema.openid.net/birthDate' + + + +Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license \ No newline at end of file diff --git a/vendor/plugins/open_id_authentication/Rakefile b/vendor/plugins/open_id_authentication/Rakefile new file mode 100644 index 0000000..31074b8 --- /dev/null +++ b/vendor/plugins/open_id_authentication/Rakefile @@ -0,0 +1,22 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the open_id_authentication plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the open_id_authentication plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'OpenIdAuthentication' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb b/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb new file mode 100644 index 0000000..6f78afc --- /dev/null +++ b/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb @@ -0,0 +1,11 @@ +class OpenIdAuthenticationTablesGenerator < Rails::Generator::NamedBase + def initialize(runtime_args, runtime_options = {}) + super + end + + def manifest + record do |m| + m.migration_template 'migration.rb', 'db/migrate' + end + end +end diff --git a/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/templates/migration.rb b/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/templates/migration.rb new file mode 100644 index 0000000..ef2a0cf --- /dev/null +++ b/vendor/plugins/open_id_authentication/generators/open_id_authentication_tables/templates/migration.rb @@ -0,0 +1,20 @@ +class <%= class_name %> < ActiveRecord::Migration + def self.up + create_table :open_id_authentication_associations, :force => true do |t| + t.integer :issued, :lifetime + t.string :handle, :assoc_type + t.binary :server_url, :secret + end + + create_table :open_id_authentication_nonces, :force => true do |t| + t.integer :timestamp, :null => false + t.string :server_url, :null => true + t.string :salt, :null => false + end + end + + def self.down + drop_table :open_id_authentication_associations + drop_table :open_id_authentication_nonces + end +end diff --git a/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/templates/migration.rb b/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/templates/migration.rb new file mode 100644 index 0000000..d13bbab --- /dev/null +++ b/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/templates/migration.rb @@ -0,0 +1,26 @@ +class <%= class_name %> < ActiveRecord::Migration + def self.up + drop_table :open_id_authentication_settings + drop_table :open_id_authentication_nonces + + create_table :open_id_authentication_nonces, :force => true do |t| + t.integer :timestamp, :null => false + t.string :server_url, :null => true + t.string :salt, :null => false + end + end + + def self.down + drop_table :open_id_authentication_nonces + + create_table :open_id_authentication_nonces, :force => true do |t| + t.integer :created + t.string :nonce + end + + create_table :open_id_authentication_settings, :force => true do |t| + t.string :setting + t.binary :value + end + end +end diff --git a/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/upgrade_open_id_authentication_tables_generator.rb b/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/upgrade_open_id_authentication_tables_generator.rb new file mode 100644 index 0000000..02fddd7 --- /dev/null +++ b/vendor/plugins/open_id_authentication/generators/upgrade_open_id_authentication_tables/upgrade_open_id_authentication_tables_generator.rb @@ -0,0 +1,11 @@ +class UpgradeOpenIdAuthenticationTablesGenerator < Rails::Generator::NamedBase + def initialize(runtime_args, runtime_options = {}) + super + end + + def manifest + record do |m| + m.migration_template 'migration.rb', 'db/migrate' + end + end +end diff --git a/vendor/plugins/open_id_authentication/init.rb b/vendor/plugins/open_id_authentication/init.rb new file mode 100644 index 0000000..808c7bd --- /dev/null +++ b/vendor/plugins/open_id_authentication/init.rb @@ -0,0 +1,18 @@ +if config.respond_to?(:gems) + config.gem 'ruby-openid', :lib => 'openid', :version => '>=2.0.4' +else + begin + require 'openid' + rescue LoadError + begin + gem 'ruby-openid', '>=2.0.4' + rescue Gem::LoadError + puts "Install the ruby-openid gem to enable OpenID support" + end + end +end + +config.to_prepare do + OpenID::Util.logger = Rails.logger + ActionController::Base.send :include, OpenIdAuthentication +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb new file mode 100644 index 0000000..b485c5f --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication.rb @@ -0,0 +1,240 @@ +require 'uri' +require 'openid/extensions/sreg' +require 'openid/extensions/ax' +require 'openid/store/filesystem' + +require File.dirname(__FILE__) + '/open_id_authentication/association' +require File.dirname(__FILE__) + '/open_id_authentication/nonce' +require File.dirname(__FILE__) + '/open_id_authentication/db_store' +require File.dirname(__FILE__) + '/open_id_authentication/request' +require File.dirname(__FILE__) + '/open_id_authentication/timeout_fixes' if OpenID::VERSION == "2.0.4" + +module OpenIdAuthentication + OPEN_ID_AUTHENTICATION_DIR = RAILS_ROOT + "/tmp/openids" + + def self.store + @@store + end + + def self.store=(*store_option) + store, *parameters = *([ store_option ].flatten) + + @@store = case store + when :db + OpenIdAuthentication::DbStore.new + when :file + OpenID::Store::Filesystem.new(OPEN_ID_AUTHENTICATION_DIR) + else + store + end + end + + self.store = :db + + class InvalidOpenId < StandardError + end + + class Result + ERROR_MESSAGES = { + :missing => "Sorry, the OpenID server couldn't be found", + :invalid => "Sorry, but this does not appear to be a valid OpenID", + :canceled => "OpenID verification was canceled", + :failed => "OpenID verification failed", + :setup_needed => "OpenID verification needs setup" + } + + def self.[](code) + new(code) + end + + def initialize(code) + @code = code + end + + def status + @code + end + + ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } } + + def successful? + @code == :successful + end + + def unsuccessful? + ERROR_MESSAGES.keys.include?(@code) + end + + def message + ERROR_MESSAGES[@code] + end + end + + # normalizes an OpenID according to http://openid.net/specs/openid-authentication-2_0.html#normalization + def self.normalize_identifier(identifier) + # clean up whitespace + identifier = identifier.to_s.strip + + # if an XRI has a prefix, strip it. + identifier.gsub!(/xri:\/\//i, '') + + # dodge XRIs -- TODO: validate, don't just skip. + unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0)) + # does it begin with http? if not, add it. + identifier = "http://#{identifier}" unless identifier =~ /^http/i + + # strip any fragments + identifier.gsub!(/\#(.*)$/, '') + + begin + uri = URI.parse(identifier) + uri.scheme = uri.scheme.downcase # URI should do this + identifier = uri.normalize.to_s + rescue URI::InvalidURIError + raise InvalidOpenId.new("#{identifier} is not an OpenID identifier") + end + end + + return identifier + end + + # deprecated for OpenID 2.0, where not all OpenIDs are URLs + def self.normalize_url(url) + ActiveSupport::Deprecation.warn "normalize_url has been deprecated, use normalize_identifier instead" + self.normalize_identifier(url) + end + + protected + def normalize_url(url) + OpenIdAuthentication.normalize_url(url) + end + + def normalize_identifier(url) + OpenIdAuthentication.normalize_identifier(url) + end + + # The parameter name of "openid_identifier" is used rather than the Rails convention "open_id_identifier" + # because that's what the specification dictates in order to get browser auto-complete working across sites + def using_open_id?(identity_url = nil) #:doc: + identity_url ||= params[:openid_identifier] || params[:openid_url] + !identity_url.blank? || params[:open_id_complete] + end + + def authenticate_with_open_id(identity_url = nil, options = {}, &block) #:doc: + identity_url ||= params[:openid_identifier] || params[:openid_url] + + if params[:open_id_complete].nil? + begin_open_id_authentication(identity_url, options, &block) + else + complete_open_id_authentication(&block) + end + end + + private + def begin_open_id_authentication(identity_url, options = {}) + identity_url = normalize_identifier(identity_url) + return_to = options.delete(:return_to) + method = options.delete(:method) + + options[:required] ||= [] # reduces validation later + options[:optional] ||= [] + + open_id_request = open_id_consumer.begin(identity_url) + add_simple_registration_fields(open_id_request, options) + add_ax_fields(open_id_request, options) + redirect_to(open_id_redirect_url(open_id_request, return_to, method)) + rescue OpenIdAuthentication::InvalidOpenId => e + yield Result[:invalid], identity_url, nil + rescue OpenID::OpenIDError, Timeout::Error => e + logger.error("[OPENID] #{e}") + yield Result[:missing], identity_url, nil + end + + def complete_open_id_authentication + params_with_path = params.reject { |key, value| request.path_parameters[key] } + params_with_path.delete(:format) + open_id_response = timeout_protection_from_identity_server { open_id_consumer.complete(params_with_path, requested_url) } + identity_url = normalize_identifier(open_id_response.display_identifier) if open_id_response.display_identifier + + case open_id_response.status + when OpenID::Consumer::SUCCESS + profile_data = {} + + # merge the SReg data and the AX data into a single hash of profile data + [ OpenID::SReg::Response, OpenID::AX::FetchResponse ].each do |data_response| + if data_response.from_success_response( open_id_response ) + profile_data.merge! data_response.from_success_response( open_id_response ).data + end + end + + yield Result[:successful], identity_url, profile_data + when OpenID::Consumer::CANCEL + yield Result[:canceled], identity_url, nil + when OpenID::Consumer::FAILURE + yield Result[:failed], identity_url, nil + when OpenID::Consumer::SETUP_NEEDED + yield Result[:setup_needed], open_id_response.setup_url, nil + end + end + + def open_id_consumer + OpenID::Consumer.new(session, OpenIdAuthentication.store) + end + + def add_simple_registration_fields(open_id_request, fields) + sreg_request = OpenID::SReg::Request.new + + # filter out AX identifiers (URIs) + required_fields = fields[:required].collect { |f| f.to_s unless f =~ /^https?:\/\// }.compact + optional_fields = fields[:optional].collect { |f| f.to_s unless f =~ /^https?:\/\// }.compact + + sreg_request.request_fields(required_fields, true) unless required_fields.blank? + sreg_request.request_fields(optional_fields, false) unless optional_fields.blank? + sreg_request.policy_url = fields[:policy_url] if fields[:policy_url] + open_id_request.add_extension(sreg_request) + end + + def add_ax_fields( open_id_request, fields ) + ax_request = OpenID::AX::FetchRequest.new + + # look through the :required and :optional fields for URIs (AX identifiers) + fields[:required].each do |f| + next unless f =~ /^https?:\/\// + ax_request.add( OpenID::AX::AttrInfo.new( f, nil, true ) ) + end + + fields[:optional].each do |f| + next unless f =~ /^https?:\/\// + ax_request.add( OpenID::AX::AttrInfo.new( f, nil, false ) ) + end + + open_id_request.add_extension( ax_request ) + end + + def open_id_redirect_url(open_id_request, return_to = nil, method = nil) + open_id_request.return_to_args['_method'] = (method || request.method).to_s + open_id_request.return_to_args['open_id_complete'] = '1' + open_id_request.redirect_url(root_url, return_to || requested_url) + end + + def requested_url + relative_url_root = self.class.respond_to?(:relative_url_root) ? + self.class.relative_url_root.to_s : + request.relative_url_root + "#{request.protocol}#{request.host_with_port}#{ActionController::Base.relative_url_root}#{request.path}" + end + + def timeout_protection_from_identity_server + yield + rescue Timeout::Error + Class.new do + def status + OpenID::FAILURE + end + + def msg + "Identity server timed out" + end + end.new + end +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication/association.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication/association.rb new file mode 100644 index 0000000..9654eae --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication/association.rb @@ -0,0 +1,9 @@ +module OpenIdAuthentication + class Association < ActiveRecord::Base + set_table_name :open_id_authentication_associations + + def from_record + OpenID::Association.new(handle, secret, issued, lifetime, assoc_type) + end + end +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication/db_store.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication/db_store.rb new file mode 100644 index 0000000..780fb6a --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication/db_store.rb @@ -0,0 +1,55 @@ +require 'openid/store/interface' + +module OpenIdAuthentication + class DbStore < OpenID::Store::Interface + def self.cleanup_nonces + now = Time.now.to_i + Nonce.delete_all(["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew]) + end + + def self.cleanup_associations + now = Time.now.to_i + Association.delete_all(['issued + lifetime > ?',now]) + end + + def store_association(server_url, assoc) + remove_association(server_url, assoc.handle) + Association.create(:server_url => server_url, + :handle => assoc.handle, + :secret => assoc.secret, + :issued => assoc.issued, + :lifetime => assoc.lifetime, + :assoc_type => assoc.assoc_type) + end + + def get_association(server_url, handle = nil) + assocs = if handle.blank? + Association.find_all_by_server_url(server_url) + else + Association.find_all_by_server_url_and_handle(server_url, handle) + end + + assocs.reverse.each do |assoc| + a = assoc.from_record + if a.expires_in == 0 + assoc.destroy + else + return a + end + end if assocs.any? + + return nil + end + + def remove_association(server_url, handle) + Association.delete_all(['server_url = ? AND handle = ?', server_url, handle]) > 0 + end + + def use_nonce(server_url, timestamp, salt) + return false if Nonce.find_by_server_url_and_timestamp_and_salt(server_url, timestamp, salt) + return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew + Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt) + return true + end + end +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication/nonce.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication/nonce.rb new file mode 100644 index 0000000..c52f6c5 --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication/nonce.rb @@ -0,0 +1,5 @@ +module OpenIdAuthentication + class Nonce < ActiveRecord::Base + set_table_name :open_id_authentication_nonces + end +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication/request.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication/request.rb new file mode 100644 index 0000000..e0cc8e3 --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication/request.rb @@ -0,0 +1,23 @@ +module OpenIdAuthentication + module Request + def self.included(base) + base.alias_method_chain :request_method, :openid + end + + def request_method_with_openid + if !parameters[:_method].blank? && parameters[:open_id_complete] == '1' + parameters[:_method].to_sym + else + request_method_without_openid + end + end + end +end + +# In Rails 2.3, the request object has been renamed +# from AbstractRequest to Request +if defined? ActionController::Request + ActionController::Request.send :include, OpenIdAuthentication::Request +else + ActionController::AbstractRequest.send :include, OpenIdAuthentication::Request +end diff --git a/vendor/plugins/open_id_authentication/lib/open_id_authentication/timeout_fixes.rb b/vendor/plugins/open_id_authentication/lib/open_id_authentication/timeout_fixes.rb new file mode 100644 index 0000000..cc711c9 --- /dev/null +++ b/vendor/plugins/open_id_authentication/lib/open_id_authentication/timeout_fixes.rb @@ -0,0 +1,20 @@ +# http://trac.openidenabled.com/trac/ticket/156 +module OpenID + @@timeout_threshold = 20 + + def self.timeout_threshold + @@timeout_threshold + end + + def self.timeout_threshold=(value) + @@timeout_threshold = value + end + + class StandardFetcher + def make_http(uri) + http = @proxy.new(uri.host, uri.port) + http.read_timeout = http.open_timeout = OpenID.timeout_threshold + http + end + end +end \ No newline at end of file diff --git a/vendor/plugins/open_id_authentication/tasks/open_id_authentication_tasks.rake b/vendor/plugins/open_id_authentication/tasks/open_id_authentication_tasks.rake new file mode 100644 index 0000000..c71434a --- /dev/null +++ b/vendor/plugins/open_id_authentication/tasks/open_id_authentication_tasks.rake @@ -0,0 +1,30 @@ +namespace :open_id_authentication do + namespace :db do + desc "Creates authentication tables for use with OpenIdAuthentication" + task :create => :environment do + generate_migration(["open_id_authentication_tables", "add_open_id_authentication_tables"]) + end + + desc "Upgrade authentication tables from ruby-openid 1.x.x to 2.x.x" + task :upgrade => :environment do + generate_migration(["upgrade_open_id_authentication_tables", "upgrade_open_id_authentication_tables"]) + end + + def generate_migration(args) + require 'rails_generator' + require 'rails_generator/scripts/generate' + + if ActiveRecord::Base.connection.supports_migrations? + Rails::Generator::Scripts::Generate.new.run(args) + else + raise "Task unavailable to this database (no migration support)" + end + end + + desc "Clear the authentication tables" + task :clear => :environment do + OpenIdAuthentication::DbStore.cleanup_nonces + OpenIdAuthentication::DbStore.cleanup_associations + end + end +end diff --git a/vendor/plugins/open_id_authentication/test/normalize_test.rb b/vendor/plugins/open_id_authentication/test/normalize_test.rb new file mode 100644 index 0000000..635d3ab --- /dev/null +++ b/vendor/plugins/open_id_authentication/test/normalize_test.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/test_helper' + +class NormalizeTest < Test::Unit::TestCase + include OpenIdAuthentication + + NORMALIZATIONS = { + "openid.aol.com/nextangler" => "http://openid.aol.com/nextangler", + "http://openid.aol.com/nextangler" => "http://openid.aol.com/nextangler", + "https://openid.aol.com/nextangler" => "https://openid.aol.com/nextangler", + "HTTP://OPENID.AOL.COM/NEXTANGLER" => "http://openid.aol.com/NEXTANGLER", + "HTTPS://OPENID.AOL.COM/NEXTANGLER" => "https://openid.aol.com/NEXTANGLER", + "loudthinking.com" => "http://loudthinking.com/", + "http://loudthinking.com" => "http://loudthinking.com/", + "http://loudthinking.com:80" => "http://loudthinking.com/", + "https://loudthinking.com:443" => "https://loudthinking.com/", + "http://loudthinking.com:8080" => "http://loudthinking.com:8080/", + "techno-weenie.net" => "http://techno-weenie.net/", + "http://techno-weenie.net" => "http://techno-weenie.net/", + "http://techno-weenie.net " => "http://techno-weenie.net/", + "=name" => "=name" + } + + def test_normalizations + NORMALIZATIONS.each do |from, to| + assert_equal to, normalize_identifier(from) + end + end + + def test_broken_open_id + assert_raises(InvalidOpenId) { normalize_identifier(nil) } + end +end diff --git a/vendor/plugins/open_id_authentication/test/open_id_authentication_test.rb b/vendor/plugins/open_id_authentication/test/open_id_authentication_test.rb new file mode 100644 index 0000000..ddcc17b --- /dev/null +++ b/vendor/plugins/open_id_authentication/test/open_id_authentication_test.rb @@ -0,0 +1,46 @@ +require File.dirname(__FILE__) + '/test_helper' + +class OpenIdAuthenticationTest < Test::Unit::TestCase + def setup + @controller = Class.new do + include OpenIdAuthentication + def params() {} end + end.new + end + + def test_authentication_should_fail_when_the_identity_server_is_missing + open_id_consumer = mock() + open_id_consumer.expects(:begin).raises(OpenID::OpenIDError) + @controller.expects(:open_id_consumer).returns(open_id_consumer) + @controller.expects(:logger).returns(mock(:error => true)) + + @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url| + assert result.missing? + assert_equal "Sorry, the OpenID server couldn't be found", result.message + end + end + + def test_authentication_should_be_invalid_when_the_identity_url_is_invalid + @controller.send(:authenticate_with_open_id, "!") do |result, identity_url| + assert result.invalid?, "Result expected to be invalid but was not" + assert_equal "Sorry, but this does not appear to be a valid OpenID", result.message + end + end + + def test_authentication_should_fail_when_the_identity_server_times_out + open_id_consumer = mock() + open_id_consumer.expects(:begin).raises(Timeout::Error, "Identity Server took too long.") + @controller.expects(:open_id_consumer).returns(open_id_consumer) + @controller.expects(:logger).returns(mock(:error => true)) + + @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url| + assert result.missing? + assert_equal "Sorry, the OpenID server couldn't be found", result.message + end + end + + def test_authentication_should_begin_when_the_identity_server_is_present + @controller.expects(:begin_open_id_authentication) + @controller.send(:authenticate_with_open_id, "http://someone.example.com") + end +end diff --git a/vendor/plugins/open_id_authentication/test/status_test.rb b/vendor/plugins/open_id_authentication/test/status_test.rb new file mode 100644 index 0000000..b1d5e09 --- /dev/null +++ b/vendor/plugins/open_id_authentication/test/status_test.rb @@ -0,0 +1,14 @@ +require File.dirname(__FILE__) + '/test_helper' + +class StatusTest < Test::Unit::TestCase + include OpenIdAuthentication + + def test_state_conditional + assert Result[:missing].missing? + assert Result[:missing].unsuccessful? + assert !Result[:missing].successful? + + assert Result[:successful].successful? + assert !Result[:successful].unsuccessful? + end +end \ No newline at end of file diff --git a/vendor/plugins/open_id_authentication/test/test_helper.rb b/vendor/plugins/open_id_authentication/test/test_helper.rb new file mode 100644 index 0000000..43216e1 --- /dev/null +++ b/vendor/plugins/open_id_authentication/test/test_helper.rb @@ -0,0 +1,17 @@ +require 'test/unit' +require 'rubygems' + +gem 'activesupport' +require 'active_support' + +gem 'actionpack' +require 'action_controller' + +gem 'mocha' +require 'mocha' + +gem 'ruby-openid' +require 'openid' + +RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT +require File.dirname(__FILE__) + "/../lib/open_id_authentication" diff --git a/vendor/plugins/recaptcha/CHANGELOG b/vendor/plugins/recaptcha/CHANGELOG new file mode 100644 index 0000000..92a63fd --- /dev/null +++ b/vendor/plugins/recaptcha/CHANGELOG @@ -0,0 +1,23 @@ +== 0.2.2 / 2009-09-14 + +* Add a timeout to the validator +* Give the documentation some love + +== 0.2.1 / 2009-09-14 + +* Removed Ambethia namespace, and restructured classes a bit +* Added an example rails app in the example-rails branch + +== 0.2.0 / 2009-09-12 + +* RecaptchaOptions AJAX API Fix +* Added 'cucumber' as a test environment to skip +* Ruby 1.9 compat fixes +* Added option :message => 'Custom error message' to verify_recaptcha +* Removed dependency on ActiveRecord constant +* Add I18n + +== 0.1.0 / 2008-2-8 + +* 1 major enhancement + * Initial Gem Release \ No newline at end of file diff --git a/vendor/plugins/recaptcha/LICENSE b/vendor/plugins/recaptcha/LICENSE new file mode 100644 index 0000000..dc9c67e --- /dev/null +++ b/vendor/plugins/recaptcha/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2007 Jason L Perry + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/vendor/plugins/recaptcha/README.rdoc b/vendor/plugins/recaptcha/README.rdoc new file mode 100644 index 0000000..741e75e --- /dev/null +++ b/vendor/plugins/recaptcha/README.rdoc @@ -0,0 +1,92 @@ += reCAPTCHA + +Author:: Jason L Perry (http://ambethia.com) +Copyright:: Copyright (c) 2007 Jason L Perry +License:: {MIT}[http://creativecommons.org/licenses/MIT/] +Info:: http://ambethia.com/recaptcha +Git:: http://github.com/ambethia/recaptcha/tree/master +Bugs:: http://github.com/ambethia/recaptcha/issues + +This plugin adds helpers for the {reCAPTCHA API}[http://recaptcha.net]. In your views you can use +the +recaptcha_tags+ method to embed the needed javascript, and you can validate in your controllers +with +verify_recaptcha+. + +You'll want to add your public and private API keys in the environment variables +RECAPTCHA_PUBLIC_KEY+ +and +RECAPTCHA_PRIVATE_KEY+, respectively. You could also specify them in <tt>config/environment.rb</tt> if you +are so inclined (see below). Exceptions will be raised if you call these methods and the keys can't be found. + +== Rails Installation + +reCAPTCHA for Rails can be installed as a gem: + + config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com" + +Or, as a standard rails plugin: + + script/plugin install git://github.com/ambethia/recaptcha.git + +== Setting up your API Keys + +There are two ways to setup your reCAPTCHA API keys once you {obtain}[http://recaptcha.net/whyrecaptcha.html] +a pair. You can pass in your keys as options at runtime, for example: + + recaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy' + +and later, + + verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx' + + +Or, preferably, you can keep your keys out of your code base by exporting the environment variables +mentioned earlier. You might do this in the .profile/rc, or equivalent for the user running your +application: + + export RECAPTCHA_PUBLIC_KEY = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy' + export RECAPTCHA_PRIVATE_KEY = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx' + +If that's not your thing, and dropping things into <tt>config/environment.rb</tt> is, you can just do: + + ENV['RECAPTCHA_PUBLIC_KEY'] = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy' + ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx' + +== +recaptcha_tags+ + +Some of the options available: + +<tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+) +<tt>:noscript</tt>:: Include <noscript> content (default +true+) +<tt>:display</tt>:: Takes a hash containing the +theme+ and +tabindex+ options per the API. (default +nil+) +<tt>:ajax</tt>:: Render the dynamic AJAX captcha per the API. (default +false+) +<tt>:public_key</tt>:: Your public API key, takes precedence over the ENV variable (default +nil+) +<tt>:error</tt>:: Override the error code returned from the reCAPTCHA API (default +nil+) + +You can also override the html attributes for the sizes of the generated +textarea+ and +iframe+ +elements, if CSS isn't your thing. Inspect the source of +recaptcha_tags+ to see these options. + +== +verify_recaptcha+ + +This method returns +true+ or +false+ after processing the parameters from the reCAPTCHA widget. Why +isn't this a model validation? Because that violates MVC. Use can use it like this, or how ever you +like. Passing in the ActiveRecord object is optional, if you do--and the captcha fails to verify--an +error will be added to the object for you to use. + +Some of the options available: + +<tt>:model</tt>:: Model to set errors +<tt>:message</tt>:: Custom error message +<tt>:private_key</tt>:: Your private API key, takes precedence over the ENV variable (default +nil+). +<tt>:timeout</tt>:: The number of seconds to wait for reCAPTCHA servers before give up. (default +3+) + + respond_to do |format| + if verify_recaptcha(:model => @post, :message => 'Oh! It's error with reCAPTCHA!') && @post.save + # ... + else + # ... + end + end + +== TODO +* Remove Rails/ActionController dependencies +* Framework agnostic +* Add some helpers to use in before_filter and what not +* Better documentation diff --git a/vendor/plugins/recaptcha/Rakefile b/vendor/plugins/recaptcha/Rakefile new file mode 100644 index 0000000..c63d575 --- /dev/null +++ b/vendor/plugins/recaptcha/Rakefile @@ -0,0 +1,58 @@ +require 'rake' + +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "recaptcha" + gem.description = "This plugin adds helpers for the reCAPTCHA API " + gem.summary = "Helpers for the reCAPTCHA API" + gem.homepage = "http://ambethia.com/recaptcha" + gem.authors = ["Jason L. Perry"] + gem.email = "jasper@ambethia.com" + gem.files.reject! { |fn| fn.include? ".gitignore" } + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" +end + +require 'rake/rdoctask' +Rake::RDocTask.new do |rd| + if File.exist?('VERSION.yml') + config = YAML.load(File.read('VERSION.yml')) + version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}" + else + version = "" + end + + rd.main = "README.rdoc" + rd.rdoc_files.include "README.rdoc", "LICENSE", "lib/**/*.rb" + rd.rdoc_dir = 'rdoc' + rd.options << '-N' # line numbers + rd.options << '-S' # inline source +end + +require 'rake/testtask' +Rake::TestTask.new(:test) do |test| + test.libs << 'test' + test.pattern = 'test/**/*_test.rb' + # test.verbose = true +end + +begin + require 'rcov/rcovtask' + Rcov::RcovTask.new do |test| + test.libs << 'test' + test.pattern = 'test/**/*_test.rb' + test.verbose = true + end +rescue LoadError + task :rcov do + abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" + end +end + +task :default => :test + + + diff --git a/vendor/plugins/recaptcha/VERSION b/vendor/plugins/recaptcha/VERSION new file mode 100644 index 0000000..ee1372d --- /dev/null +++ b/vendor/plugins/recaptcha/VERSION @@ -0,0 +1 @@ +0.2.2 diff --git a/vendor/plugins/recaptcha/init.rb b/vendor/plugins/recaptcha/init.rb new file mode 100644 index 0000000..2e9a27a --- /dev/null +++ b/vendor/plugins/recaptcha/init.rb @@ -0,0 +1,6 @@ +# Rails plugin initialization. +# You can also install it as a gem: +# config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com" + +require 'net/http' +require 'recaptcha/rails' \ No newline at end of file diff --git a/vendor/plugins/recaptcha/lib/recaptcha.rb b/vendor/plugins/recaptcha/lib/recaptcha.rb new file mode 100644 index 0000000..37989b5 --- /dev/null +++ b/vendor/plugins/recaptcha/lib/recaptcha.rb @@ -0,0 +1,22 @@ +require 'recaptcha/client_helper' +require 'recaptcha/verify' + +module Recaptcha + module VERSION #:nodoc: + MAJOR = 0 + MINOR = 2 + TINY = 2 + + STRING = [MAJOR, MINOR, TINY].join('.') + end + + + RECAPTCHA_API_SERVER = 'http://api.recaptcha.net'; + RECAPTCHA_API_SECURE_SERVER = 'https://api-secure.recaptcha.net'; + RECAPTCHA_VERIFY_SERVER = 'api-verify.recaptcha.net'; + + SKIP_VERIFY_ENV = ['test', 'cucumber'] + + class RecaptchaError < StandardError + end +end \ No newline at end of file diff --git a/vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb b/vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb new file mode 100644 index 0000000..b787eaf --- /dev/null +++ b/vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb @@ -0,0 +1,42 @@ +module Recaptcha + module ClientHelper + # Your public API can be specified in the +options+ hash or preferably + # the environment variable +RECAPTCHA_PUBLIC_KEY+. + def recaptcha_tags(options = {}) + # Default options + key = options[:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY'] + error = options[:error] ||= flash[:recaptcha_error] + uri = options[:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER + html = "" + if options[:display] + html << %{<script type="text/javascript">\n} + html << %{ var RecaptchaOptions = #{options[:display].to_json};\n} + html << %{</script>\n} + end + if options[:ajax] + html << %{<div id="dynamic_recaptcha"></div>} + html << %{<script type="text/javascript" src="#{uri}/js/recaptcha_ajax.js"></script>\n} + html << %{<script type="text/javascript">\n} + html << %{ Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha')#{options[:display] ? ',RecaptchaOptions' : ''});} + html << %{</script>\n} + else + html << %{<script type="text/javascript" src="#{uri}/challenge?k=#{key}} + html << %{#{error ? "&error=#{CGI::escape(error)}" : ""}"></script>\n} + unless options[:noscript] == false + html << %{<noscript>\n } + html << %{<iframe src="#{uri}/noscript?k=#{key}" } + html << %{height="#{options[:iframe_height] ||= 300}" } + html << %{width="#{options[:iframe_width] ||= 500}" } + html << %{frameborder="0"></iframe><br/>\n } + html << %{<textarea name="recaptcha_challenge_field" } + html << %{rows="#{options[:textarea_rows] ||= 3}" } + html << %{cols="#{options[:textarea_cols] ||= 40}"></textarea>\n } + html << %{<input type="hidden" name="recaptcha_response_field" value="manual_challenge">} + html << %{</noscript>\n} + end + end + raise RecaptchaError, "No public key specified." unless key + return html + end # recaptcha_tags + end # ClientHelper +end # Recaptcha diff --git a/vendor/plugins/recaptcha/lib/recaptcha/rails.rb b/vendor/plugins/recaptcha/lib/recaptcha/rails.rb new file mode 100644 index 0000000..08741cf --- /dev/null +++ b/vendor/plugins/recaptcha/lib/recaptcha/rails.rb @@ -0,0 +1,4 @@ +require 'recaptcha' + +ActionView::Base.send(:include, Recaptcha::ClientHelper) +ActionController::Base.send(:include, Recaptcha::Verify) \ No newline at end of file diff --git a/vendor/plugins/recaptcha/lib/recaptcha/verify.rb b/vendor/plugins/recaptcha/lib/recaptcha/verify.rb new file mode 100644 index 0000000..c553826 --- /dev/null +++ b/vendor/plugins/recaptcha/lib/recaptcha/verify.rb @@ -0,0 +1,45 @@ +module Recaptcha + module Verify + # Your private API can be specified in the +options+ hash or preferably + # the environment variable +RECAPTCHA_PUBLIC_KEY+. + def verify_recaptcha(options = {}) + return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV'] + model = options.is_a?(Hash)? options[:model] : options + private_key = options[:private_key] if options.is_a?(Hash) + private_key ||= ENV['RECAPTCHA_PRIVATE_KEY'] + raise RecaptchaError, "No private key specified." unless private_key + begin + recaptcha = nil + Timeout::timeout(options[:timeout] || 3) do + recaptcha = Net::HTTP.post_form URI.parse("http://#{RECAPTCHA_VERIFY_SERVER}/verify"), { + "privatekey" => private_key, + "remoteip" => request.remote_ip, + "challenge" => params[:recaptcha_challenge_field], + "response" => params[:recaptcha_response_field] + } + end + answer, error = recaptcha.body.split.map { |s| s.chomp } + unless answer == 'true' + flash[:recaptcha_error] = error + if model + model.valid? + model.errors.add :base, options[:message] || "Word verification response is incorrect, please try again." + end + return false + else + flash[:recaptcha_error] = nil + return true + end + rescue Timeout::Error + flash[:recaptcha_error] = "recaptcha-not-reachable" + if model + model.valid? + model.errors.add :base, options[:message] || "Oops, we failed to validate your word verification response. Please try again." + end + return false + rescue Exception => e + raise RecaptchaError, e.message, e.backtrace + end + end # verify_recaptcha + end # Verify +end # Recaptcha diff --git a/vendor/plugins/recaptcha/recaptcha.gemspec b/vendor/plugins/recaptcha/recaptcha.gemspec new file mode 100644 index 0000000..091db26 --- /dev/null +++ b/vendor/plugins/recaptcha/recaptcha.gemspec @@ -0,0 +1,54 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE +# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec` +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{recaptcha} + s.version = "0.2.2" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Jason L. Perry"] + s.date = %q{2009-10-14} + s.description = %q{This plugin adds helpers for the reCAPTCHA API } + s.email = %q{jasper@ambethia.com} + s.extra_rdoc_files = [ + "LICENSE", + "README.rdoc" + ] + s.files = [ + "CHANGELOG", + "LICENSE", + "README.rdoc", + "Rakefile", + "VERSION", + "init.rb", + "lib/recaptcha.rb", + "lib/recaptcha/client_helper.rb", + "lib/recaptcha/rails.rb", + "lib/recaptcha/verify.rb", + "recaptcha.gemspec", + "tasks/recaptcha_tasks.rake", + "test/recaptcha_test.rb", + "test/verify_recaptcha_test.rb" + ] + s.homepage = %q{http://github.com/ambethia/recaptcha} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.5} + s.summary = %q{Helpers for the reCAPTCHA API} + s.test_files = [ + "test/recaptcha_test.rb", + "test/verify_recaptcha_test.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end diff --git a/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake b/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake new file mode 100644 index 0000000..a0cf1ad --- /dev/null +++ b/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :recaptcha do +# # Task goes here +# end \ No newline at end of file diff --git a/vendor/plugins/recaptcha/test/recaptcha_test.rb b/vendor/plugins/recaptcha/test/recaptcha_test.rb new file mode 100644 index 0000000..260f5b2 --- /dev/null +++ b/vendor/plugins/recaptcha/test/recaptcha_test.rb @@ -0,0 +1,37 @@ +require 'test/unit' +require 'cgi' +require File.dirname(__FILE__) + '/../lib/recaptcha' + +class RecaptchaClientHelperTest < Test::Unit::TestCase + include Recaptcha + include Recaptcha::ClientHelper + include Recaptcha::Verify + + attr_accessor :session + + def setup + @session = {} + ENV['RECAPTCHA_PUBLIC_KEY'] = '0000000000000000000000000000000000000000' + ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + end + + def test_recaptcha_tags + # Might as well match something... + assert_match /http:\/\/api.recaptcha.net/, recaptcha_tags + end + + def test_recaptcha_tags_with_ssl + assert_match /https:\/\/api-secure.recaptcha.net/, recaptcha_tags(:ssl => true) + end + + def test_recaptcha_tags_without_noscript + assert_no_match /noscript/, recaptcha_tags(:noscript => false) + end + + def test_should_raise_exception_without_public_key + assert_raise RecaptchaError do + ENV['RECAPTCHA_PUBLIC_KEY'] = nil + recaptcha_tags + end + end +end diff --git a/vendor/plugins/recaptcha/test/verify_recaptcha_test.rb b/vendor/plugins/recaptcha/test/verify_recaptcha_test.rb new file mode 100644 index 0000000..da523b8 --- /dev/null +++ b/vendor/plugins/recaptcha/test/verify_recaptcha_test.rb @@ -0,0 +1,96 @@ +require 'test/unit' +require 'rails/version' # For getting the rails version constants +require 'active_support/vendor' # For loading I18n +require 'mocha' +require 'net/http' +require File.dirname(__FILE__) + '/../lib/recaptcha' + +class RecaptchaVerifyTest < Test::Unit::TestCase + def setup + + ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + @controller = TestController.new + @controller.request = stub(:remote_ip => "1.1.1.1") + @controller.params = {:recaptcha_challenge_field => "challenge", :recaptcha_response_field => "response"} + + @expected_post_data = {} + @expected_post_data["privatekey"] = ENV['RECAPTCHA_PRIVATE_KEY'] + @expected_post_data["remoteip"] = @controller.request.remote_ip + @expected_post_data["challenge"] = "challenge" + @expected_post_data["response"] = "response" + + @expected_uri = URI.parse("http://#{Recaptcha::RECAPTCHA_VERIFY_SERVER}/verify") + end + + def test_should_raise_exception_without_private_key + assert_raise Recaptcha::RecaptchaError do + ENV['RECAPTCHA_PRIVATE_KEY'] = nil + @controller.verify_recaptcha + end + end + + def test_should_return_false_when_key_is_invalid + expect_http_post(response_with_body("false\ninvalid-site-private-key")) + + assert !@controller.verify_recaptcha + assert_equal "invalid-site-private-key", @controller.session[:recaptcha_error] + end + + def test_returns_true_on_success + @controller.session[:recaptcha_error] = "previous error that should be cleared" + expect_http_post(response_with_body("true\n")) + + assert @controller.verify_recaptcha + assert_nil @controller.session[:recaptcha_error] + end + + def test_errors_should_be_added_to_model + expect_http_post(response_with_body("false\nbad-news")) + + errors = mock + errors.expects(:add).with(:base, "Captcha response is incorrect, please try again.") + model = mock(:valid? => false, :errors => errors) + + assert !@controller.verify_recaptcha(:model => model) + assert_equal "bad-news", @controller.session[:recaptcha_error] + end + + def test_returns_true_on_success_with_optional_key + @controller.session[:recaptcha_error] = "previous error that should be cleared" + # reset private key + @expected_post_data["privatekey"] = 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX' + expect_http_post(response_with_body("true\n")) + + assert @controller.verify_recaptcha(:private_key => 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX') + assert_nil @controller.session[:recaptcha_error] + end + + def test_timeout + expect_http_post(Timeout::Error, :exception => true) + assert !@controller.verify_recaptcha() + assert_equal "recaptcha-not-reachable", @controller.session[:recaptcha_error] + end + + private + + class TestController + include Recaptcha::Verify + attr_accessor :request, :params, :session + + def initialize + @session = {} + end + end + + def expect_http_post(response, options = {}) + unless options[:exception] + Net::HTTP.expects(:post_form).with(@expected_uri, @expected_post_data).returns(response) + else + Net::HTTP.expects(:post_form).raises response + end + end + + def response_with_body(body) + stub(:body => body) + end +end diff --git a/vendor/plugins/strip_attributes/README.rdoc b/vendor/plugins/strip_attributes/README.rdoc new file mode 100644 index 0000000..bd55c0c --- /dev/null +++ b/vendor/plugins/strip_attributes/README.rdoc @@ -0,0 +1,77 @@ +== StripAttributes + +StripAttributes is a Rails plugin that automatically strips all ActiveRecord +model attributes of leading and trailing whitespace before validation. If the +attribute is blank, it strips the value to +nil+. + +It works by adding a before_validation hook to the record. By default, all +attributes are stripped of whitespace, but <tt>:only</tt> and <tt>:except</tt> +options can be used to limit which attributes are stripped. Both options accept +a single attribute (<tt>:only => :field</tt>) or arrays of attributes (<tt>:except => +[:field1, :field2, :field3]</tt>). + +=== Examples + + class DrunkPokerPlayer < ActiveRecord::Base + strip_attributes! + end + + class SoberPokerPlayer < ActiveRecord::Base + strip_attributes! :except => :boxers + end + + class ConservativePokerPlayer < ActiveRecord::Base + strip_attributes! :only => [:shoe, :sock, :glove] + end + +=== Installation + +Option 1. Use the standard Rails plugin install (assuming Rails 2.1). + + ./script/plugin install git://github.com/rmm5t/strip_attributes.git + +Option 2. Use git submodules + + git submodule add git://github.com/rmm5t/strip_attributes.git vendor/plugins/strip_attributes + +Option 3. Use braid[http://github.com/evilchelu/braid/tree/master] (assuming +you're using git) + + braid add --rails_plugin git://github.com/rmm5t/strip_attributes.git + git merge braid/track + +=== Other + +If you want to use this outside of Rails, extend StripAttributes in your +ActiveRecord model after putting strip_attributes in your <tt>$LOAD_PATH</tt>: + + require 'strip_attributes' + class SomeModel < ActiveRecord::Base + extend StripAttributes + strip_attributes! + end + +=== Support + +The StripAttributes homepage is http://stripattributes.rubyforge.org. You can +find the StripAttributes RubyForge progject page at: +http://rubyforge.org/projects/stripattributes + +StripAttributes source is hosted on GitHub[http://github.com/]: +http://github.com/rmm5t/strip_attributes + +Feel free to submit suggestions or feature requests. If you send a patch, +remember to update the corresponding unit tests. In fact, I prefer new features +to be submitted in the form of new unit tests. + +=== Credits + +The idea was triggered by the information at +http://wiki.rubyonrails.org/rails/pages/HowToStripWhitespaceFromModelFields +but was modified from the original to include more idiomatic ruby and rails +support. + +=== License + +Copyright (c) 2007-2008 Ryan McGeary released under the MIT license +http://en.wikipedia.org/wiki/MIT_License \ No newline at end of file diff --git a/vendor/plugins/strip_attributes/Rakefile b/vendor/plugins/strip_attributes/Rakefile new file mode 100644 index 0000000..88baf33 --- /dev/null +++ b/vendor/plugins/strip_attributes/Rakefile @@ -0,0 +1,30 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the stripattributes plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the stripattributes plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'Stripattributes' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +desc 'Publishes rdoc to rubyforge server' +task :publish_rdoc => :rdoc do + cmd = "scp -r rdoc/* rmm5t@rubyforge.org:/var/www/gforge-projects/stripattributes" + puts "\nPublishing rdoc: #{cmd}\n\n" + system(cmd) +end + diff --git a/vendor/plugins/strip_attributes/init.rb b/vendor/plugins/strip_attributes/init.rb new file mode 100644 index 0000000..2c71b29 --- /dev/null +++ b/vendor/plugins/strip_attributes/init.rb @@ -0,0 +1,2 @@ +require 'strip_attributes' +ActiveRecord::Base.extend(StripAttributes) diff --git a/vendor/plugins/strip_attributes/lib/strip_attributes.rb b/vendor/plugins/strip_attributes/lib/strip_attributes.rb new file mode 100644 index 0000000..fa66d39 --- /dev/null +++ b/vendor/plugins/strip_attributes/lib/strip_attributes.rb @@ -0,0 +1,31 @@ +module StripAttributes + # Strips whitespace from model fields and converts blank values to nil. + def strip_attributes!(options = nil) + before_validation do |record| + attributes = StripAttributes.narrow(record.attributes, options) + attributes.each do |attr, value| + if value.respond_to?(:strip) + record[attr] = (value.blank?) ? nil : value.strip + end + end + end + end + + # Necessary because Rails has removed the narrowing of attributes using :only + # and :except on Base#attributes + def self.narrow(attributes, options) + if options.nil? + attributes + else + if except = options[:except] + except = Array(except).collect { |attribute| attribute.to_s } + attributes.except(*except) + elsif only = options[:only] + only = Array(only).collect { |attribute| attribute.to_s } + attributes.slice(*only) + else + raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})" + end + end + end +end diff --git a/vendor/plugins/strip_attributes/shoulda_macros/macros.rb b/vendor/plugins/strip_attributes/shoulda_macros/macros.rb new file mode 100644 index 0000000..95b318e --- /dev/null +++ b/vendor/plugins/strip_attributes/shoulda_macros/macros.rb @@ -0,0 +1,35 @@ +require 'shoulda/active_record' + +module StripAttributes + module Macros + def should_strip_attributes(*attributes) + klass = respond_to?(:described_type) ? described_type : model_class + attributes.each do |attribute| + attribute = attribute.to_sym + should "strip whitespace from #{attribute}" do + object = get_instance_of(klass) + object.send("#{attribute}=", " string ") + object.valid? + assert_equal "string", object.send(attribute) + end + end + end + + def should_not_strip_attributes(*attributes) + klass = respond_to?(:described_type) ? described_type : model_class + attributes.each do |attribute| + attribute = attribute.to_sym + should "not strip whitespace from #{attribute}" do + object = get_instance_of(klass) + object.send("#{attribute}=", " string ") + object.valid? + assert_equal " string ", object.send(attribute) + end + end + end + end +end + +class Test::Unit::TestCase + extend StripAttributes::Macros +end diff --git a/vendor/plugins/strip_attributes/test/strip_attributes_test.rb b/vendor/plugins/strip_attributes/test/strip_attributes_test.rb new file mode 100644 index 0000000..32ec1ae --- /dev/null +++ b/vendor/plugins/strip_attributes/test/strip_attributes_test.rb @@ -0,0 +1,96 @@ +require "#{File.dirname(__FILE__)}/test_helper" + +module MockAttributes + def self.included(base) + base.column :foo, :string + base.column :bar, :string + base.column :biz, :string + base.column :baz, :string + base.column :bang, :string + end +end + +class StripAllMockRecord < ActiveRecord::Base + include MockAttributes + strip_attributes! +end + +class StripOnlyOneMockRecord < ActiveRecord::Base + include MockAttributes + strip_attributes! :only => :foo +end + +class StripOnlyThreeMockRecord < ActiveRecord::Base + include MockAttributes + strip_attributes! :only => [:foo, :bar, :biz] +end + +class StripExceptOneMockRecord < ActiveRecord::Base + include MockAttributes + strip_attributes! :except => :foo +end + +class StripExceptThreeMockRecord < ActiveRecord::Base + include MockAttributes + strip_attributes! :except => [:foo, :bar, :biz] +end + +class StripAttributesTest < Test::Unit::TestCase + def setup + @init_params = { :foo => "\tfoo", :bar => "bar \t ", :biz => "\tbiz ", :baz => "", :bang => " " } + end + + def test_should_exist + assert Object.const_defined?(:StripAttributes) + end + + def test_should_strip_all_fields + record = StripAllMockRecord.new(@init_params) + record.valid? + assert_equal "foo", record.foo + assert_equal "bar", record.bar + assert_equal "biz", record.biz + assert_nil record.baz + assert_nil record.bang + end + + def test_should_strip_only_one_field + record = StripOnlyOneMockRecord.new(@init_params) + record.valid? + assert_equal "foo", record.foo + assert_equal "bar \t ", record.bar + assert_equal "\tbiz ", record.biz + assert_equal "", record.baz + assert_equal " ", record.bang + end + + def test_should_strip_only_three_fields + record = StripOnlyThreeMockRecord.new(@init_params) + record.valid? + assert_equal "foo", record.foo + assert_equal "bar", record.bar + assert_equal "biz", record.biz + assert_equal "", record.baz + assert_equal " ", record.bang + end + + def test_should_strip_all_except_one_field + record = StripExceptOneMockRecord.new(@init_params) + record.valid? + assert_equal "\tfoo", record.foo + assert_equal "bar", record.bar + assert_equal "biz", record.biz + assert_nil record.baz + assert_nil record.bang + end + + def test_should_strip_all_except_three_fields + record = StripExceptThreeMockRecord.new(@init_params) + record.valid? + assert_equal "\tfoo", record.foo + assert_equal "bar \t ", record.bar + assert_equal "\tbiz ", record.biz + assert_nil record.baz + assert_nil record.bang + end +end diff --git a/vendor/plugins/strip_attributes/test/test_helper.rb b/vendor/plugins/strip_attributes/test/test_helper.rb new file mode 100644 index 0000000..7dd5a96 --- /dev/null +++ b/vendor/plugins/strip_attributes/test/test_helper.rb @@ -0,0 +1,21 @@ +require 'test/unit' +require 'rubygems' +require 'active_record' +begin require 'redgreen' if ENV['TM_FILENAME'].nil?; rescue LoadError; end + +PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")) + +$LOAD_PATH.unshift "#{PLUGIN_ROOT}/lib" +require "#{PLUGIN_ROOT}/init" + +class ActiveRecord::Base + alias_method :save, :valid? + def self.columns() + @columns ||= [] + end + + def self.column(name, sql_type = nil, default = nil, null = true) + @columns ||= [] + @columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null) + end +end
adiel/availabletopair
2b035e6fe0122ca9cb82c2e548af8fc712e07412
User atom feed updates when an available pair changes. Now calculating pairs when changes are made.
diff --git a/app/controllers/availabilities_controller.rb b/app/controllers/availabilities_controller.rb index 9ef0860..f79e859 100644 --- a/app/controllers/availabilities_controller.rb +++ b/app/controllers/availabilities_controller.rb @@ -1,85 +1,87 @@ class AvailabilitiesController < ApplicationController # GET /availabilities # GET /availabilities.xml def index - @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["end_time > :end_time",{:end_time => Time.now.getgm}]) - + @availabilities = Availability.find(:all, :order => "start_time", + :conditions => ["end_time > :end_time", + {:end_time => Time.now.utc}]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availabilities } end end # GET /availabilities/1 # GET /availabilities/1.xml def show @availability = Availability.find(params[:id]) + @availability.pairs.sort! {|p1,p2| p1.updated_at <=> p2.updated_at}.reverse! respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/new # GET /availabilities/new.xml def new @availability = Availability.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/1/edit def edit @availability = Availability.find(params[:id]) end # POST /availabilities # POST /availabilities.xml def create @availability = Availability.new(params[:availability]) respond_to do |format| if @availability.save flash[:notice] = 'Availability was successfully created.' format.html { redirect_to(@availability) } format.xml { render :xml => @availability, :status => :created, :location => @availability } else format.html { render :action => "new" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # PUT /availabilities/1 # PUT /availabilities/1.xml def update @availability = Availability.find(params[:id]) respond_to do |format| if @availability.update_attributes(params[:availability]) flash[:notice] = 'Availability was successfully updated.' format.html { redirect_to(@availability) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # DELETE /availabilities/1 # DELETE /availabilities/1.xml def destroy @availability = Availability.find(params[:id]) @availability.destroy respond_to do |format| format.html { redirect_to(availabilities_url) } format.xml { head :ok } end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da8068e..13efcda 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,17 +1,29 @@ class UsersController < ApplicationController layout 'availabilities' + + def sort_availabilities_and_pairs + @availabilities.each do |availability| + availability.pairs.sort!{ |p1, p2| p1.updated_at <=> p2.updated_at}.reverse! + end + @availabilities.sort! do |a1, a2| + a1_updated = a1.pairs.length == 0 ? a1.updated_at : a1.pairs[0].updated_at + a2_updated = a2.pairs.length == 0 ? a2.updated_at : a2.pairs[0].updated_at + a1_updated <=> a2_updated + end.reverse! + end + # GET /username # GET /username.atom def index @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["developer = :developer and end_time > :end_time" , - {:developer => params[:id],:end_time => Time.now.getgm}]) + {:developer => params[:id],:end_time => Time.now.utc}]) respond_to do |format| format.html # index.html.erb format.atom do - @availabilities.sort! { |a1,a2| a1.updated_at <=> a2.updated_at}.reverse! + sort_availabilities_and_pairs end end end end diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index 00dd1a2..9726d9d 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,46 +1,50 @@ module AvailabilitiesHelper def contact_link(availability) email?(availability.contact) ? mail_to(h(availability.contact)) : link_to(h(availability.contact),h(availability.contact)) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability) "%dh %02dm" % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)}" end def display_when_time(availability) "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" end def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end + + def pairs_updated(availability) + availability.pairs.length > 0 ? availability.pairs[0].updated_at : availability.updated_at + end end diff --git a/app/models/availability.rb b/app/models/availability.rb index 2a925d5..601d53c 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,39 +1,28 @@ class Availability < ActiveRecord::Base + validates_presence_of :developer, :contact, :start_time, :end_time + has_many :pairs + strip_attributes! - def initialize(availability = nil) - super + def pair_synchronizer + @pair_synchronizer ||= PairSynchronizer.new end - def pairs - @pairs ||= find_pairs - @pairs - end - - def find_pairs - conditions = "developer != :developer and start_time < :end_time and end_time > :start_time" - condition_values = {:developer => developer, - :start_time => start_time, - :end_time => end_time} - if project.to_s != "" - conditions += " and (project = :project or project = '')" - condition_values[:project] = project - end - - pair_conditions = [conditions, condition_values] - pairs = Availability.find(:all, :conditions => pair_conditions) - set_intersecting_start_and_end_times!(pairs) + def pair_synchronizer=(pair_synchronizer) + @pair_synchronizer = pair_synchronizer end - def set_intersecting_start_and_end_times!(pairs) - pairs.each do |pair| - pair.start_time = pair.start_time > start_time ? pair.start_time : start_time - pair.end_time = pair.end_time < end_time ? pair.end_time : end_time - end - pairs + def save + super() + pair_synchronizer.synchronize_pairs(self) end + def destroy + super() + pair_synchronizer.synchronize_pairs(self) + end + def duration_sec end_time - start_time end end diff --git a/app/models/pair.rb b/app/models/pair.rb new file mode 100644 index 0000000..9d2635f --- /dev/null +++ b/app/models/pair.rb @@ -0,0 +1,7 @@ +class Pair < ActiveRecord::Base + belongs_to :availability + + def duration_sec + end_time - start_time + end +end diff --git a/app/models/pair_matcher.rb b/app/models/pair_matcher.rb new file mode 100644 index 0000000..c579af3 --- /dev/null +++ b/app/models/pair_matcher.rb @@ -0,0 +1,18 @@ +class PairMatcher + + def find_pairs(availability) + conditions = "developer != :developer and start_time < :end_time and end_time > :start_time" + condition_values = {:developer => availability.developer, + :start_time => availability.start_time, + :end_time => availability.end_time} + if availability.project.to_s != "" + conditions += " and (project = :project or project = '')" + condition_values[:project] = availability.project + end + + pair_conditions = [conditions, condition_values] + pairs = Availability.find(:all, :conditions => pair_conditions) + end + +end + \ No newline at end of file diff --git a/app/models/pair_repository.rb b/app/models/pair_repository.rb new file mode 100644 index 0000000..48cb922 --- /dev/null +++ b/app/models/pair_repository.rb @@ -0,0 +1,28 @@ +class PairRepository + + def latest_start_time (master_availability, pair_availability) + pair_availability.start_time > master_availability.start_time ? pair_availability.start_time : master_availability.start_time + end + + def earliest_end_time (master_availability, pair_availability) + pair_availability.end_time < master_availability.end_time ? pair_availability.end_time : master_availability.end_time + end + + def create(master_availability,pair_availability) + pair = Pair.new + update(pair,master_availability,pair_availability) + end + + def update(pair,master_availability,pair_availability) + pair.availability_id = master_availability.id + pair.available_pair_id = pair_availability.id + pair.developer = pair_availability.developer + pair.contact = pair_availability.contact + pair.project = master_availability.project || pair_availability.project + pair.start_time = latest_start_time(master_availability, pair_availability) + pair.end_time = earliest_end_time(master_availability, pair_availability) + pair.save + pair + end + +end diff --git a/app/models/pair_synchronizer.rb b/app/models/pair_synchronizer.rb new file mode 100644 index 0000000..e815343 --- /dev/null +++ b/app/models/pair_synchronizer.rb @@ -0,0 +1,53 @@ +class PairSynchronizer + + def initialize(pair_matcher = nil, pair_repository = nil) + @pair_matcher = pair_matcher || PairMatcher.new + @pair_repository = pair_repository || PairRepository.new + end + + def save_or_update (existing, master_availability, pair_availability) + if existing.nil? + @pair_repository.create(master_availability, pair_availability) + else + @pair_repository.update(existing, master_availability, pair_availability) + end + end + + def save_or_update_master(existing_pairs, availability, new_matching_availability) + existing_master = existing_pairs.find do |p| + p.available_pair_id == new_matching_availability.id + end + save_or_update(existing_master, availability, new_matching_availability) + end + + def save_or_update_pair (existing_pairs, availability, new_matching_availability) + existing_pair = existing_pairs.find do |p| + p.availability_id == new_matching_availability.id + end + save_or_update(existing_pair, new_matching_availability, availability) + end + + def synchronize_pairs(availability) + conditions_clause = "availability_id = :availability_id or available_pair_id = :available_pair_id" + conditions_params = {:availability_id => availability.id,:available_pair_id => availability.id} + + existing_pairs = Pair.find(:all,:conditions => [conditions_clause,conditions_params]) + new_matching_availabilities = @pair_matcher.find_pairs(availability) + + new_matching_availabilities.each do |new_matching_availability| + save_or_update_master(existing_pairs, availability, new_matching_availability) + save_or_update_pair(existing_pairs, availability, new_matching_availability) + end + + existing_pairs.each do |existing| + match = new_matching_availabilities.find {|new_matching_availability| + new_matching_availability.id == existing.availability_id || + new_matching_availability.id == existing.available_pair_id + } + existing.destroy if match.nil? + end + + end + +end + diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb index 83474fe..6beb2de 100644 --- a/app/views/users/index.atom.erb +++ b/app/views/users/index.atom.erb @@ -1,35 +1,35 @@ <feed xmlns="http://www.w3.org/2005/Atom" > <title><%= user %> is Available To Pair</title> <id><%= http_root %>/<%= user%></id> <link href="<%= http_root %>/<%= user%>.atom" rel="self" /> <link href="<%= http_root %>/<%= user%>" /> <author> <name>Available To Pair</name> <email>noreply@availabletopair.com</email> </author> - <% unless @availabilities.length == 0 %> - <updated><%=h @availabilities[0].updated_at.xmlschema %></updated> - <%end%> +<% unless @availabilities.length == 0 %> + <updated><%= pairs_updated(@availabilities[0]).xmlschema %></updated> +<%end%> <% @availabilities.each do |availability| %> <entry> - <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(availability.updated_at)%>)</title> + <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(pairs_updated(availability))%>)</title> <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> - <published><%=h availability.updated_at.xmlschema %></published> - <updated><%=h availability.updated_at.xmlschema %></updated> - <id>http://availabletopair.com/<%=h availability.id %>/<%=h availability.updated_at.xmlschema %></id> + <published><%= pairs_updated(availability).xmlschema %></published> + <updated><%= pairs_updated(availability).xmlschema %></updated> + <id>http://availabletopair.com/<%=h availability.id %>/<%=h pairs_updated(availability).xmlschema %></id> <content type="html"> <![CDATA[ <% if availability.pairs.length == 0 %> No developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. <% else %> The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: <ul> <% availability.pairs.each do |pair| %> - <li><%=h display_duration(pair) %> from <%=h display_when_time(pair) %> - <%= h pair.developer %> on <%=h display_project(pair) %></li> + <li><%=h display_duration(pair) %> from <%=h display_when_time(pair) %> - <%= h pair.developer %> on <%=h display_project(pair) %> (updated: <%= display_date_time(pair.updated_at)%>)</li> <% end %> </ul> <% end %> ]]> </content> </entry><% end %> </feed> diff --git a/config/database.yml b/config/database.yml index d8a5506..47bb8be 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,51 +1,53 @@ # MySQL. Versions 4.1 and 5.0 are recommended. # # Install the MySQL driver: # gem install mysql # On Mac OS X: # sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql # On Mac OS X Leopard: # sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config # This sets the ARCHFLAGS environment variable to your native architecture # On Windows: # gem install mysql # Choose the win32 build. # Install MySQL and put its /bin directory on your path. # # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html development: adapter: mysql encoding: utf8 reconnect: false database: AvailableToPair_development pool: 5 username: root password: asdf host: localhost # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: &TEST adapter: mysql encoding: utf8 reconnect: false database: AvailableToPair_test pool: 5 username: root password: asdf host: localhost production: adapter: mysql encoding: utf8 reconnect: false database: AvailableToPair_production pool: 5 username: root password: asdf host: localhost +cucumber: + <<: *TEST cucumber: <<: *TEST \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index 1de8437..31cc804 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,41 +1,42 @@ # Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') + Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs # config.load_paths += %W( #{RAILS_ROOT}/extras ) # Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "sqlite3-ruby", :lib => "sqlite3" # config.gem "aws-s3", :lib => "aws/s3" # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. config.time_zone = 'UTC' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de end \ No newline at end of file diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index b5ef6c2..7fc9dd2 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -1,26 +1,26 @@ -# IMPORTANT: This file was generated by Cucumber 0.4.0 +# IMPORTANT: This file was generated by Cucumber 0.4.2 # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. config.cache_classes = true # This must be true for Cucumber to operate correctly! # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test -config.gem 'cucumber', :lib => false, :version => '>=0.4.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) +config.gem 'cucumber', :lib => false, :version => '>=0.4.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) config.gem 'webrat', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) config.gem 'rspec', :lib => false, :version => '>=1.2.8' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) config.gem 'rspec-rails', :lib => false, :version => '>=1.2.7.1' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) diff --git a/db/migrate/20091023022700_create_pairs.rb b/db/migrate/20091023022700_create_pairs.rb new file mode 100644 index 0000000..909d035 --- /dev/null +++ b/db/migrate/20091023022700_create_pairs.rb @@ -0,0 +1,13 @@ +class CreatePairs < ActiveRecord::Migration + def self.up + create_table :pairs do |t| + t.integer :availability_id + t.integer :available_pair_id + t.timestamps + end + end + + def self.down + drop_table :pairs + end +end diff --git a/db/migrate/20091023023000_add_pairs_indexes.rb b/db/migrate/20091023023000_add_pairs_indexes.rb new file mode 100644 index 0000000..f5c0b9a --- /dev/null +++ b/db/migrate/20091023023000_add_pairs_indexes.rb @@ -0,0 +1,9 @@ +class AddPairsIndexes < ActiveRecord::Migration + def self.up + add_index :pairs, [:availability_id], {:name => "pairs_availability_id_index"} + end + + def self.down + remove_index :pairs, "pairs_availability_id_index" + end +end diff --git a/db/migrate/20091023114300_amend_pairs_add_developer.rb b/db/migrate/20091023114300_amend_pairs_add_developer.rb new file mode 100644 index 0000000..e270bbc --- /dev/null +++ b/db/migrate/20091023114300_amend_pairs_add_developer.rb @@ -0,0 +1,9 @@ +class AmendPairsAddDeveloper < ActiveRecord::Migration + def self.up + add_column :pairs, :developer, :string + end + + def self.down + remove_column :availabilities, :developer + end +end diff --git a/db/migrate/20091023114700_amend_pairs_add_project.rb b/db/migrate/20091023114700_amend_pairs_add_project.rb new file mode 100644 index 0000000..10b9025 --- /dev/null +++ b/db/migrate/20091023114700_amend_pairs_add_project.rb @@ -0,0 +1,9 @@ +class AmendPairsAddProject < ActiveRecord::Migration + def self.up + add_column :pairs, :project, :string + end + + def self.down + remove_column :availabilities, :project + end +end diff --git a/db/migrate/20091023151017_add_open_id_authentication_tables.rb b/db/migrate/20091023151017_add_open_id_authentication_tables.rb new file mode 100644 index 0000000..caae0d8 --- /dev/null +++ b/db/migrate/20091023151017_add_open_id_authentication_tables.rb @@ -0,0 +1,20 @@ +class AddOpenIdAuthenticationTables < ActiveRecord::Migration + def self.up + create_table :open_id_authentication_associations, :force => true do |t| + t.integer :issued, :lifetime + t.string :handle, :assoc_type + t.binary :server_url, :secret + end + + create_table :open_id_authentication_nonces, :force => true do |t| + t.integer :timestamp, :null => false + t.string :server_url, :null => true + t.string :salt, :null => false + end + end + + def self.down + drop_table :open_id_authentication_associations + drop_table :open_id_authentication_nonces + end +end diff --git a/db/migrate/20091023225800_amend_pairs_add_start_and_end_time.rb b/db/migrate/20091023225800_amend_pairs_add_start_and_end_time.rb new file mode 100644 index 0000000..ef9dc95 --- /dev/null +++ b/db/migrate/20091023225800_amend_pairs_add_start_and_end_time.rb @@ -0,0 +1,11 @@ +class AmendPairsAddStartAndEndTime < ActiveRecord::Migration + def self.up + add_column :pairs, :start_time, :datetime + add_column :pairs, :end_time, :datetime + end + + def self.down + remove_column :availabilities, :start_time + remove_column :availabilities, :end_time + end +end diff --git a/db/migrate/20091023233000_amend_pairs_add_contact.rb b/db/migrate/20091023233000_amend_pairs_add_contact.rb new file mode 100644 index 0000000..237ef09 --- /dev/null +++ b/db/migrate/20091023233000_amend_pairs_add_contact.rb @@ -0,0 +1,9 @@ +class AmendPairsAddContact < ActiveRecord::Migration + def self.up + add_column :pairs, :contact, :string + end + + def self.down + remove_column :availabilities, :contact + end +end diff --git a/db/schema.rb b/db/schema.rb index d09acc1..189d2d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,36 +1,56 @@ # This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20091016171300) do +ActiveRecord::Schema.define(:version => 20091023233000) do create_table "availabilities", :force => true do |t| t.string "developer" t.datetime "start_time" t.datetime "end_time" t.string "contact" t.datetime "created_at" t.datetime "updated_at" t.string "project" end add_index "availabilities", ["developer", "start_time", "end_time"], :name => "availabilities_pair_search_index" add_index "availabilities", ["developer"], :name => "availabilities_name_index" - create_table "possible_pairs", :id => false, :force => true do |t| - t.integer "availability1", :default => 0, :null => false - t.integer "availability2", :default => 0, :null => false - t.string "dev1" - t.string "dev2" + create_table "open_id_authentication_associations", :force => true do |t| + t.integer "issued" + t.integer "lifetime" + t.string "handle" + t.string "assoc_type" + t.binary "server_url" + t.binary "secret" + end + + create_table "open_id_authentication_nonces", :force => true do |t| + t.integer "timestamp", :null => false + t.string "server_url" + t.string "salt", :null => false + end + + create_table "pairs", :force => true do |t| + t.integer "availability_id" + t.integer "available_pair_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "developer" + t.string "project" t.datetime "start_time" t.datetime "end_time" + t.string "contact" end + add_index "pairs", ["availability_id"], :name => "pairs_availability_id_index" + end diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 2f9f397..d0d7f84 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,192 +1,174 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00:(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on curb \(updated: [^\)]*\)(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb \(updated: [^\)]*\)| Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id - Scenario: Multiple availabilities are ordered by latest of pair updated and availability updated + Scenario: Multiple availabilities are ordered by latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | - And I visit "/JeffGarlin.atom" + And I visit "/JeffGarlin.atom" When I reduce the end time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - When I touch the availability at position 2 of the feed - And visit "/LarryDavid.atom" again - Then I should see the following feed entries: - | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - When I extend the start time of the availability at position 1 of the feed by 1 min - And visit "/LarryDavid.atom" again - Then I should see the following feed entries: - | title | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/JeffGarlin.atom" When I extend the end time of the availability at position 1 of the feed by 1 min And I reduce the start time of the availability at position 1 of the feed by 1 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - Scenario: Multiple availabilities have feed updated date as latest of pair updated and availability updated + Scenario: Multiple availabilities have feed updated date as latest pair updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | - | JeffGarlin | curb | December 13, 2019 21:00 | December 13, 2019 22:00 | http://github.com/LarryDavid | - | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 22:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 21:59 | December 13, 2019 23:00 | http://github.com/LarryDavid | + | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 23:00 | http://github.com/LarryDavid | When I visit "/JeffGarlin.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | And the feed should show as updated at the published time of the entry at position 1 When I visit "/LarryCharles.atom" And I extend the start time of the availability at position 1 of the feed by 10 min And visit "/LarryDavid.atom" Then I should see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - Then the feed should show as updated at the published time of the entry at position 1 - When I touch the availability at position 2 of the feed - Then I should see the following feed entries: - | title | - | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | - | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | - And the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file + Then the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index 44a098f..65077fd 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,55 +1,55 @@ Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | | Prof Farnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | Scenario: Availabilities with end time in the past should not show Given no availabilities in the system - And the following availabilities in the system with an end time one minute in the past: + And the following availabilities in the system with an end time 2 minutes in the past: | developer | project | - | PhilipJFry | futurama | - And the following availabilities in the system with an end time one minute in the future: + | PhilipJFry | futurama | + And the following availabilities in the system with an end time 2 minutes in the future: | developer | project | | MalcolmTucker | the thick of it | When I am on the list availabilities page Then I should see "MalcolmTucker" But I should not see "PhilipJFry" diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index 1e3fb3a..2c618a7 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,55 +1,55 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first Given only the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | No | http://github.com/LarryDavid | | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 21:30 - 02:30" And I follow "Bender" Then My path should be "/Bender" And I should see "All Bender's availability" Scenario: Availabilities with end time in the past should not show Given no availabilities in the system - And the following availabilities in the system with an end time one minute in the past: + And the following availabilities in the system with an end time 2 minutes in the past: | developer | project | | PhilipJFry | futurama | - And the following availabilities in the system with an end time one minute in the future: + And the following availabilities in the system with an end time 2 minutes in the future: | developer | project | | PhilipJFry | the thick of it | When I visit "/PhilipJFry" Then I should see "the thick of it" But I should not see "futurama" \ No newline at end of file diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index 8d08a2f..ba01f4b 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,71 +1,72 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on anything for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | + | Prof Farnsworth | Futurama | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | - | Prof Farnsworth | anything | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | + Scenario: Show availability shows link to atom feed Given only the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" \ No newline at end of file diff --git a/features/ruby b/features/ruby new file mode 100644 index 0000000..e69de29 diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index 23c93fc..0ea6f9a 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,52 +1,52 @@ Given /^no availabilities in the system$/ do + Pair.delete_all Availability.delete_all end Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| Availability.create(:developer => row[0], :project => row[1], :start_time => row[2], :end_time => row[3], :contact => row[4]) end end -Given /^the following availabilities in the system with an end time one minute in the past:$/ do |table| +Given /^the following availabilities in the system with an end time (\d*) minutes? in the past:$/ do |mins,table| table.rows.each do |row| - Availability.create(:developer => row[0], :project => row[1], :start_time => Time.now - 120, :end_time => Time.now - 60) + a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf', :start_time => Time.now.utc - 120, :end_time => Time.now.utc - (60 * mins.to_i)) end end -Given /^the following availabilities in the system with an end time one minute in the future:$/ do |table| - puts "#{Time.now + 60}" +Given /^the following availabilities in the system with an end time (\d*) minutes? in the future:$/ do |mins,table| table.rows.each do |row| - Availability.create(:developer => row[0], :project => row[1], :start_time => Time.now - 60, :end_time => (Time.now + 60)) + a = Availability.create(:developer => row[0], :project => row[1], :contact => 'asdf',:start_time => Time.now.utc - 60, :end_time => Time.now.utc + (60 * mins.to_i)) end end Then /^I should see the following availabilites listed in order$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 11eccf7..a0125dd 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,139 +1,143 @@ When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end Then /^My path should be "([^\"]*)"$/ do |path| URI.parse(current_url).path.should == path end Then /^I (?:should )?see the following feed entries:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) end end Then /^I should see the following feed entries with content:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) content = entry.xpath("xmlns:content").text content_html = Nokogiri::HTML(content) content_html.text.should =~ /#{table.rows[index][1]}/ end end Then /^The only entry's content should link to availability page from time period$/ do doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') only_availability = Availability.find(:all)[0] expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")}" content = entries[0].xpath("xmlns:content").text content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) end Then /^the feed should have the following properties:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) end end Then /^the feed should have the following links:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") link.length.should eql(1) link.xpath("@rel").text.should eql(row[1]) end end Then /^the feed should have the following text nodes:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath(row[0]).text.should eql(row[1]) end end When /check the published date of the feed entry at position (\d*)$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should_not eql("") @published_dates ||= {} @published_dates[entry_position] = Time.parse(published_text) end When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| id = AtomHelper.entry_id(response.body,entry_position) sleep 1 # to make sure the new updated_at is different Availability.find(id).touch end Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| published = Time.parse(AtomHelper.published_text(response.body,entry_position)) @published_dates[entry_position].should < published Time.now.should >= published end Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| published_text = AtomHelper.published_text(response.body,entry_position) published_text.should eql(Time.parse(published_text).xmlschema) end Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| doc = Nokogiri::XML(response.body) published = AtomHelper.published_text(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:updated").text.should eql (published) end Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) end Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) end Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| doc = Nokogiri::XML(response.body) id = AtomHelper.entry_id(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) end Then /^I reduce the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time -= (extend_by.to_i * 60) + sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.end_time += (extend_by.to_i * 60) + sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I reduce the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time -= (extend_by.to_i * 60) + sleep 2 #make sure the updated_at is changed availabilty.save end Then /^I extend the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| id = AtomHelper.entry_id(response.body,entry_position) availabilty = Availability.find(id) availabilty.start_time += (extend_by.to_i * 60) + sleep 2 #make sure the updated_at is changed availabilty.save end \ No newline at end of file diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb index 0cd7e41..6a36d65 100644 --- a/features/step_definitions/webrat_steps.rb +++ b/features/step_definitions/webrat_steps.rb @@ -1,189 +1,189 @@ -# IMPORTANT: This file was generated by Cucumber 0.4.0 +# IMPORTANT: This file was generated by Cucumber 0.4.2 # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. # Consider adding your own code to a new file instead of editing this one. require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) # Commonly used webrat steps # http://github.com/brynary/webrat Given /^I am on (.+)$/ do |page_name| visit path_to(page_name) end When /^I go to (.+)$/ do |page_name| visit path_to(page_name) end When /^I press "([^\"]*)"$/ do |button| click_button(button) end When /^I follow "([^\"]*)"$/ do |link| click_link(link) end When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent| click_link_within(parent, link) end When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| fill_in(field, :with => value) end When /^I fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field| fill_in(field, :with => value) end # Use this to fill in an entire form with data from a table. Example: # # When I fill in the following: # | Account Number | 5002 | -# | Expiry date | 2019-11-01 | +# | Expiry date | 2009-11-01 | # | Note | Nice guy | # | Wants Email? | | # # TODO: Add support for checkbox, select og option # based on naming conventions. # When /^I fill in the following:$/ do |fields| fields.rows_hash.each do |name, value| When %{I fill in "#{name}" with "#{value}"} end end When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field| select(value, :from => field) end # Use this step in conjunction with Rail's datetime_select helper. For example: # When I select "December 25, 2008 10:00" as the date and time When /^I select "([^\"]*)" as the date and time$/ do |time| select_datetime(time) end # Use this step when using multiple datetime_select helpers on a page or # you want to specify which datetime to select. Given the following view: # <%= f.label :preferred %><br /> # <%= f.datetime_select :preferred %> # <%= f.label :alternative %><br /> # <%= f.datetime_select :alternative %> # The following steps would fill out the form: # When I select "November 23, 2004 11:20" as the "Preferred" date and time # And I select "November 25, 2004 10:30" as the "Alternative" date and time When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label| select_datetime(datetime, :from => datetime_label) end # Use this step in conjunction with Rail's time_select helper. For example: # When I select "2:20PM" as the time # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat # will convert the 2:20PM to 14:20 and then select it. When /^I select "([^\"]*)" as the time$/ do |time| select_time(time) end # Use this step when using multiple time_select helpers on a page or you want to # specify the name of the time on the form. For example: # When I select "7:30AM" as the "Gym" time When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label| select_time(time, :from => time_label) end # Use this step in conjunction with Rail's date_select helper. For example: # When I select "February 20, 1981" as the date When /^I select "([^\"]*)" as the date$/ do |date| select_date(date) end # Use this step when using multiple date_select helpers on one page or # you want to specify the name of the date on the form. For example: # When I select "April 26, 1982" as the "Date of Birth" date When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label| select_date(date, :from => date_label) end When /^I check "([^\"]*)"$/ do |field| check(field) end When /^I uncheck "([^\"]*)"$/ do |field| uncheck(field) end When /^I choose "([^\"]*)"$/ do |field| choose(field) end When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field| attach_file(field, path) end Then /^I should see "([^\"]*)"$/ do |text| response.should contain(text) end Then /^I should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| within(selector) do |content| content.should contain(text) end end Then /^I should see \/([^\/]*)\/$/ do |regexp| regexp = Regexp.new(regexp) response.should contain(regexp) end Then /^I should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| within(selector) do |content| regexp = Regexp.new(regexp) content.should contain(regexp) end end Then /^I should not see "([^\"]*)"$/ do |text| response.should_not contain(text) end Then /^I should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| within(selector) do |content| content.should_not contain(text) end end Then /^I should not see \/([^\/]*)\/$/ do |regexp| regexp = Regexp.new(regexp) response.should_not contain(regexp) end Then /^I should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| within(selector) do |content| regexp = Regexp.new(regexp) content.should_not contain(regexp) end end Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should =~ /#{value}/ end Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should_not =~ /#{value}/ end Then /^the "([^\"]*)" checkbox should be checked$/ do |label| field_labeled(label).should be_checked end Then /^the "([^\"]*)" checkbox should not be checked$/ do |label| field_labeled(label).should_not be_checked end Then /^I should be on (.+)$/ do |page_name| URI.parse(current_url).path.should == path_to(page_name) end Then /^show me the page$/ do save_and_open_page end \ No newline at end of file diff --git a/features/support/atom_helper.rb b/features/support/atom_helper.rb index f867b27..9c8611b 100644 --- a/features/support/atom_helper.rb +++ b/features/support/atom_helper.rb @@ -1,16 +1,16 @@ class AtomHelper def self.entry_id(xml,entry_position) - AtomHelper.load(xml).xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text + link = AtomHelper.load(xml).xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text /(\d*)$/.match(link)[0] end def self.published_text(xml,entry_position) AtomHelper.load(xml).xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text end def self.load(xml) xml.respond_to?("xpath") ? xml : Nokogiri::XML(xml) end end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 9c5340c..d2117f4 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,48 +1,47 @@ -# IMPORTANT: This file was generated by Cucumber 0.4.0 +# IMPORTANT: This file was generated by Cucumber 0.4.2 # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. # Consider adding your own code to a new file instead of editing this one. # Sets up the Rails environment for Cucumber ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' # If you set this to true, each scenario will run in a database transaction. # You can still turn off transactions on a per-scenario basis, simply tagging # a feature or scenario with the @no-txn tag. # # If you set this to false, transactions will be off for all scenarios, # regardless of whether you use @no-txn or not. # # Beware that turning transactions off will leave data in your database # after each scenario, which can lead to hard-to-debug failures in # subsequent scenarios. If you do this, we recommend you create a Before # block that will explicitly put your database in a known state. Cucumber::Rails::World.use_transactional_fixtures = true # If you set this to false, any error raised from within your app will bubble # up to your step definition and out to cucumber unless you catch it somewhere # on the way. You can make Rails rescue errors and render error pages on a # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. # # If you set this to true, Rails will rescue all errors and render error # pages, more or less in the same way your application would behave in the # default production environment. It's not recommended to do this for all # of your scenarios, as this makes it hard to discover errors in your application. ActionController::Base.allow_rescue = false require 'cucumber' # Comment out the next line if you don't want Cucumber Unicode support require 'cucumber/formatter/unicode' require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table) require 'cucumber/rails/rspec' - require 'webrat' require 'webrat/core/matchers' Webrat.configure do |config| config.mode = :rails config.open_error_files = false # Set to true if you want error pages to pop up in the browser end diff --git a/features/support/paths.rb b/features/support/paths.rb index 088cea0..dcaf67e 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -1,29 +1,29 @@ module NavigationHelpers # Maps a name to a path. Used by the # # When /^I go to (.+)$/ do |page_name| # # step definition in webrat_steps.rb # def path_to(page_name) case page_name - + when /the home\s?page/ '/' when /the list availabilities page/ '/availabilities' # Add more mappings here. # Here is a more fancy example: # # when /^(.*)'s profile page$/i # user_profile_path(User.find_by_login($1)) else raise "Can't find mapping from \"#{page_name}\" to a path.\n" + "Now, go and add a mapping in #{__FILE__}" end end end World(NavigationHelpers) diff --git a/features/support/version_check.rb b/features/support/version_check.rb index 7245c94..57439d7 100644 --- a/features/support/version_check.rb +++ b/features/support/version_check.rb @@ -1,29 +1,29 @@ -if Cucumber::VERSION::STRING != '0.4.0' +if Cucumber::VERSION != '0.4.2' warning = <<-WARNING (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) R O T T E N C U C U M B E R A L E R T (::) -Your #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} file was generated with Cucumber 0.4.0, -but you seem to be running Cucumber #{Cucumber::VERSION::STRING}. If you're running an older -version than #{Cucumber::VERSION::STRING}, just upgrade your gem. If you're running a newer -version than #{Cucumber::VERSION::STRING} you should: +Your #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} file was generated with Cucumber 0.4.2, +but you seem to be running Cucumber #{Cucumber::VERSION}. If you're running an older +version than #{Cucumber::VERSION}, just upgrade your gem. If you're running a newer +version than #{Cucumber::VERSION} you should: 1) Read http://wiki.github.com/aslakhellesoy/cucumber/upgrading 2) Regenerate your cucumber environment with the following command: ruby script/generate cucumber If you get prompted to replace a file, hit 'd' to see the difference. When you're sure you have captured any personal edits, confirm that you want to overwrite #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} by pressing 'y'. Then reapply any personal changes that may have been overwritten. This message will then self destruct. (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) WARNING warn(warning) at_exit {warn(warning)} end \ No newline at end of file diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index 6d7f8bc..9cab97a 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,71 +1,60 @@ require 'spec_helper' describe Availability do - it "should find pairs as matching availabilities for different developers where times overlap" do - availability = Availability.new(:start_time => Time.now,:end_time => Time.now) - availability.developer = "currentDev" - expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] - Availability.stub!(:find).with(:all, - :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", - {:developer => availability.developer, - :start_time => availability.start_time, - :end_time => availability.end_time}]).and_return(expected_pairs) - - actual_pairs = availability.pairs - - actual_pairs.should be(expected_pairs) + describe "when the start and end time are within the same day" do + + it "should calculate the duration as the difference between the end and start times in seconds" do + start_time = Time.parse("2009-11-15 09:00") + end_time = Time.parse("2009-11-15 17:35") + + duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec + + duration_sec.should eql(end_time - start_time) + end end - describe "when a project has been specified" do + describe "when the start and end time cross two days" do - it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do - availability = Availability.new(:start_time => Time.now,:end_time => Time.now) - availability.developer = "currentDev" - availability.project = "some proj" - expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] - Availability.stub!(:find).with(:all, - :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", - {:developer => availability.developer, - :start_time => availability.start_time, - :end_time => availability.end_time, - :project => availability.project}]).and_return(expected_pairs) + it "should calculate the duration as the difference between the end and start times" do + start_time = Time.parse("2009-11-15 22:00") + end_time = Time.parse("2009-11-15 00:15") - actual_pairs = availability.pairs + duration_sec = Availability.new(:start_time => start_time, :end_time => end_time).duration_sec - actual_pairs.should be(expected_pairs) + duration_sec.should eql(end_time - start_time) end end - it "should set the start time of each pair to the later of the two start times" do - availability = Availability.new(:start_time => Time.parse("2012-06-01 15:25"),:end_time => Time.now) + describe "when saving" do - pair_1 = Availability.new(:start_time => Time.parse("2012-06-01 15:26"),:end_time => Time.now) - pair_2 = Availability.new(:start_time => Time.parse("2012-06-01 15:24"),:end_time => Time.now) - expected_pairs = [pair_1,pair_2] + it "should sync pairs" do + availability = Availability.new - Availability.stub!(:find).and_return(expected_pairs) + pair_synchronizer = mock(:pair_synchronizer) + pair_synchronizer.should_receive(:synchronize_pairs).with(availability) - actual_pairs = availability.pairs + availability.pair_synchronizer = pair_synchronizer + + availability.save + end - actual_pairs[0].start_time.should be (pair_1.start_time) - actual_pairs[1].start_time.should be (availability.start_time) end - it "should set the end time of each pair to the earlier of the two end times" do - availability = Availability.new(:end_time => Time.parse("2012-06-01 15:25"),:start_time => Time.now) + describe "when destroying" do - pair_1 = Availability.new(:end_time => Time.parse("2012-06-01 15:24"),:start_time => Time.now) - pair_2 = Availability.new(:end_time => Time.parse("2012-06-01 15:26"),:start_time => Time.now) + it "should sync pairs" do - expected_pairs = [pair_1,pair_2] + availability = Availability.new - Availability.stub!(:find).and_return(expected_pairs) + pair_synchronizer = mock(:pair_synchronizer) + pair_synchronizer.should_receive(:synchronize_pairs).with(availability) - actual_pairs = availability.pairs + availability.pair_synchronizer = pair_synchronizer + + availability.destroy + end - actual_pairs[0].end_time.should be (pair_1.end_time) - actual_pairs[1].end_time.should be (availability.end_time) end end diff --git a/spec/models/pair_matcher_spec.rb b/spec/models/pair_matcher_spec.rb new file mode 100644 index 0000000..51af0f5 --- /dev/null +++ b/spec/models/pair_matcher_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe PairMatcher do + + it "should find pairs as matching availabilities for different developers where times overlap" do + availability = Availability.new(:start_time => Time.now,:end_time => Time.now) + availability.developer = "currentDev" + expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] + Availability.stub!(:find).with(:all, + :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", + {:developer => availability.developer, + :start_time => availability.start_time, + :end_time => availability.end_time}]).and_return(expected_pairs) + + actual_pairs = PairMatcher.new.find_pairs(availability) + + actual_pairs.should be(expected_pairs) + end + + describe "when a project has been specified" do + + it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do + availability = Availability.new(:start_time => Time.now,:end_time => Time.now) + availability.developer = "currentDev" + availability.project = "some proj" + expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] + Availability.stub!(:find).with(:all, + :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", + {:developer => availability.developer, + :start_time => availability.start_time, + :end_time => availability.end_time, + :project => availability.project}]).and_return(expected_pairs) + + actual_pairs = PairMatcher.new.find_pairs(availability) + + actual_pairs.should be(expected_pairs) + end + end + +end + diff --git a/spec/models/pair_repository_spec.rb b/spec/models/pair_repository_spec.rb new file mode 100644 index 0000000..45cf928 --- /dev/null +++ b/spec/models/pair_repository_spec.rb @@ -0,0 +1,137 @@ +require 'spec_helper' + +describe PairRepository do + master_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) + pair_availability = Availability.new(:start_time => Time.now, :end_time => Time.now) + + describe "when creating a pair" do + + it "should set availability_id as master id and available_to_pair id as pair id" do + master_availability.id = 543 + pair_availability.id = 654 + + pair = PairRepository.new.create(master_availability,pair_availability) + + pair.availability_id.should eql(master_availability.id) + pair.available_pair_id.should eql(pair_availability.id) + end + + it "should set developer as pair developer" do + master_availability.developer = "masterdev" + pair_availability.developer = "pairdev" + + pair = PairRepository.new.create(master_availability,pair_availability) + + pair.developer.should eql pair_availability.developer + end + + it "should set contact as pair contact" do + master_availability.contact = "master@xp.com" + pair_availability.contact = "pair@xp.com" + + pair = PairRepository.new.create(master_availability,pair_availability) + + pair.contact.should eql pair_availability.contact + end + + describe "and the start time of the pair is later than that of the master" do + + before do + master_availability.start_time = Time.parse("2012-06-01 15:25") + pair_availability.start_time = Time.parse("2012-06-01 15:26") + end + + it "should use the pair's start time" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.start_time.should be (pair_availability.start_time) + end + + end + + describe "and the start time of the pair is earlier than that of the master" do + + before do + master_availability.start_time = Time.parse("2012-06-01 15:26") + pair_availability.start_time = Time.parse("2012-06-01 15:25") + end + + it "should use the master's start time" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.start_time.should be (master_availability.start_time) + end + + end + + describe "and the end time of the pair is later than that of the master" do + + before do + master_availability.end_time = Time.parse("2012-06-01 15:25") + pair_availability.end_time = Time.parse("2012-06-01 15:26") + end + + it "should use the masters's end time" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.end_time.should be (master_availability.end_time) + end + + end + + describe "and the end time of the pair is earlier than that of the master" do + + before do + master_availability.end_time = Time.parse("2012-06-01 15:26") + pair_availability.end_time = Time.parse("2012-06-01 15:25") + end + + it "should use the pair's end time" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.end_time.should be (pair_availability.end_time) + end + + end + + describe "and a project is not specified on either" do + + before do + master_availability.project = nil + pair_availability.project = nil + end + + it "should set the project nil" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.project.should eql nil + end + + end + + describe "and a project is specified on the master only" do + + before do + master_availability.project = "someProj" + pair_availability.project = nil + end + + it "should use the master's project" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.project.should eql(master_availability.project) + end + + end + + describe "and a project is specified on the pair" do + + before do + master_availability.project = nil + pair_availability.project = "someProj" + end + + it "should use the pair's project" do + pair = PairRepository.new.create(master_availability,pair_availability) + pair.project.should eql(pair_availability.project) + end + end + + end + +end + diff --git a/spec/models/pair_synchronizer_spec.rb b/spec/models/pair_synchronizer_spec.rb new file mode 100644 index 0000000..29b3005 --- /dev/null +++ b/spec/models/pair_synchronizer_spec.rb @@ -0,0 +1,144 @@ +require 'spec_helper' + +describe PairSynchronizer do + + describe "when syncing pairs" do + + describe "when there is a single new availability" do + + availability = Availability.new + matching_availabilities = [] + existing_pairs = [] + + before do + + availability.id = 321 + matching_availabilities = create_test_availabilities([5]) + existing_pairs = [] + + Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return([]) + + end + + it "should create two pairs for the new match, one in each direction" do + + pair_matcher = mock(:pair_matcher) + pair_repository = mock(:pair_matcher) + pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) + + pair_repository.should_receive(:create).with(availability,matching_availabilities[0]) + pair_repository.should_receive(:create).with(matching_availabilities[0],availability) + + PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) + end + end + + describe "when there some existing and some new availabilities" do + + availability = Availability.new + matching_availabilities = [] + existing_pairs = [] + + before do + + availability.id = 321 + matching_availabilities = create_test_availabilities([5,6,7,8]) + + existing_pairs = [stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[0].id), + stub(:availability_id => matching_availabilities[0].id, :available_pair_id => availability.id), + stub(:availability_id => availability.id, :available_pair_id => matching_availabilities[2].id), + stub(:availability_id => matching_availabilities[2].id, :available_pair_id => availability.id)] + + Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) + + end + + it "should create any matching pair that doesn't exist" do + + pair_matcher = mock(:pair_matcher) + pair_repository = mock(:pair_matcher) + pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) + + pair_repository.should_receive(:create).with(availability,matching_availabilities[1]) + pair_repository.should_receive(:create).with(matching_availabilities[1],availability) + pair_repository.should_receive(:create).with(availability,matching_availabilities[3]) + pair_repository.should_receive(:create).with(matching_availabilities[3],availability) + + pair_repository.stub!(:update) + + PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) + + end + + it "should update the existing availabilities" do + + pair_matcher = mock(:pair_matcher) + pair_repository = mock(:pair_matcher) + pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) + + pair_repository.should_receive(:update).with(existing_pairs[0],availability,matching_availabilities[0]) + pair_repository.should_receive(:update).with(existing_pairs[1],matching_availabilities[0],availability) + pair_repository.should_receive(:update).with(existing_pairs[2],availability,matching_availabilities[2]) + pair_repository.should_receive(:update).with(existing_pairs[3],matching_availabilities[2],availability) + + pair_repository.stub!(:create) + + PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) + + end + + end + + describe "when there are missing availabilities" do + + availability = Availability.new + matching_availabilities = [] + existing_pairs = [] + + before do + + availability.id = 321 + matching_availabilities = create_test_availabilities([5]) + + existing_pairs = [mock(:id => 99, :availability_id => availability.id, :available_pair_id => 5), + mock(:id => 98, :availability_id => 5, :available_pair_id => availability.id), + mock(:id => 97,:availability_id => availability.id, :available_pair_id => 102), + mock(:id => 96,:availability_id => 102, :available_pair_id => availability.id), + mock(:id => 95,:availability_id => availability.id, :available_pair_id => 103), + mock(:id => 94,:availability_id => 103, :available_pair_id => availability.id)] + + Pair.stub!(:find).with(:all, :conditions => ["availability_id = :availability_id or available_pair_id = :available_pair_id", {:availability_id => availability.id, :available_pair_id => availability.id}]).and_return(existing_pairs) + + end + + it "should destroy the missing pairs" do + + pair_matcher = mock(:pair_matcher) + pair_repository = mock(:pair_matcher) + pair_matcher.stub!(:find_pairs).with(availability).and_return(matching_availabilities) + + existing_pairs[2].should_receive(:destroy) + existing_pairs[3].should_receive(:destroy) + existing_pairs[4].should_receive(:destroy) + existing_pairs[5].should_receive(:destroy) + + pair_repository.stub!(:create) + pair_repository.stub!(:update) + + PairSynchronizer.new(pair_matcher,pair_repository).synchronize_pairs(availability) + + end + end + end + +end + +def create_test_availabilities(ids) + availabilities = [] + ids.each do |id| + availability = Availability.new + availability.id = id + availabilities.push availability + end + availabilities +end
adiel/availabletopair
bb187ac5c91bdfaf17aaf7fea1ed0e3f7030cbfe
Refactoring of cucumber steps for atom feed
diff --git a/app/controllers/availabilities_controller.rb b/app/controllers/availabilities_controller.rb index f9b1ebc..9ef0860 100644 --- a/app/controllers/availabilities_controller.rb +++ b/app/controllers/availabilities_controller.rb @@ -1,87 +1,85 @@ class AvailabilitiesController < ApplicationController # GET /availabilities # GET /availabilities.xml def index - @availabilities = Availability.find(:all, - :order => "start_time", - :conditions => ["end_time > :end_time",{:end_time => Time.now.getgm}]) + @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["end_time > :end_time",{:end_time => Time.now.getgm}]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availabilities } end end # GET /availabilities/1 # GET /availabilities/1.xml def show @availability = Availability.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/new # GET /availabilities/new.xml def new @availability = Availability.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/1/edit def edit @availability = Availability.find(params[:id]) end # POST /availabilities # POST /availabilities.xml def create @availability = Availability.new(params[:availability]) respond_to do |format| if @availability.save flash[:notice] = 'Availability was successfully created.' format.html { redirect_to(@availability) } format.xml { render :xml => @availability, :status => :created, :location => @availability } else format.html { render :action => "new" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # PUT /availabilities/1 # PUT /availabilities/1.xml def update @availability = Availability.find(params[:id]) respond_to do |format| if @availability.update_attributes(params[:availability]) flash[:notice] = 'Availability was successfully updated.' format.html { redirect_to(@availability) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # DELETE /availabilities/1 # DELETE /availabilities/1.xml def destroy @availability = Availability.find(params[:id]) @availability.destroy respond_to do |format| format.html { redirect_to(availabilities_url) } format.xml { head :ok } end end end diff --git a/app/models/availability.rb b/app/models/availability.rb index 3738aea..2a925d5 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,35 +1,39 @@ class Availability < ActiveRecord::Base + def initialize(availability = nil) + super + end + def pairs @pairs ||= find_pairs @pairs end def find_pairs conditions = "developer != :developer and start_time < :end_time and end_time > :start_time" condition_values = {:developer => developer, :start_time => start_time, :end_time => end_time} if project.to_s != "" conditions += " and (project = :project or project = '')" condition_values[:project] = project end pair_conditions = [conditions, condition_values] pairs = Availability.find(:all, :conditions => pair_conditions) set_intersecting_start_and_end_times!(pairs) end def set_intersecting_start_and_end_times!(pairs) pairs.each do |pair| pair.start_time = pair.start_time > start_time ? pair.start_time : start_time pair.end_time = pair.end_time < end_time ? pair.end_time : end_time end pairs end def duration_sec end_time - start_time end end diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index bba7f98..56db48c 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,28 +1,30 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> + <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> <td><%= link_to(h(availability.developer), "/" + h(availability.developer)) %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> + <td><%= display_date_time(availability.updated_at) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index bfeb565..246c969 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,34 +1,36 @@ <h1><%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span> | <%= link_to 'Edit', edit_availability_path(@availability) %></h1> <% if @availability.pairs.length == 0 %> <p> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> over this period. </p> <% else %> <p> Available to pair with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %>: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> + <th>Updated</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> <td><%= link_to(h(pair.developer),"/" + h(pair.developer)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> + <td><%= display_date_time(pair.updated_at) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> <p>Subscribe to updates of <%=h @availability.developer %>'s available pairs (<a href="/<%=h @availability.developer%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 6c6a513..e5267d7 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,28 +1,30 @@ <h1>All <%= user %>'s availability</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> + <th>Updated</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> <td><%=h availability.developer %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> + <td><%= display_date_time(availability.updated_at) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> <p>Subscribe to updates of <%=user %>'s available pairs (<a href="/<%=user%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 3dcca7d..2f9f397 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,122 +1,192 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00. | Scenario: When no pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | Scenario: Single availability with no pairs shows published as updated_at of availability Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | Scenario: Multiple availabilities have feed updated date as last updated Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given only the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id + Scenario: Multiple availabilities are ordered by latest of pair updated and availability updated + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | + And I visit "/JeffGarlin.atom" + When I reduce the end time of the availability at position 1 of the feed by 1 min + And visit "/LarryDavid.atom" + Then I should see the following feed entries: + | title | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + When I touch the availability at position 2 of the feed + And visit "/LarryDavid.atom" again + Then I should see the following feed entries: + | title | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + When I extend the start time of the availability at position 1 of the feed by 1 min + And visit "/LarryDavid.atom" again + Then I should see the following feed entries: + | title | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + + Scenario: Updates to a pair that do not affect the shared dev time do not affect updated date + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + And I visit "/JeffGarlin.atom" + When I extend the end time of the availability at position 1 of the feed by 1 min + And I reduce the start time of the availability at position 1 of the feed by 1 min + And visit "/LarryDavid.atom" + Then I should see the following feed entries: + | title | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + + Scenario: Multiple availabilities have feed updated date as latest of pair updated and availability updated + Given only the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 21:00 | December 13, 2019 22:00 | http://github.com/LarryDavid | + | LarryCharles | curb | December 14, 2019 21:59 | December 15, 2019 22:00 | http://github.com/LarryDavid | + When I visit "/JeffGarlin.atom" + And I extend the start time of the availability at position 1 of the feed by 10 min + And visit "/LarryDavid.atom" + Then I should see the following feed entries: + | title | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + And the feed should show as updated at the published time of the entry at position 1 + When I visit "/LarryCharles.atom" + And I extend the start time of the availability at position 1 of the feed by 10 min + And visit "/LarryDavid.atom" + Then I should see the following feed entries: + | title | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + Then the feed should show as updated at the published time of the entry at position 1 + When I touch the availability at position 2 of the feed + Then I should see the following feed entries: + | title | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + And the feed should show as updated at the published time of the entry at position 1 \ No newline at end of file diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index baf734a..11eccf7 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,119 +1,139 @@ When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end Then /^My path should be "([^\"]*)"$/ do |path| URI.parse(current_url).path.should == path end Then /^I (?:should )?see the following feed entries:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) end end Then /^I should see the following feed entries with content:$/ do |table| doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') entries.length.should eql(table.rows.length) entries.each_with_index do |entry, index| entry.xpath("xmlns:title").text.should match(table.rows[index][0]) content = entry.xpath("xmlns:content").text content_html = Nokogiri::HTML(content) content_html.text.should =~ /#{table.rows[index][1]}/ end end Then /^The only entry's content should link to availability page from time period$/ do doc = Nokogiri::XML(response.body) entries = doc.xpath('/xmlns:feed/xmlns:entry') only_availability = Availability.find(:all)[0] expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")}" content = entries[0].xpath("xmlns:content").text content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) end Then /^the feed should have the following properties:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) end end Then /^the feed should have the following links:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") link.length.should eql(1) link.xpath("@rel").text.should eql(row[1]) end end Then /^the feed should have the following text nodes:$/ do |table| doc = Nokogiri::XML(response.body) table.rows.each do |row| doc.xpath(row[0]).text.should eql(row[1]) end end When /check the published date of the feed entry at position (\d*)$/ do |entry_position| - doc = Nokogiri::XML(response.body) - published_text = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + published_text = AtomHelper.published_text(response.body,entry_position) published_text.should_not eql("") @published_dates ||= {} @published_dates[entry_position] = Time.parse(published_text) end When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| - doc = Nokogiri::XML(response.body) - link = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text - id = /(\d*)$/.match(link)[0] + id = AtomHelper.entry_id(response.body,entry_position) sleep 1 # to make sure the new updated_at is different Availability.find(id).touch end Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| - doc = Nokogiri::XML(response.body) - published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) + published = Time.parse(AtomHelper.published_text(response.body,entry_position)) @published_dates[entry_position].should < published Time.now.should >= published end Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| - doc = Nokogiri::XML(response.body) - published_text = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + published_text = AtomHelper.published_text(response.body,entry_position) published_text.should eql(Time.parse(published_text).xmlschema) end Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| doc = Nokogiri::XML(response.body) - published = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + published = AtomHelper.published_text(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:updated").text.should eql (published) end Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) - published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) - + published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) end Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| doc = Nokogiri::XML(response.body) - published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) - + published = Time.parse(AtomHelper.published_text(doc,entry_position)) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) end Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| doc = Nokogiri::XML(response.body) - link = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text - id = /(\d*)$/.match(link)[0] + id = AtomHelper.entry_id(doc,entry_position) doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) +end + +Then /^I reduce the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| + id = AtomHelper.entry_id(response.body,entry_position) + availabilty = Availability.find(id) + availabilty.end_time -= (extend_by.to_i * 60) + availabilty.save +end + +Then /^I extend the end time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| + id = AtomHelper.entry_id(response.body,entry_position) + availabilty = Availability.find(id) + availabilty.end_time += (extend_by.to_i * 60) + availabilty.save +end + +Then /^I reduce the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| + id = AtomHelper.entry_id(response.body,entry_position) + availabilty = Availability.find(id) + availabilty.start_time -= (extend_by.to_i * 60) + availabilty.save +end + +Then /^I extend the start time of the availability at position (\d*) of the feed by (\d*) mins?$/ do |entry_position,extend_by| + id = AtomHelper.entry_id(response.body,entry_position) + availabilty = Availability.find(id) + availabilty.start_time += (extend_by.to_i * 60) + availabilty.save end \ No newline at end of file diff --git a/features/support/atom_helper.rb b/features/support/atom_helper.rb new file mode 100644 index 0000000..f867b27 --- /dev/null +++ b/features/support/atom_helper.rb @@ -0,0 +1,16 @@ +class AtomHelper + + def self.entry_id(xml,entry_position) + AtomHelper.load(xml).xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text + /(\d*)$/.match(link)[0] + end + + def self.published_text(xml,entry_position) + AtomHelper.load(xml).xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + end + + def self.load(xml) + xml.respond_to?("xpath") ? xml : Nokogiri::XML(xml) + end + +end \ No newline at end of file
adiel/availabletopair
4eb31ed47f1023ddead91942ad9b8c865146e8c8
Availabilities that have passed their end date should not show.
diff --git a/app/controllers/availabilities_controller.rb b/app/controllers/availabilities_controller.rb index 8ca8392..f9b1ebc 100644 --- a/app/controllers/availabilities_controller.rb +++ b/app/controllers/availabilities_controller.rb @@ -1,85 +1,87 @@ class AvailabilitiesController < ApplicationController # GET /availabilities # GET /availabilities.xml def index - @availabilities = Availability.find(:all, :order => "start_time") + @availabilities = Availability.find(:all, + :order => "start_time", + :conditions => ["end_time > :end_time",{:end_time => Time.now.getgm}]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availabilities } end end # GET /availabilities/1 # GET /availabilities/1.xml def show @availability = Availability.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/new # GET /availabilities/new.xml def new @availability = Availability.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @availability } end end # GET /availabilities/1/edit def edit @availability = Availability.find(params[:id]) end # POST /availabilities # POST /availabilities.xml def create @availability = Availability.new(params[:availability]) respond_to do |format| if @availability.save flash[:notice] = 'Availability was successfully created.' format.html { redirect_to(@availability) } format.xml { render :xml => @availability, :status => :created, :location => @availability } else format.html { render :action => "new" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # PUT /availabilities/1 # PUT /availabilities/1.xml def update @availability = Availability.find(params[:id]) respond_to do |format| if @availability.update_attributes(params[:availability]) flash[:notice] = 'Availability was successfully updated.' format.html { redirect_to(@availability) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @availability.errors, :status => :unprocessable_entity } end end end # DELETE /availabilities/1 # DELETE /availabilities/1.xml def destroy @availability = Availability.find(params[:id]) @availability.destroy respond_to do |format| format.html { redirect_to(availabilities_url) } format.xml { head :ok } end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8e6150e..da8068e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,17 +1,17 @@ class UsersController < ApplicationController layout 'availabilities' # GET /username # GET /username.atom def index @availabilities = Availability.find(:all, :order => "start_time", - :conditions => ["developer = :developer", - {:developer => params[:id]}]) + :conditions => ["developer = :developer and end_time > :end_time" , + {:developer => params[:id],:end_time => Time.now.getgm}]) respond_to do |format| format.html # index.html.erb format.atom do @availabilities.sort! { |a1,a2| a1.updated_at <=> a2.updated_at}.reverse! end end end end diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 301927a..3dcca7d 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,122 +1,122 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | | http://www.example.com/LarryDavid.atom | self | | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | | title | LarryDavid is Available To Pair | | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | PhllilJFry | futurama | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | PhllilJFry | futurama | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00. | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00. | When I visit "/PhllilJFry.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Mon Dec 14, 2009 21:59 - 00:00. | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Sat Dec 14, 2019 21:59 - 00:00. | Scenario: When no pairs are available content should link to availability from datetime - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | - | LarryCharles | | December 13, 2009 23:30 | December 14, 2009 02:00 | http://github.com/LarryCharles | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2019 23:00 | December 14, 2019 01:00 | http://github.com/JeffGarlin | + | LarryCharles | | December 13, 2019 23:30 | December 14, 2019 02:00 | http://github.com/LarryCharles | When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | - | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Fri Dec 13, 2019 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | Scenario: Single availability with no pairs shows published as updated_at of availability - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | - | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | - | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | When I touch the availability at position 2 of the feed And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | - | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | - | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | + | Pairs available for Fri Dec 13, 2019 21:59 - 00:00 | + | Pairs available for Sat Dec 14, 2019 21:59 - 00:00 | Scenario: Multiple availabilities have feed updated date as last updated - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | - | LarryDavid | curb | December 15, 2009 21:59 | December 16, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2019 21:59 | December 15, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 15, 2019 21:59 | December 16, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index 95a08ba..44a098f 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,44 +1,55 @@ -Feature: Register new availability +Feature: List availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | + | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | + | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | - | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | - | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | + | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | + | LarryDavid | curb | December 13, 2019 21:59 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Bender | futurama | Sun Nov 01, 2009 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | - | LarryDavid | curb | Sun Dec 13, 2009 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | - | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | + | Bender | futurama | Fri Nov 01, 2019 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | + | LarryDavid | curb | Fri Dec 13, 2019 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | + | Philip.J.Fry | futurama | Wed Jan 01, 2020 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | Curb | December 13, 2009 21:00 | December 14, 2009 05:00 | http://github.com/larry_david | - | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | - | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | - | Prof Farnsworth | | December 13, 2009 21:15 | December 14, 2009 01:30 | http://github.com/prof_farnsworth | + | LarryDavid | Curb | December 13, 2019 21:00 | December 14, 2019 05:00 | http://github.com/larry_david | + | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | Curb | Sun Dec 13, 2009 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | - | Prof Farnsworth | anything | Sun Dec 13, 2009 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | - | Philip.J.Fry | Futurama | Sun Dec 13, 2009 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | - | Bender | Futurama | Sun Dec 13, 2009 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | + | LarryDavid | Curb | Fri Dec 13, 2019 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | + | Prof Farnsworth | anything | Fri Dec 13, 2019 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | + | Bender | Futurama | Fri Dec 13, 2019 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | + Scenario: Availabilities with end time in the past should not show + Given no availabilities in the system + And the following availabilities in the system with an end time one minute in the past: + | developer | project | + | PhilipJFry | futurama | + And the following availabilities in the system with an end time one minute in the future: + | developer | project | + | MalcolmTucker | the thick of it | + When I am on the list availabilities page + Then I should see "MalcolmTucker" + But I should not see "PhilipJFry" diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index e8a2a8f..1e3fb3a 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,43 +1,55 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | - | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | - | LarryDavid | curb | December 13, 2009 22:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | - | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | Philip.J.Fry | futurama | January 1, 2020 22:00 | January 1, 2020 23:00 | http://github.com/philip_j_fry | + | Bender | futurama | November 1, 2019 22:00 | November 2, 2019 05:00 | http://github.com/Bender | + | LarryDavid | curb | December 13, 2019 22:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | curb | Sun Dec 13, 2009 21:00 - 00:00 | 3h 00m | No | http://github.com/LarryDavid | - | LarryDavid | curb | Sun Dec 13, 2009 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Fri Dec 13, 2019 21:00 - 00:00 | 3h 00m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Fri Dec 13, 2019 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2019 21:00 | December 14, 2019 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | - | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 21:30 - 02:30" + And I follow "Fri Dec 13, 2019 21:30 - 02:30" And I follow "Bender" Then My path should be "/Bender" - And I should see "All Bender's availability" \ No newline at end of file + And I should see "All Bender's availability" + + Scenario: Availabilities with end time in the past should not show + Given no availabilities in the system + And the following availabilities in the system with an end time one minute in the past: + | developer | project | + | PhilipJFry | futurama | + And the following availabilities in the system with an end time one minute in the future: + | developer | project | + | PhilipJFry | the thick of it | + When I visit "/PhilipJFry" + Then I should see "the thick of it" + But I should not see "futurama" \ No newline at end of file diff --git a/features/Register_new_availability.feature b/features/Register_new_availability.feature index 27631d4..a29f041 100644 --- a/features/Register_new_availability.feature +++ b/features/Register_new_availability.feature @@ -1,17 +1,17 @@ Feature: Register new availability In order that anyone looking for a pair knows when I am available As an open source developer I want to publish my availability to pair in advance Scenario: User adds new availability Given no availabilities in the system When I am on the homepage And I follow "Make yourself available" And I fill in "developer" with "aslakhellesoy" And I fill in "project" with "Cucumber" - And I select "December 25, 2009 10:00" as the "Start time" date and time - And I select "December 25, 2009 12:30" as the "End time" date and time + And I select "December 25, 2014 10:00" as the "Start time" date and time + And I select "December 25, 2014 12:30" as the "End time" date and time And I fill in "contact" with "http://github.com/aslakhellesoy" And I press "Publish availability" - Then I should see /aslakhellesoy is available to pair on Cucumber for 2h 30m from Fri Dec 25, 2009 10:00 \- 12:30/ + Then I should see /aslakhellesoy is available to pair on Cucumber for 2h 30m from Thu Dec 25, 2014 10:00 \- 12:30/ diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index d51bfc4..8d08a2f 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,71 +1,71 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | - | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | - | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | - | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | + | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | + | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | + | Bender | | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | Philip.J.Fry | | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 22:00 - 04:30" - Then I should see /Bender is available to pair on anything for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00 - 04:30" + Then I should see /Bender is available to pair on anything for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | anything | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | + | Philip.J.Fry | anything | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | - | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | - | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | - | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | + | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | + | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | + | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00 - 04:30" + Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/philip_j_fry | - | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/bender | - | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | - | Philip.J.Fry | Futurama The Movie | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/larry_david | + | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/philip_j_fry | + | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/bender | + | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | + | Philip.J.Fry | Futurama The Movie | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/larry_david | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00 - 04:30" + Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | - | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | - | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | - | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | - | Prof Farnsworth | | December 13, 2009 21:15 | December 14, 2009 01:30 | http://github.com/prof_farnsworth | + | LarryDavid | Curb | January 1, 2020 11:20 | January 1, 2020 11:30 | http://github.com/larry_david | + | MalcolmTucker | The Thick Of It | December 1, 2019 22:00 | December 1, 2019 22:20 | http://github.com/malcolm_tucker | + | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/bender | + | Philip.J.Fry | Futurama | December 13, 2019 21:30 | December 14, 2019 02:30 | http://github.com/philip_j_fry | + | Prof Farnsworth | | December 13, 2019 21:15 | December 14, 2019 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 22:00 - 04:30" - Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ + And I follow "Fri Dec 13, 2019 22:00 - 04:30" + Then I should see /Bender is available to pair on Futurama for 6h 30m from Fri Dec 13, 2019 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | - | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | - | Prof Farnsworth | anything | Sun Dec 13, 2009 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | + | Philip.J.Fry | Futurama | Fri Dec 13, 2019 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | + | Prof Farnsworth | anything | Fri Dec 13, 2019 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | Scenario: Show availability shows link to atom feed - Given the following availabilities in the system + Given only the following availabilities in the system | developer | project | start time | end time | contact | - | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | + | Bender | Futurama | December 13, 2019 22:00 | December 14, 2019 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page - And I follow "Sun Dec 13, 2009 22:00 - 04:30" + And I follow "Fri Dec 13, 2019 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" Then My path should be "/Bender.atom" \ No newline at end of file diff --git a/features/step_definitions/availability_steps.rb b/features/step_definitions/availability_steps.rb index 1e1ab4e..23c93fc 100644 --- a/features/step_definitions/availability_steps.rb +++ b/features/step_definitions/availability_steps.rb @@ -1,38 +1,52 @@ Given /^no availabilities in the system$/ do Availability.delete_all end -Given /^the following availabilities in the system$/ do |table| +Given /^only the following availabilities in the system$/ do |table| Given "no availabilities in the system" table.rows.each do |row| Availability.create(:developer => row[0], :project => row[1], :start_time => row[2], :end_time => row[3], :contact => row[4]) end end +Given /^the following availabilities in the system with an end time one minute in the past:$/ do |table| + table.rows.each do |row| + Availability.create(:developer => row[0], :project => row[1], :start_time => Time.now - 120, :end_time => Time.now - 60) + end +end + +Given /^the following availabilities in the system with an end time one minute in the future:$/ do |table| + puts "#{Time.now + 60}" + table.rows.each do |row| + Availability.create(:developer => row[0], :project => row[1], :start_time => Time.now - 60, :end_time => (Time.now + 60)) + end +end + + Then /^I should see the following availabilites listed in order$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".availabilities tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" Then "I should see \"#{row[4]}\" within \"#{row_selector} td:nth-child(5)\"" end end Then /^I should see the following matching pairs$/ do |table| table.rows.each_with_index do |row,index| row_selector = ".pairs tr:nth-child(#{index + 2})" Then "I should see \"#{row[0]}\" within \"#{row_selector} td:nth-child(1)\"" Then "I should see \"#{row[1]}\" within \"#{row_selector} td:nth-child(2)\"" Then "I should see \"#{row[2]}\" within \"#{row_selector} td:nth-child(3)\"" Then "I should see \"#{row[3]}\" within \"#{row_selector} td:nth-child(4)\"" end end diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb index 5fe991d..0cd7e41 100644 --- a/features/step_definitions/webrat_steps.rb +++ b/features/step_definitions/webrat_steps.rb @@ -1,189 +1,189 @@ # IMPORTANT: This file was generated by Cucumber 0.4.0 # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. # Consider adding your own code to a new file instead of editing this one. require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) # Commonly used webrat steps # http://github.com/brynary/webrat Given /^I am on (.+)$/ do |page_name| visit path_to(page_name) end When /^I go to (.+)$/ do |page_name| visit path_to(page_name) end When /^I press "([^\"]*)"$/ do |button| click_button(button) end When /^I follow "([^\"]*)"$/ do |link| click_link(link) end When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent| click_link_within(parent, link) end When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| fill_in(field, :with => value) end When /^I fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field| fill_in(field, :with => value) end # Use this to fill in an entire form with data from a table. Example: # # When I fill in the following: # | Account Number | 5002 | -# | Expiry date | 2009-11-01 | +# | Expiry date | 2019-11-01 | # | Note | Nice guy | # | Wants Email? | | # # TODO: Add support for checkbox, select og option # based on naming conventions. # When /^I fill in the following:$/ do |fields| fields.rows_hash.each do |name, value| When %{I fill in "#{name}" with "#{value}"} end end When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field| select(value, :from => field) end # Use this step in conjunction with Rail's datetime_select helper. For example: # When I select "December 25, 2008 10:00" as the date and time When /^I select "([^\"]*)" as the date and time$/ do |time| select_datetime(time) end # Use this step when using multiple datetime_select helpers on a page or # you want to specify which datetime to select. Given the following view: # <%= f.label :preferred %><br /> # <%= f.datetime_select :preferred %> # <%= f.label :alternative %><br /> # <%= f.datetime_select :alternative %> # The following steps would fill out the form: # When I select "November 23, 2004 11:20" as the "Preferred" date and time # And I select "November 25, 2004 10:30" as the "Alternative" date and time When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label| select_datetime(datetime, :from => datetime_label) end # Use this step in conjunction with Rail's time_select helper. For example: # When I select "2:20PM" as the time # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat # will convert the 2:20PM to 14:20 and then select it. When /^I select "([^\"]*)" as the time$/ do |time| select_time(time) end # Use this step when using multiple time_select helpers on a page or you want to # specify the name of the time on the form. For example: # When I select "7:30AM" as the "Gym" time When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label| select_time(time, :from => time_label) end # Use this step in conjunction with Rail's date_select helper. For example: # When I select "February 20, 1981" as the date When /^I select "([^\"]*)" as the date$/ do |date| select_date(date) end # Use this step when using multiple date_select helpers on one page or # you want to specify the name of the date on the form. For example: # When I select "April 26, 1982" as the "Date of Birth" date When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label| select_date(date, :from => date_label) end When /^I check "([^\"]*)"$/ do |field| check(field) end When /^I uncheck "([^\"]*)"$/ do |field| uncheck(field) end When /^I choose "([^\"]*)"$/ do |field| choose(field) end When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field| attach_file(field, path) end Then /^I should see "([^\"]*)"$/ do |text| response.should contain(text) end Then /^I should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| within(selector) do |content| content.should contain(text) end end Then /^I should see \/([^\/]*)\/$/ do |regexp| regexp = Regexp.new(regexp) response.should contain(regexp) end Then /^I should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| within(selector) do |content| regexp = Regexp.new(regexp) content.should contain(regexp) end end Then /^I should not see "([^\"]*)"$/ do |text| response.should_not contain(text) end Then /^I should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| within(selector) do |content| content.should_not contain(text) end end Then /^I should not see \/([^\/]*)\/$/ do |regexp| regexp = Regexp.new(regexp) response.should_not contain(regexp) end Then /^I should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| within(selector) do |content| regexp = Regexp.new(regexp) content.should_not contain(regexp) end end Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should =~ /#{value}/ end Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should_not =~ /#{value}/ end Then /^the "([^\"]*)" checkbox should be checked$/ do |label| field_labeled(label).should be_checked end Then /^the "([^\"]*)" checkbox should not be checked$/ do |label| field_labeled(label).should_not be_checked end Then /^I should be on (.+)$/ do |page_name| URI.parse(current_url).path.should == path_to(page_name) end Then /^show me the page$/ do save_and_open_page end \ No newline at end of file diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index 5d58679..6d7f8bc 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,71 +1,71 @@ require 'spec_helper' describe Availability do it "should find pairs as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs.should be(expected_pairs) end describe "when a project has been specified" do - it "should set the end time of each pair to the earlier of the two end times" do + it "should find pairs as matching availabilities for different developers on the same project or anything where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" availability.project = "some proj" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time, :project => availability.project}]).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs.should be(expected_pairs) end end it "should set the start time of each pair to the later of the two start times" do availability = Availability.new(:start_time => Time.parse("2012-06-01 15:25"),:end_time => Time.now) pair_1 = Availability.new(:start_time => Time.parse("2012-06-01 15:26"),:end_time => Time.now) pair_2 = Availability.new(:start_time => Time.parse("2012-06-01 15:24"),:end_time => Time.now) expected_pairs = [pair_1,pair_2] Availability.stub!(:find).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs[0].start_time.should be (pair_1.start_time) actual_pairs[1].start_time.should be (availability.start_time) end it "should set the end time of each pair to the earlier of the two end times" do availability = Availability.new(:end_time => Time.parse("2012-06-01 15:25"),:start_time => Time.now) pair_1 = Availability.new(:end_time => Time.parse("2012-06-01 15:24"),:start_time => Time.now) pair_2 = Availability.new(:end_time => Time.parse("2012-06-01 15:26"),:start_time => Time.now) expected_pairs = [pair_1,pair_2] Availability.stub!(:find).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs[0].end_time.should be (pair_1.end_time) actual_pairs[1].end_time.should be (availability.end_time) end end
adiel/availabletopair
6f87696b3452dad973ff9f8a8b33a43f6a20db43
Add Google Analytics
diff --git a/app/views/layouts/availabilities.html.erb b/app/views/layouts/availabilities.html.erb index 8266c5b..8fbaa3d 100644 --- a/app/views/layouts/availabilities.html.erb +++ b/app/views/layouts/availabilities.html.erb @@ -1,24 +1,34 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>Available To Pair - matchmaking for Extreme Programmers</title> <%= stylesheet_link_tag 'all' %> </head> <body> -<div id="header"> - <div id="logo"><a href="/">Available To Pair</a></div> - <div id="how"><a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a></div> - <div class="clear">&nbsp;</div> - <div id="tagline"> - matchmaking for Extreme Programmers</div> -</div> -<p style="color: green"><%= flash[:notice] %></p> - -<%= yield %> + <div id="header"> + <div id="logo"><a href="/">Available To Pair</a></div> + <div id="how"><a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a></div> + <div class="clear">&nbsp;</div> + <div id="tagline"> - matchmaking for Extreme Programmers</div> + </div> + <p style="color: green"><%= flash[:notice] %></p> +<%= yield %> +<% if ENV['RAILS_ENV'] == "production" %> + <script type="text/javascript"> + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); + </script> + <script type="text/javascript"> + try { + var pageTracker = _gat._getTracker("UA-11197967-1"); + pageTracker._trackPageview(); + } catch(err) {}</script> +<% end %> </body> </html>
adiel/availabletopair
27cca2176b81c02bc5e9c7eefa44419d99eab3af
Stop downcasing the developer names in links.
diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index e7564eb..bba7f98 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,28 +1,28 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> - <td><%= link_to(h(availability.developer), "/" + h(availability.developer.downcase)) %></td> + <td><%= link_to(h(availability.developer), "/" + h(availability.developer)) %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 17d91b3..bfeb565 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,34 +1,34 @@ <h1><%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span> | <%= link_to 'Edit', edit_availability_path(@availability) %></h1> <% if @availability.pairs.length == 0 %> <p> No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> over this period. </p> <% else %> <p> Available to pair with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %>: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> - <td><%= link_to(h(pair.developer),"/" + h(pair.developer.downcase)) %></td> + <td><%= link_to(h(pair.developer),"/" + h(pair.developer)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> -<p>Subscribe to updates of <%=h @availability.developer %>'s available pairs (<a href="/<%=h @availability.developer.downcase%>.atom">atom</a>)</p> +<p>Subscribe to updates of <%=h @availability.developer %>'s available pairs (<a href="/<%=h @availability.developer%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb index 7d65cce..83474fe 100644 --- a/app/views/users/index.atom.erb +++ b/app/views/users/index.atom.erb @@ -1,35 +1,35 @@ <feed xmlns="http://www.w3.org/2005/Atom" > <title><%= user %> is Available To Pair</title> <id><%= http_root %>/<%= user%></id> - <link href="<%= http_root %>/<%= user.downcase%>.atom" rel="self" /> - <link href="<%= http_root %>/<%= user.downcase%>" /> + <link href="<%= http_root %>/<%= user%>.atom" rel="self" /> + <link href="<%= http_root %>/<%= user%>" /> <author> <name>Available To Pair</name> <email>noreply@availabletopair.com</email> </author> <% unless @availabilities.length == 0 %> <updated><%=h @availabilities[0].updated_at.xmlschema %></updated> <%end%> <% @availabilities.each do |availability| %> <entry> <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(availability.updated_at)%>)</title> <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> <published><%=h availability.updated_at.xmlschema %></published> <updated><%=h availability.updated_at.xmlschema %></updated> <id>http://availabletopair.com/<%=h availability.id %>/<%=h availability.updated_at.xmlschema %></id> <content type="html"> <![CDATA[ <% if availability.pairs.length == 0 %> No developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. <% else %> The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: <ul> <% availability.pairs.each do |pair| %> <li><%=h display_duration(pair) %> from <%=h display_when_time(pair) %> - <%= h pair.developer %> on <%=h display_project(pair) %></li> <% end %> </ul> <% end %> ]]> </content> </entry><% end %> </feed> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 41f116c..6c6a513 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,28 +1,28 @@ <h1>All <%= user %>'s availability</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> <td><%=h availability.developer %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> -<p>Subscribe to updates of <%=user %>'s available pairs (<a href="/<%=user.downcase%>.atom">atom</a>)</p> +<p>Subscribe to updates of <%=user %>'s available pairs (<a href="/<%=user%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature index 92945e9..301927a 100644 --- a/features/Feed_of_user_availabilities.feature +++ b/features/Feed_of_user_availabilities.feature @@ -1,117 +1,122 @@ Feature: Feed of user availabilities In order that I can get notifications when available pairs change for any of my availabilities As an open source developer I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id Scenario: Feed is titled for user and links back to self and webpage - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | - | title | larrydavid is Available To Pair | - | id | http://www.example.com/larrydavid | + | title | LarryDavid is Available To Pair | + | id | http://www.example.com/LarryDavid | And the feed should have the following links: | href | rel | - | http://www.example.com/larrydavid.atom | self | - | http://www.example.com/larrydavid | | + | http://www.example.com/LarryDavid.atom | self | + | http://www.example.com/LarryDavid | | Scenario: Feed author is Available To Pair with noreply email - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then the feed should have the following properties: | property | value | - | title | larrydavid is Available To Pair | - | id | http://www.example.com/larrydavid | + | title | LarryDavid is Available To Pair | + | id | http://www.example.com/LarryDavid | And the feed should have the following text nodes: | xpath | text | | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + | PhllilJFry | futurama | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00. | + When I visit "/PhllilJFry.atom" + Then I should see the following feed entries with content: + | title | content | + | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | No developers are available to pair on futurama with PhllilJFry on Mon Dec 14, 2009 21:59 - 00:00. | Scenario: When no pairs are available content should link to availability from datetime Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: When pairs are available content should link to availability from datetime Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then The only entry's content should link to availability page from time period Scenario: Single availability with pairs is listed with summary title and pair details in content Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | | LarryCharles | | December 13, 2009 23:30 | December 14, 2009 02:00 | http://github.com/LarryCharles | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then I should see the following feed entries with content: | title | content | | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | Scenario: Single availability with no pairs shows published as updated_at of availability Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" And check the published date of the feed entry at position 1 And touch the availability at position 1 of the feed - And visit "/larrydavid.atom" again + And visit "/LarryDavid.atom" again Then the published date of the entry at position 1 has been updated And the published date of the entry at position 1 is in xmlschema format Scenario: Multiple availabilities are ordered by updated date Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | And I visit "/larrydavid.atom" And I see the following feed entries: | title | | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | When I touch the availability at position 2 of the feed - And visit "/larrydavid.atom" again + And visit "/LarryDavid.atom" again Then I should see the following feed entries: | title | | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | Scenario: Multiple availabilities have feed updated date as last updated Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 15, 2009 21:59 | December 16, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then the feed should show as updated at the published time of the entry at position 1 When I touch the availability at position 2 of the feed - And I visit "/larrydavid.atom" again + And I visit "/LarryDavid.atom" again Then the feed should show as updated at the published time of the entry at position 1 Scenario: Availability should show updated time in the title Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then the title of the entry at position 1 should contain the updated time Scenario: Availability should show updated time and id in the entry id Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | - When I visit "/larrydavid.atom" + When I visit "/LarryDavid.atom" Then the id of the entry at position 1 should contain the updated time Then the id of the entry at position 1 should contain the availability id diff --git a/features/List_availabilities.feature b/features/List_availabilities.feature index caea6bc..95a08ba 100644 --- a/features/List_availabilities.feature +++ b/features/List_availabilities.feature @@ -1,44 +1,44 @@ Feature: Register new availability In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see all developers' availabilities Scenario: Single availability is listed on the availabilities page Given the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 0m | No | http://github.com/philip_j_fry | + | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: Multiple availabilities are listed on the availabilities page soonest first Given the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | Bender | futurama | Sun Nov 01, 2009 22:00 - 05:00 | 7h 0m | No | http://github.com/Bender | - | LarryDavid | curb | Sun Dec 13, 2009 21:59 - 00:00 | 2h 1m | No | http://github.com/LarryDavid | - | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 0m | No | http://github.com/philip_j_fry | + | Bender | futurama | Sun Nov 01, 2009 22:00 - 05:00 | 7h 00m | No | http://github.com/Bender | + | LarryDavid | curb | Sun Dec 13, 2009 21:59 - 00:00 | 2h 01m | No | http://github.com/LarryDavid | + | Philip.J.Fry | futurama | Fri Jan 01, 2010 22:00 - 23:00 | 1h 00m | No | http://github.com/philip_j_fry | Scenario: An availability is listed with two matching pairs Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | December 13, 2009 21:00 | December 14, 2009 05:00 | http://github.com/larry_david | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2009 21:15 | December 14, 2009 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page Then I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | - | LarryDavid | Curb | Sun Dec 13, 2009 21:00 - 05:00 | 8h 0m | Yes(1) | http://github.com/LarryDavid | + | LarryDavid | Curb | Sun Dec 13, 2009 21:00 - 05:00 | 8h 00m | Yes(1) | http://github.com/LarryDavid | | Prof Farnsworth | anything | Sun Dec 13, 2009 21:15 - 01:30 | 4h 15m | Yes(3) | http://github.com/philip_j_fry | - | Philip.J.Fry | Futurama | Sun Dec 13, 2009 21:30 - 02:30 | 5h 0m | Yes(2) | http://github.com/philip_j_fry | + | Philip.J.Fry | Futurama | Sun Dec 13, 2009 21:30 - 02:30 | 5h 00m | Yes(2) | http://github.com/philip_j_fry | | Bender | Futurama | Sun Dec 13, 2009 22:00 - 04:30 | 6h 30m | Yes(2) | http://github.com/philip_j_fry | diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index b86a2a4..e8a2a8f 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,43 +1,43 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first Given the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2009 22:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | And I visit "/LarryDavid" Then I should see "All LarryDavid's availability" And I should see the following availabilites listed in order - | developer | project | when | dev time | pairs available | contact | - | LarryDavid | curb | Sun Dec 13, 2009 21:00 - 00:00 | 3h 0m | No | http://github.com/LarryDavid | - | LarryDavid | curb | Sun Dec 13, 2009 22:00 - 00:00 | 2h 0m | No | http://github.com/LarryDavid | + | developer | project | when | dev time | pairs available | contact | + | LarryDavid | curb | Sun Dec 13, 2009 21:00 - 00:00 | 3h 00m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Sun Dec 13, 2009 22:00 - 00:00 | 2h 00m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" - Then My path should be "/larrydavid" + Then My path should be "/LarryDavid" Scenario: User page shows link to atom feed When I visit "/MarkKerrigan" Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" When I follow "atom" - Then My path should be "/markkerrigan.atom" + Then My path should be "/MarkKerrigan.atom" Scenario: Developer name on show page links to user page Given the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 21:30 - 02:30" And I follow "Bender" - Then My path should be "/bender" - And I should see "All bender's availability" \ No newline at end of file + Then My path should be "/Bender" + And I should see "All Bender's availability" \ No newline at end of file diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index 6630ae2..d51bfc4 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,71 +1,71 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on anything for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2009 21:15 | December 14, 2009 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | | Prof Farnsworth | anything | Sun Dec 13, 2009 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | Scenario: Show availability shows link to atom feed Given the following availabilities in the system | developer | project | start time | end time | contact | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see "Subscribe to updates of Bender's available pairs (atom)" When I follow "atom" - Then My path should be "/bender.atom" \ No newline at end of file + Then My path should be "/Bender.atom" \ No newline at end of file
adiel/availabletopair
865bd2e2fcbe4452831f8bfcf16fe251b2807d5a
Atom feed of user availabilities ordered by last updated (not taking into account changed pairs yet)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a4c4b79..8e6150e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,17 @@ class UsersController < ApplicationController layout 'availabilities' # GET /username + # GET /username.atom def index @availabilities = Availability.find(:all, :order => "start_time", :conditions => ["developer = :developer", {:developer => params[:id]}]) + respond_to do |format| + format.html # index.html.erb + format.atom do + @availabilities.sort! { |a1,a2| a1.updated_at <=> a2.updated_at}.reverse! + end + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22a7940..5089055 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,8 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + + def http_root + 'http://' + request.env["HTTP_HOST"] + end + end diff --git a/app/helpers/availabilities_helper.rb b/app/helpers/availabilities_helper.rb index b559c3a..00dd1a2 100644 --- a/app/helpers/availabilities_helper.rb +++ b/app/helpers/availabilities_helper.rb @@ -1,42 +1,46 @@ module AvailabilitiesHelper def contact_link(availability) email?(availability.contact) ? mail_to(h(availability.contact)) : link_to(h(availability.contact),h(availability.contact)) end def project_link(availability) http?(availability.project) ? link_to(h(availability.project),h(availability.project)) : display_project(availability) end def http?(url) url =~ /^http:\/\// end def email?(url) url =~ /\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i end def display_duration(availability) - "#{(availability.duration_sec / 3600).floor}h #{((availability.duration_sec % 3600) / 60).to_i}m" + "%dh %02dm" % [(availability.duration_sec / 3600).floor, ((availability.duration_sec % 3600) / 60).to_i] end def display_date_time(time) time.strftime("%a %b %d, %Y %H:%M") end def display_time(time) time.strftime("%H:%M") end def display_when(availability) "#{display_date_time(availability.start_time)} - #{display_time(availability.end_time)}" end + def display_when_time(availability) + "#{display_time(availability.start_time)} to #{display_time(availability.end_time)}" + end + def display_project(availability) availability.project.to_s == "" ? "anything" : availability.project end def pairs_link(availability) availability.pairs.length == 0 ? "No" : link_to("Yes", availability) + "(#{availability.pairs.length})" end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..5bf8c53 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,7 @@ +module UsersHelper + + def user + h params[:id] + end + +end \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index e27c4bf..17d91b3 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,34 +1,34 @@ -<h1><%=h @availability.developer %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> +<h1><%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span> | <%= link_to 'Edit', edit_availability_path(@availability) %></h1> <% if @availability.pairs.length == 0 %> <p> - No developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period. + No developers are available to pair on <%= project_link(@availability) %> with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %> over this period. </p> <% else %> <p> - The following developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period: + Available to pair with <%= link_to(h(@availability.developer),"/" + h(@availability.developer)) %>: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> - <td><%= link_to(h(pair.developer), "/" + h(pair.developer.downcase)) %></td> + <td><%= link_to(h(pair.developer),"/" + h(pair.developer.downcase)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> - +<p>Subscribe to updates of <%=h @availability.developer %>'s available pairs (<a href="/<%=h @availability.developer.downcase%>.atom">atom</a>)</p> <div class="nav"> - <%= link_to 'Home', availabilities_path %> + <%= link_to 'Home', availabilities_path %> | <%= link_to 'Make yourself available', new_availability_path %> </div> diff --git a/app/views/users/index.atom.erb b/app/views/users/index.atom.erb new file mode 100644 index 0000000..7d65cce --- /dev/null +++ b/app/views/users/index.atom.erb @@ -0,0 +1,35 @@ +<feed xmlns="http://www.w3.org/2005/Atom" > + <title><%= user %> is Available To Pair</title> + <id><%= http_root %>/<%= user%></id> + <link href="<%= http_root %>/<%= user.downcase%>.atom" rel="self" /> + <link href="<%= http_root %>/<%= user.downcase%>" /> + <author> + <name>Available To Pair</name> + <email>noreply@availabletopair.com</email> + </author> + <% unless @availabilities.length == 0 %> + <updated><%=h @availabilities[0].updated_at.xmlschema %></updated> + <%end%> + <% @availabilities.each do |availability| %> + <entry> + <title type="text" >Pairs available for <%=h display_when(availability) %> (updated: <%= display_date_time(availability.updated_at)%>)</title> + <link href="<%= http_root %>/availabilities/<%=h availability.id %>" /> + <published><%=h availability.updated_at.xmlschema %></published> + <updated><%=h availability.updated_at.xmlschema %></updated> + <id>http://availabletopair.com/<%=h availability.id %>/<%=h availability.updated_at.xmlschema %></id> + <content type="html"> + <![CDATA[ + <% if availability.pairs.length == 0 %> + No developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>. + <% else %> + The following developers are available to pair on <%= project_link(availability) %> with <%=h availability.developer %> on <a href="<%= http_root %>/availabilities/<%=h availability.id %>"><%=h display_when(availability) %></a>: + <ul> + <% availability.pairs.each do |pair| %> + <li><%=h display_duration(pair) %> from <%=h display_when_time(pair) %> - <%= h pair.developer %> on <%=h display_project(pair) %></li> + <% end %> + </ul> + <% end %> + ]]> + </content> + </entry><% end %> +</feed> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index be226be..41f116c 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,28 +1,28 @@ -<h1>Who's available?</h1> +<h1>All <%= user %>'s availability</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> <td><%=h availability.developer %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> - +<p>Subscribe to updates of <%=user %>'s available pairs (<a href="/<%=user.downcase%>.atom">atom</a>)</p> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9aa04a7..07cd9a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,47 +1,47 @@ ActionController::Routing::Routes.draw do |map| map.resources :availabilities # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # map.resources :products # Sample resource route with options: # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # Sample resource route with sub-resources: # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # Sample resource route with more complex sub-resources # map.resources :products do |products| # products.resources :comments # products.resources :sales, :collection => { :recent => :get } # end # Sample resource route within a namespace: # map.namespace :admin do |admin| # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # admin.resources :products # end # You can have the root of your site routed with map.root -- just remember to delete public/index.html. map.root :controller => "availabilities" - map.connect ':id', :controller => :users, :action => :index + map.connect ':id.:format', :controller => :users, :action => :index # See how all your routes lay out with "rake routes" # Install the default routes as the lowest priority. # Note: These default routes make all actions in every controller accessible via GET requests. You should # consider removing or commenting them out if you're using named routes and resources. map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end diff --git a/features/Feed_of_user_availabilities.feature b/features/Feed_of_user_availabilities.feature new file mode 100644 index 0000000..92945e9 --- /dev/null +++ b/features/Feed_of_user_availabilities.feature @@ -0,0 +1,117 @@ +Feature: Feed of user availabilities + In order that I can get notifications when available pairs change for any of my availabilities + As an open source developer + I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id + + Scenario: Feed is titled for user and links back to self and webpage + When I visit "/larrydavid.atom" + Then the feed should have the following properties: + | property | value | + | title | larrydavid is Available To Pair | + | id | http://www.example.com/larrydavid | + And the feed should have the following links: + | href | rel | + | http://www.example.com/larrydavid.atom | self | + | http://www.example.com/larrydavid | | + + Scenario: Feed author is Available To Pair with noreply email + When I visit "/larrydavid.atom" + Then the feed should have the following properties: + | property | value | + | title | larrydavid is Available To Pair | + | id | http://www.example.com/larrydavid | + And the feed should have the following text nodes: + | xpath | text | + | /xmlns:feed/xmlns:author/xmlns:name | Available To Pair | + | /xmlns:feed/xmlns:author/xmlns:email | noreply@availabletopair.com | + + Scenario: Single availability with no pairs is listed with summary title and content detailing no pairs available + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + Then I should see the following feed entries with content: + | title | content | + | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | No developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00. | + + Scenario: When no pairs are available content should link to availability from datetime + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + Then The only entry's content should link to availability page from time period + + Scenario: When pairs are available content should link to availability from datetime + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | + When I visit "/larrydavid.atom" + Then The only entry's content should link to availability page from time period + + Scenario: Single availability with pairs is listed with summary title and pair details in content + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | JeffGarlin | curb | December 13, 2009 23:00 | December 14, 2009 01:00 | http://github.com/JeffGarlin | + | LarryCharles | | December 13, 2009 23:30 | December 14, 2009 02:00 | http://github.com/LarryCharles | + When I visit "/larrydavid.atom" + Then I should see the following feed entries with content: + | title | content | + | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | The following developers are available to pair on curb with LarryDavid on Sun Dec 13, 2009 21:59 - 00:00:(\s*)1h 00m from 23:00 to 00:00 - JeffGarlin on curb(\s*)0h 30m from 23:30 to 00:00 - LarryCharles on anything | + + Scenario: Single availability with no pairs shows published as updated_at of availability + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + And check the published date of the feed entry at position 1 + And touch the availability at position 1 of the feed + And visit "/larrydavid.atom" again + Then the published date of the entry at position 1 has been updated + And the published date of the entry at position 1 is in xmlschema format + + Scenario: Multiple availabilities are ordered by updated date + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | + And I visit "/larrydavid.atom" + And I see the following feed entries: + | title | + | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | + | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | + When I touch the availability at position 2 of the feed + And visit "/larrydavid.atom" again + Then I should see the following feed entries: + | title | + | Pairs available for Sun Dec 13, 2009 21:59 - 00:00 | + | Pairs available for Mon Dec 14, 2009 21:59 - 00:00 | + + Scenario: Multiple availabilities have feed updated date as last updated + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 14, 2009 21:59 | December 15, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 15, 2009 21:59 | December 16, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + Then the feed should show as updated at the published time of the entry at position 1 + When I touch the availability at position 2 of the feed + And I visit "/larrydavid.atom" again + Then the feed should show as updated at the published time of the entry at position 1 + + Scenario: Availability should show updated time in the title + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + Then the title of the entry at position 1 should contain the updated time + + Scenario: Availability should show updated time and id in the entry id + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:59 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I visit "/larrydavid.atom" + Then the id of the entry at position 1 should contain the updated time + Then the id of the entry at position 1 should contain the availability id + diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature index d4de7af..b86a2a4 100644 --- a/features/List_user_availabilities.feature +++ b/features/List_user_availabilities.feature @@ -1,35 +1,43 @@ Feature: List user availabilities In order that I can see when I have made myself available and if anyone is available to pair As an open source developer I want to see all my availabilities listed with whether there are pairs available Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first Given the following availabilities in the system | developer | project | start time | end time | contact | | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | | LarryDavid | curb | December 13, 2009 22:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | - And I visit "/larrydavid" - Then I should see the following availabilites listed in order + And I visit "/LarryDavid" + Then I should see "All LarryDavid's availability" + And I should see the following availabilites listed in order | developer | project | when | dev time | pairs available | contact | | LarryDavid | curb | Sun Dec 13, 2009 21:00 - 00:00 | 3h 0m | No | http://github.com/LarryDavid | | LarryDavid | curb | Sun Dec 13, 2009 22:00 - 00:00 | 2h 0m | No | http://github.com/LarryDavid | Scenario: Developer name on all availabilities links to user page Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | When I am on the list availabilities page When I follow "LarryDavid" Then My path should be "/larrydavid" + Scenario: User page shows link to atom feed + When I visit "/MarkKerrigan" + Then I should see "Subscribe to updates of MarkKerrigan's available pairs (atom)" + When I follow "atom" + Then My path should be "/markkerrigan.atom" + Scenario: Developer name on show page links to user page Given the following availabilities in the system | developer | project | start time | end time | contact | | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 21:30 - 02:30" And I follow "Bender" - Then My path should be "/bender" \ No newline at end of file + Then My path should be "/bender" + And I should see "All bender's availability" \ No newline at end of file diff --git a/features/List_user_availabilities_as_atom.feature b/features/List_user_availabilities_as_atom.feature deleted file mode 100644 index 3be1df8..0000000 --- a/features/List_user_availabilities_as_atom.feature +++ /dev/null @@ -1,4 +0,0 @@ -Feature: List user availabilities - In order that I can get notifications when available pairs change for any of my availabilities - As an open source developer - I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id diff --git a/features/View_matching_availabilities.feature b/features/View_matching_availabilities.feature index fbb4eb9..6630ae2 100644 --- a/features/View_matching_availabilities.feature +++ b/features/View_matching_availabilities.feature @@ -1,61 +1,71 @@ Feature: View matching availabilities In order that I can find someone who wants a pair on whatever they are doing As an open source developer I want to see any matching pairs for the times I am available Scenario: One pair is found where both will work on anything Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on anything for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | anything | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: One pair is found where both will work on only a specific project Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/larry_david | Scenario: No pairs are found for a project Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/philip_j_fry | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/bender | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | | Philip.J.Fry | Futurama The Movie | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/larry_david | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ Then I should see /No developers are available to pair on Futurama with Bender over this period/ Scenario: Two pairs are found, one for the exact project, one for anything Given the following availabilities in the system | developer | project | start time | end time | contact | | LarryDavid | Curb | January 1, 2010 11:20 | January 1, 2010 11:30 | http://github.com/larry_david | | MalcolmTucker | The Thick Of It | December 1, 2009 22:00 | December 1, 2009 22:20 | http://github.com/malcolm_tucker | | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | | Philip.J.Fry | Futurama | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | | Prof Farnsworth | | December 13, 2009 21:15 | December 14, 2009 01:30 | http://github.com/prof_farnsworth | When I am on the list availabilities page And I follow "Sun Dec 13, 2009 22:00 - 04:30" Then I should see /Bender is available to pair on Futurama for 6h 30m from Sun Dec 13, 2009 22:00 \- 04:30/ And I should see the following matching pairs | developer | project | when | dev time | contact | | Philip.J.Fry | Futurama | Sun Dec 13, 2009 22:00 - 02:30 | 4h 30m | http://github.com/philip_j_fry | | Prof Farnsworth | anything | Sun Dec 13, 2009 22:00 - 01:30 | 3h 30m | http://github.com/prof_farnsworth | + + Scenario: Show availability shows link to atom feed + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | Futurama | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/malcolm_tucker | + When I am on the list availabilities page + And I follow "Sun Dec 13, 2009 22:00 - 04:30" + Then I should see "Subscribe to updates of Bender's available pairs (atom)" + When I follow "atom" + Then My path should be "/bender.atom" \ No newline at end of file diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 2dade50..baf734a 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,10 +1,119 @@ -When /^I visit "([^\"]*)"$/ do |path| +When /^(?:I )?visit "([^\"]*)"(?: again)?$/ do |path| visit path end Then /^My path should be "([^\"]*)"$/ do |path| - puts path - puts URI.parse(current_url).path URI.parse(current_url).path.should == path end +Then /^I (?:should )?see the following feed entries:$/ do |table| + doc = Nokogiri::XML(response.body) + entries = doc.xpath('/xmlns:feed/xmlns:entry') + entries.length.should eql(table.rows.length) + entries.each_with_index do |entry, index| + entry.xpath("xmlns:title").text.should match(table.rows[index][0]) + end +end + +Then /^I should see the following feed entries with content:$/ do |table| + doc = Nokogiri::XML(response.body) + entries = doc.xpath('/xmlns:feed/xmlns:entry') + entries.length.should eql(table.rows.length) + entries.each_with_index do |entry, index| + entry.xpath("xmlns:title").text.should match(table.rows[index][0]) + content = entry.xpath("xmlns:content").text + content_html = Nokogiri::HTML(content) + content_html.text.should =~ /#{table.rows[index][1]}/ + end +end + +Then /^The only entry's content should link to availability page from time period$/ do + doc = Nokogiri::XML(response.body) + entries = doc.xpath('/xmlns:feed/xmlns:entry') + + only_availability = Availability.find(:all)[0] + expected_link_text = "#{only_availability.start_time.strftime("%a %b %d, %Y %H:%M")} - #{only_availability.end_time.strftime("%H:%M")}" + + content = entries[0].xpath("xmlns:content").text + content.should match(/<a href="http:\/\/www.example.com\/availabilities\/#{only_availability.id}">#{expected_link_text}<\/a>/) +end + +Then /^the feed should have the following properties:$/ do |table| + doc = Nokogiri::XML(response.body) + table.rows.each do |row| + doc.xpath("/xmlns:feed/xmlns:#{row[0]}").text.should eql(row[1]) + end +end + +Then /^the feed should have the following links:$/ do |table| + doc = Nokogiri::XML(response.body) + table.rows.each do |row| + link = doc.xpath("/xmlns:feed/xmlns:link[@href = '#{row[0]}']") + link.length.should eql(1) + link.xpath("@rel").text.should eql(row[1]) + end +end + +Then /^the feed should have the following text nodes:$/ do |table| + doc = Nokogiri::XML(response.body) + table.rows.each do |row| + doc.xpath(row[0]).text.should eql(row[1]) + end +end + +When /check the published date of the feed entry at position (\d*)$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published_text = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + published_text.should_not eql("") + @published_dates ||= {} + @published_dates[entry_position] = Time.parse(published_text) +end + +When /(?:I )?touch the availability at position (\d*) of the feed$/ do |entry_position| + doc = Nokogiri::XML(response.body) + link = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text + id = /(\d*)$/.match(link)[0] + sleep 1 # to make sure the new updated_at is different + Availability.find(id).touch +end + +Then /the published date of the entry at position (\d*) has been updated$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) + @published_dates[entry_position].should < published + Time.now.should >= published +end + +Then /the published date of the entry at position (\d*) is in xmlschema format$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published_text = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + published_text.should eql(Time.parse(published_text).xmlschema) +end + + +Then /^the feed should show as updated at the published time of the entry at position (\d*)$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text + doc.xpath("/xmlns:feed/xmlns:updated").text.should eql (published) +end + +Then /^the title of the entry at position (\d*) should contain the updated time$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) + + doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:title").text.should match(/#{published.strftime("%a %b %d, %Y %H:%M")}/) +end + +Then /^the id of the entry at position (\d*) should contain the updated time$/ do |entry_position| + doc = Nokogiri::XML(response.body) + published = Time.parse(doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:published").text) + + doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{published.xmlschema}/) +end + +Then /^the id of the entry at position (\d*) should contain the availability id$/ do |entry_position| + doc = Nokogiri::XML(response.body) + link = doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:link/@href").text + id = /(\d*)$/.match(link)[0] + doc.xpath("/xmlns:feed/xmlns:entry[#{entry_position}]/xmlns:id").text.should match(/\/#{id}\//) +end \ No newline at end of file
adiel/availabletopair
fc1fd4ad4b9e78fd7888bfd1a18899cd19f6bf7e
New user page at /developer
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..a4c4b79 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,10 @@ +class UsersController < ApplicationController + layout 'availabilities' + # GET /username + def index + @availabilities = Availability.find(:all, + :order => "start_time", + :conditions => ["developer = :developer", + {:developer => params[:id]}]) + end +end diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index be226be..e7564eb 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,28 +1,28 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> - <td><%=h availability.developer %></td> + <td><%= link_to(h(availability.developer), "/" + h(availability.developer.downcase)) %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> <div class="nav"> <%= link_to 'Make yourself available', new_availability_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index c94b0ab..e27c4bf 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,34 +1,34 @@ <h1><%=h @availability.developer %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> <% if @availability.pairs.length == 0 %> <p> No developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period. </p> <% else %> <p> The following developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> - <td><%=h pair.developer %></td> + <td><%= link_to(h(pair.developer), "/" + h(pair.developer.downcase)) %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> <div class="nav"> <%= link_to 'Home', availabilities_path %> </div> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..be226be --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,28 @@ +<h1>Who's available?</h1> + +<table class="availabilities"> + <tr> + <th>Who</th> + <th>What</th> + <th>When</th> + <th>How long</th> + <th>Pairs available</th> + <th colspan="2">&nbsp;</th> + </tr> + +<% @availabilities.each do |availability| %> + <tr> + <td><%=h availability.developer %></td> + <td><%= project_link(availability) %></td> + <td><%= link_to(display_when(availability),availability) %></td> + <td><%=h display_duration(availability) %></td> + <td><%= pairs_link(availability) %></td> + <td><%= link_to 'Edit', edit_availability_path(availability) %></td> + <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> + </tr> +<% end %> +</table> + +<div class="nav"> + <%= link_to 'Make yourself available', new_availability_path %> +</div> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 38dbc0b..9aa04a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,45 +1,47 @@ ActionController::Routing::Routes.draw do |map| map.resources :availabilities # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # map.resources :products # Sample resource route with options: # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # Sample resource route with sub-resources: # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # Sample resource route with more complex sub-resources # map.resources :products do |products| # products.resources :comments # products.resources :sales, :collection => { :recent => :get } # end # Sample resource route within a namespace: # map.namespace :admin do |admin| # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # admin.resources :products # end # You can have the root of your site routed with map.root -- just remember to delete public/index.html. map.root :controller => "availabilities" + map.connect ':id', :controller => :users, :action => :index + # See how all your routes lay out with "rake routes" # Install the default routes as the lowest priority. # Note: These default routes make all actions in every controller accessible via GET requests. You should # consider removing or commenting them out if you're using named routes and resources. map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end diff --git a/features/List_user_availabilities.feature b/features/List_user_availabilities.feature new file mode 100644 index 0000000..d4de7af --- /dev/null +++ b/features/List_user_availabilities.feature @@ -0,0 +1,35 @@ +Feature: List user availabilities + In order that I can see when I have made myself available and if anyone is available to pair + As an open source developer + I want to see all my availabilities listed with whether there are pairs available + + Scenario: Only the specified user's availabilities are listed on the users' availabilities page soonest first + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | Philip.J.Fry | futurama | January 1, 2010 22:00 | January 1, 2010 23:00 | http://github.com/philip_j_fry | + | Bender | futurama | November 1, 2009 22:00 | November 2, 2009 05:00 | http://github.com/Bender | + | LarryDavid | curb | December 13, 2009 22:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | + | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | + And I visit "/larrydavid" + Then I should see the following availabilites listed in order + | developer | project | when | dev time | pairs available | contact | + | LarryDavid | curb | Sun Dec 13, 2009 21:00 - 00:00 | 3h 0m | No | http://github.com/LarryDavid | + | LarryDavid | curb | Sun Dec 13, 2009 22:00 - 00:00 | 2h 0m | No | http://github.com/LarryDavid | + + Scenario: Developer name on all availabilities links to user page + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | LarryDavid | curb | December 13, 2009 21:00 | December 14, 2009 00:00 | http://github.com/LarryDavid | + When I am on the list availabilities page + When I follow "LarryDavid" + Then My path should be "/larrydavid" + + Scenario: Developer name on show page links to user page + Given the following availabilities in the system + | developer | project | start time | end time | contact | + | Bender | | December 13, 2009 22:00 | December 14, 2009 04:30 | http://github.com/bender | + | Philip.J.Fry | | December 13, 2009 21:30 | December 14, 2009 02:30 | http://github.com/philip_j_fry | + When I am on the list availabilities page + And I follow "Sun Dec 13, 2009 21:30 - 02:30" + And I follow "Bender" + Then My path should be "/bender" \ No newline at end of file diff --git a/features/List_user_availabilities_as_atom.feature b/features/List_user_availabilities_as_atom.feature new file mode 100644 index 0000000..3be1df8 --- /dev/null +++ b/features/List_user_availabilities_as_atom.feature @@ -0,0 +1,4 @@ +Feature: List user availabilities + In order that I can get notifications when available pairs change for any of my availabilities + As an open source developer + I want a feed of all my availabilities with available pairs in order of last updated first and a unique title/id diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb new file mode 100644 index 0000000..2dade50 --- /dev/null +++ b/features/step_definitions/user_steps.rb @@ -0,0 +1,10 @@ +When /^I visit "([^\"]*)"$/ do |path| + visit path +end + +Then /^My path should be "([^\"]*)"$/ do |path| + puts path + puts URI.parse(current_url).path + URI.parse(current_url).path.should == path +end +
adiel/availabletopair
fad5dbd093ac5e7bf79cbb97ff29cafcde5053cb
Changed 'Back' links to 'Home'
diff --git a/app/views/availabilities/edit.html.erb b/app/views/availabilities/edit.html.erb index 430ea1f..84828cc 100644 --- a/app/views/availabilities/edit.html.erb +++ b/app/views/availabilities/edit.html.erb @@ -1,33 +1,33 @@ <h1>Editing availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> <%= f.label :developer %><br /> <%= f.text_field :developer %> </p> <p> <%= f.label :project %><br /> <%= f.text_field :project %> </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p> <%= f.label :contact %><br /> <%= f.text_field :contact %> </p> <p> <%= f.submit 'Update' %> </p> <% end %> <div class="nav"> - <%= link_to 'Back', availabilities_path %> + <%= link_to 'Home', availabilities_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/new.html.erb b/app/views/availabilities/new.html.erb index 4f2de09..4a6af08 100644 --- a/app/views/availabilities/new.html.erb +++ b/app/views/availabilities/new.html.erb @@ -1,33 +1,33 @@ <h1>New availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> <%= f.label :developer %><br /> <%= f.text_field :developer %> </p> <p> <%= f.label :project %><br /> <%= f.text_field :project %> </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p> <%= f.label :contact %><br /> <%= f.text_field :contact %> </p> <p> <%= f.submit 'Publish availability' %> </p> <% end %> <div class="nav"> - <%= link_to 'Back', availabilities_path %> + <%= link_to 'Home', availabilities_path %> </div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index 1d15ad2..c94b0ab 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,34 +1,34 @@ <h1><%=h @availability.developer %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> <% if @availability.pairs.length == 0 %> <p> No developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period. </p> <% else %> <p> The following developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> <td><%=h pair.developer %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> <div class="nav"> - <%= link_to 'Back', availabilities_path %> + <%= link_to 'Home', availabilities_path %> </div>
adiel/availabletopair
99693502e0ff676ab96b3ef043b0707e8ba58dba
CSS tweaks
diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 5ebd14a..820514a 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,74 +1,75 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; + font-size:0.8em; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; - font-size:80%; + font-size:0.9em; border-collapse: collapse; width:95% } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.5em 1em; } h1 { - font-size:1.2em; + font-size:1.3em; margin:0.8em; } #header { - font-size:2em; + font-size:2.5em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { - font-size:1.3em; + font-size:1.2em; padding:0.2em; } #logo {float:left;} #how {float:right;} .clear{ clear:both; font-size:0; } #logo a { color:#000; text-decoration:none; } .nav{ margin:1em; } #tagline { font-style:italic; font-size:0.4em; margin-left:1em; } \ No newline at end of file
adiel/availabletopair
7f08db4581eb147c25e22769d1daf775624ce303
Page title
diff --git a/app/views/layouts/availabilities.html.erb b/app/views/layouts/availabilities.html.erb index 53a9985..8266c5b 100644 --- a/app/views/layouts/availabilities.html.erb +++ b/app/views/layouts/availabilities.html.erb @@ -1,24 +1,24 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> - <title>Available To Pair</title> + <title>Available To Pair - matchmaking for Extreme Programmers</title> <%= stylesheet_link_tag 'all' %> </head> <body> <div id="header"> <div id="logo"><a href="/">Available To Pair</a></div> <div id="how"><a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a></div> <div class="clear">&nbsp;</div> <div id="tagline"> - matchmaking for Extreme Programmers</div> </div> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </body> </html>
adiel/availabletopair
c1773bc03536ecf9ae2c451130c25dc9498eb016
Tagline
diff --git a/app/views/layouts/availabilities.html.erb b/app/views/layouts/availabilities.html.erb index dae191f..53a9985 100644 --- a/app/views/layouts/availabilities.html.erb +++ b/app/views/layouts/availabilities.html.erb @@ -1,24 +1,24 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>Available To Pair</title> <%= stylesheet_link_tag 'all' %> </head> <body> <div id="header"> <div id="logo"><a href="/">Available To Pair</a></div> <div id="how"><a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a></div> <div class="clear">&nbsp;</div> - <div id="tagline"> - matchmaking for eXtreme Programmers</div> + <div id="tagline"> - matchmaking for Extreme Programmers</div> </div> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </body> </html>
adiel/availabletopair
a8fbb1781442cb297f66c9b78a28a22938425fe8
Alignment. Link to Virtual pair-programming wiki.
diff --git a/app/views/availabilities/edit.html.erb b/app/views/availabilities/edit.html.erb index c65d197..430ea1f 100644 --- a/app/views/availabilities/edit.html.erb +++ b/app/views/availabilities/edit.html.erb @@ -1,32 +1,33 @@ <h1>Editing availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> <%= f.label :developer %><br /> <%= f.text_field :developer %> </p> <p> <%= f.label :project %><br /> <%= f.text_field :project %> </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p> <%= f.label :contact %><br /> <%= f.text_field :contact %> </p> <p> <%= f.submit 'Update' %> </p> <% end %> -<%= link_to 'Show', @availability %> | -<%= link_to 'Back', availabilities_path %> \ No newline at end of file +<div class="nav"> + <%= link_to 'Back', availabilities_path %> +</div> \ No newline at end of file diff --git a/app/views/availabilities/index.html.erb b/app/views/availabilities/index.html.erb index 329034d..be226be 100644 --- a/app/views/availabilities/index.html.erb +++ b/app/views/availabilities/index.html.erb @@ -1,28 +1,28 @@ <h1>Who's available?</h1> <table class="availabilities"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>How long</th> <th>Pairs available</th> <th colspan="2">&nbsp;</th> </tr> <% @availabilities.each do |availability| %> <tr> <td><%=h availability.developer %></td> <td><%= project_link(availability) %></td> <td><%= link_to(display_when(availability),availability) %></td> <td><%=h display_duration(availability) %></td> <td><%= pairs_link(availability) %></td> <td><%= link_to 'Edit', edit_availability_path(availability) %></td> <td><%= link_to 'Delete', availability, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> -<br /> - -<%= link_to 'Make yourself available', new_availability_path %> \ No newline at end of file +<div class="nav"> + <%= link_to 'Make yourself available', new_availability_path %> +</div> \ No newline at end of file diff --git a/app/views/availabilities/new.html.erb b/app/views/availabilities/new.html.erb index 12b8c3f..4f2de09 100644 --- a/app/views/availabilities/new.html.erb +++ b/app/views/availabilities/new.html.erb @@ -1,31 +1,33 @@ <h1>New availability</h1> <% form_for(@availability) do |f| %> <%= f.error_messages %> <p> <%= f.label :developer %><br /> <%= f.text_field :developer %> </p> <p> <%= f.label :project %><br /> <%= f.text_field :project %> </p> <p> <%= f.label :start_time %><br /> <%= f.datetime_select :start_time %> </p> <p> <%= f.label :end_time %><br /> <%= f.datetime_select :end_time %> </p> <p> <%= f.label :contact %><br /> <%= f.text_field :contact %> </p> <p> <%= f.submit 'Publish availability' %> </p> <% end %> -<%= link_to 'Back', availabilities_path %> \ No newline at end of file +<div class="nav"> + <%= link_to 'Back', availabilities_path %> +</div> \ No newline at end of file diff --git a/app/views/availabilities/show.html.erb b/app/views/availabilities/show.html.erb index c1b57a8..1d15ad2 100644 --- a/app/views/availabilities/show.html.erb +++ b/app/views/availabilities/show.html.erb @@ -1,33 +1,34 @@ -<h1><%=h @availability.developer %> is available to pair on <%= display_project(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> +<h1><%=h @availability.developer %> is available to pair on <%= project_link(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> <% if @availability.pairs.length == 0 %> <p> - No developers are available to pair on <%= display_project(@availability) %> with <%=h @availability.developer %> over this period. + No developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period. </p> <% else %> <p> - The following developers are available to pair on <%= display_project(@availability) %> with <%=h @availability.developer %> over this period: + The following developers are available to pair on <%= project_link(@availability) %> with <%=h @availability.developer %> over this period: </p> <table class="pairs"> <tr> <th>Who</th> <th>What</th> <th>When</th> <th>Dev time</th> <th>Contact</th> </tr> <% @availability.pairs.each do |pair| %> <tr> <td><%=h pair.developer %></td> <td><%= project_link(pair) %></td> <td><%=h display_when(pair) %></td> <td><%=h display_duration(pair) %></td> <td><%= contact_link(pair) %></td> </tr> <% end %> </table> <% end %> -<br /> -<%= link_to 'Back', availabilities_path %> +<div class="nav"> + <%= link_to 'Back', availabilities_path %> +</div> diff --git a/app/views/layouts/availabilities.html.erb b/app/views/layouts/availabilities.html.erb index 5a495f9..4e14a21 100644 --- a/app/views/layouts/availabilities.html.erb +++ b/app/views/layouts/availabilities.html.erb @@ -1,21 +1,23 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> - <title>Availabilities: <%= controller.action_name %></title> + <title>Available To Pair</title> <%= stylesheet_link_tag 'all' %> </head> <body> <div id="header"> - Available To Pair + <div id="logo"><a href="/">Available To Pair</a></div> + <div id="how"><a href="http://c2.com/cgi/wiki?VirtualPairProgramming">How?</a></div> + <div class="clear">&nbsp;</div> </div> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </body> </html> diff --git a/log/development.log b/log/development.log index 4b1886e..5e66f16 100644 --- a/log/development.log +++ b/log/development.log @@ -9408,512 +9408,1797 @@ Rendering availabilities/index Completed in 123ms (View: 98, DB: 5) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 20:01:21) [GET] Parameters: {"id"=>"9"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Completed in 21ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/9] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 20:10:43) [GET] Parameters: {"id"=>"6"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 6)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 56ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/6] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:14:11) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` ActionView::TemplateError (wrong number of arguments (0 for 1)) on line #16 of app/views/availabilities/index.html.erb: 13: <% @availabilities.each do |availability| %> 14: <tr> 15: <td><%= developer_link(availability) %></td> 16: <td><%= project_link(availability) %></td> 17: <td><%= link_to(display_when(availability),availability) %></td> 18: <td><%=h display_duration(availability) %></td> 19: <td><%= pairs_link(availability) %></td> app/helpers/availabilities_helper.rb:11:in `h' app/helpers/availabilities_helper.rb:11:in `project_link' app/views/availabilities/index.html.erb:16 app/views/availabilities/index.html.erb:13:in `each' app/views/availabilities/index.html.erb:13 app/controllers/availabilities_controller.rb:7:in `index' -e:1:in `load' -e:1 Rendered rescues/_trace (81.0ms) Rendered rescues/_request_and_response (1.0ms) Rendering rescues/layout (internal_server_error) SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:15:28) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 68ms (View: 54, DB: 5) | 200 OK [http://localhost/] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:15:47) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 141ms (View: 53, DB: 9) | 200 OK [http://localhost/] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:16:23) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 69ms (View: 54, DB: 7) | 200 OK [http://localhost/] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:17:08) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 68ms (View: 52, DB: 7) | 200 OK [http://localhost/] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:17:37) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 128ms (View: 59, DB: 10) | 200 OK [http://localhost/] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 21:17:53) [GET] Parameters: {"id"=>"7"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 48ms (View: 35, DB: 5) | 200 OK [http://localhost/availabilities/7/edit] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#update (for 127.0.0.1 at 2009-10-16 21:18:19) [PUT] Parameters: {"commit"=>"Update", "authenticity_token"=>"ljbX9G5Y5t/4Ay602x++Be03y564NhDabZZQCNh7n20=", "id"=>"7", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"14", "project"=>"http://github.com/aslakhellesoy/cucumber", "contact"=>"", "end_time(1i)"=>"2009", "start_time(4i)"=>"00", "end_time(2i)"=>"10", "start_time(5i)"=>"00", "end_time(3i)"=>"14", "end_time(4i)"=>"19", "end_time(5i)"=>"40", "developer"=>"Aslak"}} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  SQL (0.0ms) BEGIN Availability Update (1.0ms) UPDATE `availabilities` SET `project` = 'http://github.com/aslakhellesoy/cucumber', `updated_at` = '2009-10-16 20:18:19' WHERE `id` = 7 SQL (63.0ms) COMMIT Redirected to http://localhost:3000/availabilities/7 Completed in 85ms (DB: 68) | 302 Found [http://localhost/availabilities/7] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 21:18:20) [GET] Parameters: {"id"=>"7"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Completed in 29ms (View: 16, DB: 3) | 200 OK [http://localhost/availabilities/7] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:18:23) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 163ms (View: 149, DB: 5) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 21:18:46) [GET] Parameters: {"id"=>"7"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Completed in 20ms (View: 5, DB: 6) | 200 OK [http://localhost/availabilities/7] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:18:48) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 70ms (View: 51, DB: 11) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 21:18:51) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 50ms (View: 37, DB: 3) | 200 OK [http://localhost/availabilities/3/edit] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#update (for 127.0.0.1 at 2009-10-16 21:18:53) [PUT] Parameters: {"commit"=>"Update", "authenticity_token"=>"ljbX9G5Y5t/4Ay602x++Be03y564NhDabZZQCNh7n20=", "id"=>"3", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"14", "project"=>"Cucumber", "contact"=>"http://github.com/bob", "end_time(1i)"=>"2009", "start_time(4i)"=>"13", "end_time(2i)"=>"10", "start_time(5i)"=>"00", "end_time(3i)"=>"14", "end_time(4i)"=>"15", "end_time(5i)"=>"00", "developer"=>"Bob"}} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  SQL (1.0ms) BEGIN SQL (0.0ms) COMMIT Redirected to http://localhost:3000/availabilities/3 Completed in 20ms (DB: 5) | 302 Found [http://localhost/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 21:18:54) [GET] Parameters: {"id"=>"3"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Completed in 19ms (View: 6, DB: 3) | 200 OK [http://localhost/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 21:18:56) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 69ms (View: 52, DB: 8) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 21:18:58) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 23ms (View: 9, DB: 5) | 200 OK [http://localhost/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:03:26) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 66ms (View: 54, DB: 3) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:03:28) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 161ms (View: 146, DB: 7) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:03:31) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 70ms (View: 53, DB: 10) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:07:42) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 75ms (View: 58, DB: 8) | 200 OK [http://localhost/availabilities] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:09:50) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` ActionView::TemplateError (undefined method `developer' for #<ActionView::Base:0x894c28c>) on line #15 of app/views/availabilities/index.html.erb: 12: 13: <% @availabilities.each do |availability| %> 14: <tr> 15: <td><%= developer(availability) %></td> 16: <td><%= project_link(availability) %></td> 17: <td><%= link_to(display_when(availability),availability) %></td> 18: <td><%=h display_duration(availability) %></td> app/views/availabilities/index.html.erb:15 app/views/availabilities/index.html.erb:13:in `each' app/views/availabilities/index.html.erb:13 app/controllers/availabilities_controller.rb:7:in `index' -e:1:in `load' -e:1 Rendered rescues/_trace (159.0ms) Rendered rescues/_request_and_response (0.0ms) Rendering rescues/layout (internal_server_error) SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:09:58) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 77ms (View: 61, DB: 8) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 22:22:26) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 70ms (View: 57, DB: 5) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 22:25:44) [GET] Parameters: {"id"=>"7"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Completed in 29ms (View: 14, DB: 4) | 200 OK [http://localhost/availabilities/7] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 22:25:47) [GET] Parameters: {"id"=>"4"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 27ms (View: 12, DB: 5) | 200 OK [http://localhost/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 23:50:52) [GET] Parameters: {"id"=>"4"} Availability Columns (5.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 158ms (View: 10, DB: 6) | 200 OK [http://localhost/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 23:51:45) [GET] Parameters: {"id"=>"9"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Completed in 22ms (View: 8, DB: 5) | 200 OK [http://localhost/availabilities/9] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 23:52:30) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 78ms (View: 60, DB: 9) | 200 OK [http://localhost/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 23:52:43) [GET] Parameters: {"id"=>"4"} Availability Columns (218.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 247ms (View: 19, DB: 220) | 200 OK [http://localhost/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 23:53:06) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 96ms (View: 75, DB: 10) | 200 OK [http://localhost/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:28) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 68ms (View: 52, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:30) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 133ms (View: 120, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:30) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 48, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:31) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 48, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:32) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 46, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:32) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 44, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:10:40) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 45, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:11:06) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 66ms (View: 51, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:11:24) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 67ms (View: 53, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:12:20) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 66ms (View: 52, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:12:53) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (4.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 88ms (View: 68, DB: 14) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:13:44) [GET] + Parameters: {"id"=>"4"} + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 20ms (View: 7, DB: 3) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:57) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 48, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:57) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 46, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:58) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 46, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:58) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 46, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:59) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 46, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:59) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 69ms (View: 50, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:59) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (5.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (2.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 76ms (View: 56, DB: 13) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:14:59) [GET] + Availability Load (2.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (2.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (2.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 84ms (View: 60, DB: 13) | 200 OK [http://127.0.0.1/availabilities] + SQL (3.0ms) SET NAMES 'utf8' + SQL (4.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 80ms (View: 61, DB: 15) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 79ms (View: 59, DB: 12) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (2.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (3.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (9.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (2.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 112ms (View: 81, DB: 20) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (2.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 77ms (View: 59, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (4.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (13.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 99ms (View: 63, DB: 25) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (4.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:00) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (20.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (18.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 132ms (View: 79, DB: 49) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 185ms (View: 168, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 70ms (View: 55, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 75ms (View: 58, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 49, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 46, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 63ms (View: 45, DB: 10) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 45, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 45, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:01) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 164ms (View: 44, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 66ms (View: 54, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 45, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 67ms (View: 50, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 47, DB: 4) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 44, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 49, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 158ms (View: 147, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 46, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:02) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 45, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 47, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 46, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 45, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 46, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 45, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 44, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 48, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 48, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 44, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 48, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:03) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 45, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:04) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 42, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:04) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 155ms (View: 140, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:04) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 43, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:15:04) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 45, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:07) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 28ms (View: 17, DB: 3) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:09) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 20ms (View: 8, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:09) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 20ms (View: 7, DB: 7) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:10) [GET] + Parameters: {"id"=>"4"} + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 20ms (View: 7, DB: 3) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:10) [GET] + Parameters: {"id"=>"4"} + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 19ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (2.0ms) SET NAMES 'utf8' + SQL (6.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:10) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 20ms (View: 9, DB: 12) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:17:13) [GET] + Parameters: {"id"=>"7"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  +Completed in 19ms (View: 7, DB: 5) | 200 OK [http://127.0.0.1/availabilities/7] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:17:42) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 58ms (View: 46, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:18:09) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 6613ms (View: 6597, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:19:27) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 79ms (View: 64, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:19:54) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 65ms (View: 53, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:20:06) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 61ms (View: 47, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:20:18) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 72ms (View: 56, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:23:00) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 65ms (View: 52, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:23:03) [GET] + Parameters: {"id"=>"5"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 5)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  +Completed in 28ms (View: 15, DB: 5) | 200 OK [http://127.0.0.1/availabilities/5] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:23:04) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 47, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#new (for 127.0.0.1 at 2009-10-17 00:23:05) [GET] + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` +Rendering template within layouts/availabilities +Rendering availabilities/new +Completed in 49ms (View: 38, DB: 2) | 200 OK [http://127.0.0.1/availabilities/new] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:23:06) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 47, DB: 5) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-17 00:23:07) [GET] + Parameters: {"id"=>"6"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 6)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 18ms (View: 7, DB: 3) | 200 OK [http://127.0.0.1/availabilities/6] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-17 00:23:09) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'http://github.com/aslakhellesoy/cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 59ms (View: 46, DB: 6) | 200 OK [http://127.0.0.1/availabilities] diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 350f1bd..beb81e4 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,55 +1,69 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:80%; border-collapse: collapse; width:95% } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.5em 1em; } h1 { font-size:1.2em; margin:0.8em; } #header { font-size:2em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; } input,select { font-size:1.3em; padding:0.2em; +} + +#logo {float:left;} +#how {float:right;} +.clear{ + clear:both; + font-size:0; +} +#logo a { + color:#000; + text-decoration:none; +} +.nav{ + margin:1em; } \ No newline at end of file
adiel/availabletopair
e2443bb4c6ff358333c3b6e79c410762220bd16b
Replaced default rails readme
diff --git a/README b/README index 37ec8ea..ba09601 100644 --- a/README +++ b/README @@ -1,243 +1,3 @@ -== Welcome to Rails +== Welcome to Available To Pair -Rails is a web-application framework that includes everything needed to create -database-backed web applications according to the Model-View-Control pattern. - -This pattern splits the view (also called the presentation) into "dumb" templates -that are primarily responsible for inserting pre-built data in between HTML tags. -The model contains the "smart" domain objects (such as Account, Product, Person, -Post) that holds all the business logic and knows how to persist themselves to -a database. The controller handles the incoming requests (such as Save New Account, -Update Product, Show Post) by manipulating the model and directing data to the view. - -In Rails, the model is handled by what's called an object-relational mapping -layer entitled Active Record. This layer allows you to present the data from -database rows as objects and embellish these data objects with business logic -methods. You can read more about Active Record in -link:files/vendor/rails/activerecord/README.html. - -The controller and view are handled by the Action Pack, which handles both -layers by its two parts: Action View and Action Controller. These two layers -are bundled in a single package due to their heavy interdependence. This is -unlike the relationship between the Active Record and Action Pack that is much -more separate. Each of these packages can be used independently outside of -Rails. You can read more about Action Pack in -link:files/vendor/rails/actionpack/README.html. - - -== Getting Started - -1. At the command prompt, start a new Rails application using the <tt>rails</tt> command - and your application name. Ex: rails myapp -2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options) -3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!" -4. Follow the guidelines to start developing your application - - -== Web Servers - -By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails -with a variety of other web servers. - -Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is -suitable for development and deployment of Rails applications. If you have Ruby Gems installed, -getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>. -More info at: http://mongrel.rubyforge.org - -Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or -Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use -FCGI or proxy to a pack of Mongrels/Thin/Ebb servers. - -== Apache .htaccess example for FCGI/CGI - -# General Apache options -AddHandler fastcgi-script .fcgi -AddHandler cgi-script .cgi -Options +FollowSymLinks +ExecCGI - -# If you don't want Rails to look in certain directories, -# use the following rewrite rules so that Apache won't rewrite certain requests -# -# Example: -# RewriteCond %{REQUEST_URI} ^/notrails.* -# RewriteRule .* - [L] - -# Redirect all requests not available on the filesystem to Rails -# By default the cgi dispatcher is used which is very slow -# -# For better performance replace the dispatcher with the fastcgi one -# -# Example: -# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] -RewriteEngine On - -# If your Rails application is accessed via an Alias directive, -# then you MUST also set the RewriteBase in this htaccess file. -# -# Example: -# Alias /myrailsapp /path/to/myrailsapp/public -# RewriteBase /myrailsapp - -RewriteRule ^$ index.html [QSA] -RewriteRule ^([^.]+)$ $1.html [QSA] -RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule ^(.*)$ dispatch.cgi [QSA,L] - -# In case Rails experiences terminal errors -# Instead of displaying this message you can supply a file here which will be rendered instead -# -# Example: -# ErrorDocument 500 /500.html - -ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" - - -== Debugging Rails - -Sometimes your application goes wrong. Fortunately there are a lot of tools that -will help you debug it and get it back on the rails. - -First area to check is the application log files. Have "tail -f" commands running -on the server.log and development.log. Rails will automatically display debugging -and runtime information to these files. Debugging info will also be shown in the -browser on requests from 127.0.0.1. - -You can also log your own messages directly into the log file from your code using -the Ruby logger class from inside your controllers. Example: - - class WeblogController < ActionController::Base - def destroy - @weblog = Weblog.find(params[:id]) - @weblog.destroy - logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") - end - end - -The result will be a message in your log file along the lines of: - - Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1 - -More information on how to use the logger is at http://www.ruby-doc.org/core/ - -Also, Ruby documentation can be found at http://www.ruby-lang.org/ including: - -* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/ -* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) - -These two online (and free) books will bring you up to speed on the Ruby language -and also on programming in general. - - -== Debugger - -Debugger support is available through the debugger command when you start your Mongrel or -Webrick server with --debugger. This means that you can break out of execution at any point -in the code, investigate and change the model, AND then resume execution! -You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug' -Example: - - class WeblogController < ActionController::Base - def index - @posts = Post.find(:all) - debugger - end - end - -So the controller will accept the action, run the first line, then present you -with a IRB prompt in the server window. Here you can do things like: - - >> @posts.inspect - => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>, - #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]" - >> @posts.first.title = "hello from a debugger" - => "hello from a debugger" - -...and even better is that you can examine how your runtime objects actually work: - - >> f = @posts.first - => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}> - >> f. - Display all 152 possibilities? (y or n) - -Finally, when you're ready to resume execution, you enter "cont" - - -== Console - -You can interact with the domain model by starting the console through <tt>script/console</tt>. -Here you'll have all parts of the application configured, just like it is when the -application is running. You can inspect domain models, change values, and save to the -database. Starting the script without arguments will launch it in the development environment. -Passing an argument will specify a different environment, like <tt>script/console production</tt>. - -To reload your controllers and models after launching the console run <tt>reload!</tt> - -== dbconsole - -You can go to the command line of your database directly through <tt>script/dbconsole</tt>. -You would be connected to the database with the credentials defined in database.yml. -Starting the script without arguments will connect you to the development database. Passing an -argument will connect you to a different database, like <tt>script/dbconsole production</tt>. -Currently works for mysql, postgresql and sqlite. - -== Description of Contents - -app - Holds all the code that's specific to this particular application. - -app/controllers - Holds controllers that should be named like weblogs_controller.rb for - automated URL mapping. All controllers should descend from ApplicationController - which itself descends from ActionController::Base. - -app/models - Holds models that should be named like post.rb. - Most models will descend from ActiveRecord::Base. - -app/views - Holds the template files for the view that should be named like - weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby - syntax. - -app/views/layouts - Holds the template files for layouts to be used with views. This models the common - header/footer method of wrapping views. In your views, define a layout using the - <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb, - call <% yield %> to render the view using this layout. - -app/helpers - Holds view helpers that should be named like weblogs_helper.rb. These are generated - for you automatically when using script/generate for controllers. Helpers can be used to - wrap functionality for your views into methods. - -config - Configuration files for the Rails environment, the routing map, the database, and other dependencies. - -db - Contains the database schema in schema.rb. db/migrate contains all - the sequence of Migrations for your schema. - -doc - This directory is where your application documentation will be stored when generated - using <tt>rake doc:app</tt> - -lib - Application specific libraries. Basically, any kind of custom code that doesn't - belong under controllers, models, or helpers. This directory is in the load path. - -public - The directory available for the web server. Contains subdirectories for images, stylesheets, - and javascripts. Also contains the dispatchers and the default HTML files. This should be - set as the DOCUMENT_ROOT of your web server. - -script - Helper scripts for automation and generation. - -test - Unit and functional tests along with fixtures. When using the script/generate scripts, template - test files will be generated for you and placed in this directory. - -vendor - External libraries that the application depends on. Also includes the plugins subdirectory. - If the app has frozen rails, those gems also go here, under vendor/rails/. - This directory is in the load path. +Not much to say at this point. Other than that it would be great if new development were to be done, so far as possible...you guessed it...in pairs. \ No newline at end of file
adiel/availabletopair
56f64dcac8bf31eee6469626211a03388fffa3ce
Fixed: Not matching those with projects to those with none. Big inputs.
diff --git a/app/models/availability.rb b/app/models/availability.rb index f44eb0b..3738aea 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -1,35 +1,35 @@ class Availability < ActiveRecord::Base def pairs @pairs ||= find_pairs @pairs end def find_pairs conditions = "developer != :developer and start_time < :end_time and end_time > :start_time" condition_values = {:developer => developer, :start_time => start_time, :end_time => end_time} if project.to_s != "" - conditions += " and project = :project" + conditions += " and (project = :project or project = '')" condition_values[:project] = project end pair_conditions = [conditions, condition_values] pairs = Availability.find(:all, :conditions => pair_conditions) set_intersecting_start_and_end_times!(pairs) end def set_intersecting_start_and_end_times!(pairs) pairs.each do |pair| pair.start_time = pair.start_time > start_time ? pair.start_time : start_time pair.end_time = pair.end_time < end_time ? pair.end_time : end_time end pairs end def duration_sec end_time - start_time end end diff --git a/log/development.log b/log/development.log index c1d5145..012c00d 100644 --- a/log/development.log +++ b/log/development.log @@ -8436,512 +8436,945 @@ Rendering availabilities/index Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 58ms (View: 45, DB: 4) | 200 OK [http://127.0.0.1/availabilities] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:23:32) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 53ms (View: 41, DB: 5) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:23:32) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 42ms (View: 29, DB: 6) | 200 OK [http://127.0.0.1/availabilities] SQL (8.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:25:50) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 56ms (View: 42, DB: 13) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:25:51) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 45ms (View: 32, DB: 5) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:25:51) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 45ms (View: 31, DB: 6) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:25:51) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 46ms (View: 33, DB: 4) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:25:52) [GET] Parameters: {"id"=>"4"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 30ms (View: 16, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 17:25:55) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 53ms (View: 40, DB: 3) | 200 OK [http://127.0.0.1/availabilities/3/edit] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 17:26:41) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 138ms (View: 125, DB: 4) | 200 OK [http://127.0.0.1/availabilities/3/edit] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#update (for 127.0.0.1 at 2009-10-16 17:26:45) [PUT] Parameters: {"commit"=>"Update", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "id"=>"3", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"14", "project"=>"Cucumber", "contact"=>"http://github.com/bob", "end_time(1i)"=>"2009", "start_time(4i)"=>"13", "end_time(2i)"=>"10", "start_time(5i)"=>"00", "end_time(3i)"=>"14", "end_time(4i)"=>"15", "end_time(5i)"=>"00", "developer"=>"Bob"}} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  SQL (0.0ms) BEGIN Availability Update (0.0ms) UPDATE `availabilities` SET `project` = 'Cucumber', `updated_at` = '2009-10-16 16:26:45' WHERE `id` = 3 SQL (68.0ms) COMMIT Redirected to http://127.0.0.1:3000/availabilities/3 Completed in 87ms (DB: 71) | 302 Found [http://127.0.0.1/availabilities/3] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:26:45) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 20ms (View: 7, DB: 6) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:18) [GET] Parameters: {"id"=>"3"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 44ms (View: 20, DB: 6) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:20) [GET] Parameters: {"id"=>"3"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 20ms (View: 7, DB: 2) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:20) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 18ms (View: 7, DB: 3) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:20) [GET] Parameters: {"id"=>"3"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 19ms (View: 6, DB: 3) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:20) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 20ms (View: 6, DB: 5) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:31) [GET] Parameters: {"id"=>"3"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 31ms (View: 17, DB: 4) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:37) [GET] Parameters: {"id"=>"3"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Completed in 28ms (View: 15, DB: 5) | 200 OK [http://127.0.0.1/availabilities/3] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:27:46) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 44ms (View: 32, DB: 5) | 200 OK [http://127.0.0.1/availabilities] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:27:48) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 43ms (View: 29, DB: 8) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:27:49) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 42ms (View: 30, DB: 5) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:27:51) [GET] Parameters: {"id"=>"4"} Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 22ms (View: 8, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:28:38) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 48ms (View: 31, DB: 9) | 200 OK [http://127.0.0.1/availabilities] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:28:40) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 19ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:31:40) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 20ms (View: 8, DB: 3) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:13) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show ActionView::TemplateError (undefined method `push' for #<Hash:0x884f1e0>) on line #2 of app/views/availabilities/show.html.erb: 1: <h1><%=h @availability.developer %> is available to pair on <%= display_project(@availability) %> for <span class="duration"><%= display_duration(@availability) %></span> from <span class="time"><%=h display_when(@availability) %></span></h1> 2: <% if @availability.pairs.length == 0 %> 3: <p> 4: No developers are available to pair on <%= display_project(@availability) %> with <%=h @availability.developer %> over this period. 5: </p> app/models/availability.rb:15:in `find_pairs' app/models/availability.rb:4:in `pairs' app/views/availabilities/show.html.erb:2 app/controllers/availabilities_controller.rb:18:in `show' -e:1:in `load' -e:1 Rendered rescues/_trace (83.0ms) Rendered rescues/_request_and_response (0.0ms) Rendering rescues/layout (internal_server_error) SQL (1.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:26) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00' and project = NULL)  Completed in 19ms (View: 7, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:34:34) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00' and project = NULL)  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00' and project = NULL)  Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00' and project = NULL)  Completed in 40ms (View: 27, DB: 6) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:36) [GET] Parameters: {"id"=>"3"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  Completed in 18ms (View: 5, DB: 3) | 200 OK [http://127.0.0.1/availabilities/3] SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:37) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00' and project = NULL)  Completed in 19ms (View: 7, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:39) [GET] Parameters: {"id"=>"5"} Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 5)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00' and project = NULL)  Completed in 19ms (View: 6, DB: 3) | 200 OK [http://127.0.0.1/availabilities/5] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:40) [GET] Parameters: {"id"=>"6"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 6)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00' and project = NULL)  Completed in 18ms (View: 5, DB: 4) | 200 OK [http://127.0.0.1/availabilities/6] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:34:48) [GET] Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 55ms (View: 37, DB: 8) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:34:52) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 21ms (View: 7, DB: 6) | 200 OK [http://127.0.0.1/availabilities/4] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#new (for 127.0.0.1 at 2009-10-16 17:35:02) [GET] Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Rendering template within layouts/availabilities Rendering availabilities/new Completed in 49ms (View: 38, DB: 3) | 200 OK [http://127.0.0.1/availabilities/new] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#create (for 127.0.0.1 at 2009-10-16 17:35:28) [POST] Parameters: {"commit"=>"Publish availability", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"14", "project"=>"Cucumber", "contact"=>"", "end_time(1i)"=>"2009", "start_time(4i)"=>"00", "end_time(2i)"=>"10", "start_time(5i)"=>"00", "end_time(3i)"=>"14", "end_time(4i)"=>"19", "end_time(5i)"=>"40", "developer"=>"Aslak"}} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) BEGIN Availability Create (1.0ms) INSERT INTO `availabilities` (`updated_at`, `project`, `contact`, `developer`, `start_time`, `end_time`, `created_at`) VALUES('2009-10-16 16:35:28', 'Cucumber', '', 'Aslak', '2009-10-14 00:00:00', '2009-10-14 19:40:00', '2009-10-16 16:35:28') SQL (52.0ms) COMMIT Redirected to http://127.0.0.1:3000/availabilities/7 Completed in 71ms (DB: 57) | 302 Found [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:35:28) [GET] Parameters: {"id"=>"7"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  Completed in 19ms (View: 6, DB: 5) | 200 OK [http://127.0.0.1/availabilities/7] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 17:35:39) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  Completed in 50ms (View: 34, DB: 10) | 200 OK [http://127.0.0.1/availabilities] SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 17:35:46) [GET] Parameters: {"id"=>"4"} Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  Rendering template within layouts/availabilities Rendering availabilities/show Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  Completed in 21ms (View: 9, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:16:07) [GET] + Availability Load (2.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 62ms (View: 38, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:16:08) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 133ms (View: 117, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:16:10) [GET] + Parameters: {"id"=>"7"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 160ms (View: 148, DB: 3) | 200 OK [http://127.0.0.1/availabilities/7/edit] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:16:31) [GET] + Parameters: {"id"=>"7"} + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 62ms (View: 45, DB: 5) | 200 OK [http://127.0.0.1/availabilities/7/edit] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:16:52) [GET] + Parameters: {"id"=>"7"} + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 85ms (View: 50, DB: 5) | 200 OK [http://127.0.0.1/availabilities/7/edit] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:16:59) [GET] + Parameters: {"id"=>"7"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  +Completed in 21ms (View: 6, DB: 5) | 200 OK [http://127.0.0.1/availabilities/7] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:17:02) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 53ms (View: 39, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:17:08) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 22ms (View: 7, DB: 6) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:17:11) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  +Completed in 22ms (View: 9, DB: 5) | 200 OK [http://127.0.0.1/availabilities/4] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:17:13) [GET] + Parameters: {"id"=>"4"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 4)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 46ms (View: 33, DB: 3) | 200 OK [http://127.0.0.1/availabilities/4/edit] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#new (for 127.0.0.1 at 2009-10-16 19:22:53) [GET] + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` +Rendering template within layouts/availabilities +Rendering availabilities/new +Completed in 45ms (View: 33, DB: 5) | 200 OK [http://127.0.0.1/availabilities/new] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#new (for 127.0.0.1 at 2009-10-16 19:28:53) [GET] + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` +Rendering template within layouts/availabilities +Rendering availabilities/new +Completed in 46ms (View: 34, DB: 4) | 200 OK [http://127.0.0.1/availabilities/new] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#create (for 127.0.0.1 at 2009-10-16 19:30:28) [POST] + Parameters: {"commit"=>"Publish availability", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"16", "project"=>"Make a Ben 10 alien", "contact"=>"alexlongley@gmail.com", "end_time(1i)"=>"2009", "start_time(4i)"=>"19", "end_time(2i)"=>"10", "start_time(5i)"=>"28", "end_time(3i)"=>"16", "end_time(4i)"=>"21", "end_time(5i)"=>"00", "developer"=>"Alex"}} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + SQL (0.0ms) BEGIN + Availability Create (1.0ms) INSERT INTO `availabilities` (`updated_at`, `project`, `contact`, `developer`, `start_time`, `end_time`, `created_at`) VALUES('2009-10-16 18:30:28', 'Make a Ben 10 alien', 'alexlongley@gmail.com', 'Alex', '2009-10-16 19:28:00', '2009-10-16 21:00:00', '2009-10-16 18:30:28') + SQL (56.0ms) COMMIT +Redirected to http://127.0.0.1:3000/availabilities/8 +Completed in 77ms (DB: 60) | 302 Found [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:30:28) [GET] + Parameters: {"id"=>"8"} + Availability Columns (5.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 8)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  +Completed in 23ms (View: 7, DB: 6) | 200 OK [http://127.0.0.1/availabilities/8] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:32:37) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 60ms (View: 44, DB: 8) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#new (for 127.0.0.1 at 2009-10-16 19:33:06) [GET] + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` +Rendering template within layouts/availabilities +Rendering availabilities/new +Completed in 46ms (View: 33, DB: 3) | 200 OK [http://127.0.0.1/availabilities/new] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#create (for 127.0.0.1 at 2009-10-16 19:34:18) [POST] + Parameters: {"commit"=>"Publish availability", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"16", "project"=>"", "contact"=>"adrianlongley@gmail.com", "end_time(1i)"=>"2009", "start_time(4i)"=>"18", "end_time(2i)"=>"10", "start_time(5i)"=>"33", "end_time(3i)"=>"16", "end_time(4i)"=>"23", "end_time(5i)"=>"59", "developer"=>"Adrian"}} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + SQL (0.0ms) BEGIN + Availability Create (1.0ms) INSERT INTO `availabilities` (`updated_at`, `project`, `contact`, `developer`, `start_time`, `end_time`, `created_at`) VALUES('2009-10-16 18:34:18', '', 'adrianlongley@gmail.com', 'Adrian', '2009-10-16 18:33:00', '2009-10-16 23:59:00', '2009-10-16 18:34:18') + SQL (67.0ms) COMMIT +Redirected to http://127.0.0.1:3000/availabilities/9 +Completed in 90ms (DB: 72) | 302 Found [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:34:18) [GET] + Parameters: {"id"=>"9"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  +Completed in 20ms (View: 7, DB: 3) | 200 OK [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:34:40) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 147ms (View: 132, DB: 7) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:09) [GET] + Parameters: {"id"=>"9"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  +Completed in 21ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:19) [GET] + Parameters: {"id"=>"8"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 8)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  +Completed in 21ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/8] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:30) [GET] + Parameters: {"id"=>"7"} + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 7)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  +Completed in 22ms (View: 7, DB: 6) | 200 OK [http://127.0.0.1/availabilities/7] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:32) [GET] + Parameters: {"id"=>"3"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 3)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  +Completed in 21ms (View: 8, DB: 6) | 200 OK [http://127.0.0.1/availabilities/3] + SQL (1.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:35:42) [GET] + Parameters: {"id"=>"9"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 49ms (View: 35, DB: 5) | 200 OK [http://127.0.0.1/availabilities/9/edit] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#update (for 127.0.0.1 at 2009-10-16 19:35:45) [PUT] + Parameters: {"commit"=>"Update", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "id"=>"9", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"16", "project"=>"Make a Ben 10 alien", "contact"=>"adrianlongley@gmail.com", "end_time(1i)"=>"2009", "start_time(4i)"=>"18", "end_time(2i)"=>"10", "start_time(5i)"=>"33", "end_time(3i)"=>"16", "end_time(4i)"=>"23", "end_time(5i)"=>"59", "developer"=>"Adrian"}} + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  + SQL (1.0ms) BEGIN + Availability Update (1.0ms) UPDATE `availabilities` SET `project` = 'Make a Ben 10 alien', `updated_at` = '2009-10-16 18:35:45' WHERE `id` = 9 + SQL (84.0ms) COMMIT +Redirected to http://127.0.0.1:3000/availabilities/9 +Completed in 105ms (DB: 91) | 302 Found [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:45) [GET] + Parameters: {"id"=>"9"} + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00' and project = 'Make a Ben 10 alien')  +Completed in 20ms (View: 6, DB: 5) | 200 OK [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:35:47) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00' and project = 'Make a Ben 10 alien')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 67ms (View: 53, DB: 6) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:35:53) [GET] + Parameters: {"id"=>"8"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 8)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  +Completed in 21ms (View: 7, DB: 4) | 200 OK [http://127.0.0.1/availabilities/8] + SQL (0.0ms) SET NAMES 'utf8' + SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:37:06) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00' and project = 'Make a Ben 10 alien')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 68ms (View: 51, DB: 10) | 200 OK [http://127.0.0.1/availabilities] + SQL (1.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#edit (for 127.0.0.1 at 2009-10-16 19:37:13) [GET] + Parameters: {"id"=>"9"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/edit +Completed in 129ms (View: 116, DB: 4) | 200 OK [http://127.0.0.1/availabilities/9/edit] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#update (for 127.0.0.1 at 2009-10-16 19:37:17) [PUT] + Parameters: {"commit"=>"Update", "authenticity_token"=>"EZDTp9eCyvr66FW/bD4XkSRVCZ14Q1/YIaZSM8zHNdY=", "id"=>"9", "availability"=>{"start_time(1i)"=>"2009", "start_time(2i)"=>"10", "start_time(3i)"=>"16", "project"=>"", "contact"=>"adrianlongley@gmail.com", "end_time(1i)"=>"2009", "start_time(4i)"=>"18", "end_time(2i)"=>"10", "start_time(5i)"=>"33", "end_time(3i)"=>"16", "end_time(4i)"=>"23", "end_time(5i)"=>"59", "developer"=>"Adrian"}} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  + SQL (0.0ms) BEGIN + Availability Update (0.0ms) UPDATE `availabilities` SET `project` = '', `updated_at` = '2009-10-16 18:37:17' WHERE `id` = 9 + SQL (66.0ms) COMMIT +Redirected to http://127.0.0.1:3000/availabilities/9 +Completed in 87ms (DB: 70) | 302 Found [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#show (for 127.0.0.1 at 2009-10-16 19:37:17) [GET] + Parameters: {"id"=>"9"} + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 9)  +Rendering template within layouts/availabilities +Rendering availabilities/show + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  +Completed in 19ms (View: 8, DB: 4) | 200 OK [http://127.0.0.1/availabilities/9] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:37:19) [GET] + Availability Load (0.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and project = 'Cucumber')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and project = 'Make a Ben 10 alien')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 64ms (View: 47, DB: 9) | 200 OK [http://127.0.0.1/availabilities] + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + + +Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 19:39:18) [GET] + Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time +Rendering template within layouts/availabilities +Rendering availabilities/index + Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Aslak' and start_time < '2009-10-14 19:40:00' and end_time > '2009-10-14 00:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Bob' and start_time < '2009-10-14 15:00:00' and end_time > '2009-10-14 13:00:00' and (project = 'Cucumber' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Jeff' and start_time < '2009-10-14 19:00:00' and end_time > '2009-10-14 14:15:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Dave' and start_time < '2009-10-15 00:00:00' and end_time > '2009-10-14 16:00:00')  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Adrian' and start_time < '2009-10-16 23:59:00' and end_time > '2009-10-16 18:33:00')  + Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Alex' and start_time < '2009-10-16 21:00:00' and end_time > '2009-10-16 19:28:00' and (project = 'Make a Ben 10 alien' or project = ''))  + Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (developer != 'Henry' and start_time < '2009-10-20 17:00:00' and end_time > '2009-10-20 14:00:00')  +Completed in 67ms (View: 51, DB: 8) | 200 OK [http://127.0.0.1/availabilities] diff --git a/log/test.log b/log/test.log index d0aa545..7b87c58 100644 --- a/log/test.log +++ b/log/test.log @@ -29,512 +29,523 @@ Migrating to CreatePossiblePairs (20091014143300) SQL (3.0ms) describe `possible_pairs` SQL (0.0ms) SHOW KEYS FROM `possible_pairs` SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (38.0ms) SELECT count(*) AS count_all FROM `availabilities`  Processing AvailabilitiesController#create (for 0.0.0.0 at 2009-10-16 11:55:18) [POST] Parameters: {"availability"=>{}} SQL (0.0ms) SAVEPOINT active_record_1 Availability Create (0.0ms) INSERT INTO `availabilities` (`updated_at`, `contact`, `developer`, `start_time`, `end_time`, `created_at`) VALUES('2009-10-16 10:55:18', NULL, NULL, NULL, NULL, '2009-10-16 10:55:18') SQL (0.0ms) RELEASE SAVEPOINT active_record_1 Redirected to http://test.host/availabilities/2053932786 Completed in 8ms (DB: 110) | 302 Found [http://test.host/availabilities?] SQL (1.0ms) SELECT count(*) AS count_all FROM `availabilities`  SQL (38.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (3.0ms) SELECT count(*) AS count_all FROM `availabilities`  Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Processing AvailabilitiesController#destroy (for 0.0.0.0 at 2009-10-16 11:55:18) [DELETE] Parameters: {"id"=>"2053932785"} Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  SQL (1.0ms) SAVEPOINT active_record_1 Availability Destroy (25.0ms) DELETE FROM `availabilities` WHERE `id` = 2053932785 SQL (1.0ms) RELEASE SAVEPOINT active_record_1 Redirected to http://test.host/availabilities Completed in 29ms (DB: 70) | 302 Found [http://test.host/availabilities/2053932785] SQL (1.0ms) SELECT count(*) AS count_all FROM `availabilities`  SQL (38.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Processing AvailabilitiesController#edit (for 0.0.0.0 at 2009-10-16 11:55:18) [GET] Parameters: {"id"=>"2053932785"} Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 155ms (View: 154, DB: 39) | 200 OK [http://test.host/availabilities/2053932785/edit] SQL (1.0ms) ROLLBACK SQL (1.0ms) BEGIN Processing AvailabilitiesController#index (for 0.0.0.0 at 2009-10-16 11:55:18) [GET] Availability Load (1.0ms) SELECT * FROM `availabilities` ORDER BY start_time Rendering template within layouts/availabilities Rendering availabilities/index Completed in 13ms (View: 11, DB: 3) | 200 OK [http://test.host/availabilities] SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Processing AvailabilitiesController#new (for 0.0.0.0 at 2009-10-16 11:55:18) [GET] Rendering template within layouts/availabilities Rendering availabilities/new Completed in 29ms (View: 28, DB: 1) | 200 OK [http://test.host/availabilities/new] SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 11:55:18) [GET] Parameters: {"id"=>"2053932785"} Availability Load (1.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Rendering template within layouts/availabilities Rendering availabilities/show Completed in 6ms (View: 4, DB: 1) | 200 OK [http://test.host/availabilities/2053932785] SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  Processing AvailabilitiesController#update (for 0.0.0.0 at 2009-10-16 11:55:18) [PUT] Parameters: {"availability"=>{}, "id"=>"2053932785"} Availability Load (0.0ms) SELECT * FROM `availabilities` WHERE (`availabilities`.`id` = 2053932785)  SQL (0.0ms) SAVEPOINT active_record_1 SQL (1.0ms) RELEASE SAVEPOINT active_record_1 Redirected to http://test.host/availabilities/2053932785 Completed in 6ms (DB: 1) | 302 Found [http://test.host/availabilities/2053932785?] SQL (1.0ms) ROLLBACK SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:02:20) [GET] SQL (1.0ms) ROLLBACK SQL (1.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 12:06:40) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 2968ms (View: 2964, DB: 94) | 200 OK [http://www.example.com/] Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 12:06:44) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 20ms (View: 16, DB: 1) | 200 OK [http://www.example.com/] Processing AvailabilitiesController#create (for 0.0.0.0 at 2009-10-16 12:06:55) [POST] Parameters: {"availability"=>{}} Redirected to http://test.host/availabilities/2053932787 Completed in 4ms (DB: 128) | 302 Found [http://test.host/availabilities?] Processing AvailabilitiesController#destroy (for 0.0.0.0 at 2009-10-16 12:06:55) [DELETE] Parameters: {"id"=>"2053932785"} Redirected to http://test.host/availabilities Completed in 5ms (DB: 104) | 302 Found [http://test.host/availabilities/2053932785] Processing AvailabilitiesController#edit (for 0.0.0.0 at 2009-10-16 12:06:55) [GET] Parameters: {"id"=>"2053932785"} Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 110ms (View: 108, DB: 82) | 200 OK [http://test.host/availabilities/2053932785/edit] Processing AvailabilitiesController#index (for 0.0.0.0 at 2009-10-16 12:06:55) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 21ms (View: 18, DB: 1) | 200 OK [http://test.host/availabilities] Processing AvailabilitiesController#new (for 0.0.0.0 at 2009-10-16 12:06:55) [GET] Rendering template within layouts/availabilities Rendering availabilities/new Completed in 43ms (View: 43, DB: 1) | 200 OK [http://test.host/availabilities/new] Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:06:55) [GET] Parameters: {"id"=>"2053932785"} Rendering template within layouts/availabilities Rendering availabilities/show Completed in 7ms (View: 5, DB: 3) | 200 OK [http://test.host/availabilities/2053932785] Processing AvailabilitiesController#update (for 0.0.0.0 at 2009-10-16 12:06:55) [PUT] Parameters: {"id"=>"2053932785", "availability"=>{}} Redirected to http://test.host/availabilities/2053932785 Completed in 7ms (DB: 7) | 302 Found [http://test.host/availabilities/2053932785?] Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 12:08:07) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 3194ms (View: 3191, DB: 70) | 200 OK [http://www.example.com/] Processing AvailabilitiesController#index (for 127.0.0.1 at 2009-10-16 12:08:10) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 18ms (View: 15, DB: 1) | 200 OK [http://www.example.com/] Processing AvailabilitiesController#create (for 0.0.0.0 at 2009-10-16 12:08:21) [POST] Parameters: {"availability"=>{}} Redirected to http://test.host/availabilities/2053932788 Completed in 4ms (DB: 132) | 302 Found [http://test.host/availabilities?] Processing AvailabilitiesController#destroy (for 0.0.0.0 at 2009-10-16 12:08:21) [DELETE] Parameters: {"id"=>"2053932785"} Redirected to http://test.host/availabilities Completed in 3ms (DB: 223) | 302 Found [http://test.host/availabilities/2053932785] Processing AvailabilitiesController#edit (for 0.0.0.0 at 2009-10-16 12:08:22) [GET] Parameters: {"id"=>"2053932785"} Rendering template within layouts/availabilities Rendering availabilities/edit Completed in 22ms (View: 20, DB: 385) | 200 OK [http://test.host/availabilities/2053932785/edit] Processing AvailabilitiesController#index (for 0.0.0.0 at 2009-10-16 12:08:22) [GET] Rendering template within layouts/availabilities Rendering availabilities/index Completed in 12ms (View: 11, DB: 2) | 200 OK [http://test.host/availabilities] Processing AvailabilitiesController#new (for 0.0.0.0 at 2009-10-16 12:08:22) [GET] Rendering template within layouts/availabilities Rendering availabilities/new Completed in 28ms (View: 28, DB: 0) | 200 OK [http://test.host/availabilities/new] Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:08:22) [GET] Parameters: {"id"=>"2053932785"} Rendering template within layouts/availabilities Rendering availabilities/show Processing AvailabilitiesController#update (for 0.0.0.0 at 2009-10-16 12:08:22) [PUT] Parameters: {"id"=>"2053932785", "availability"=>{}} Redirected to http://test.host/availabilities/2053932785 Completed in 4ms (DB: 3) | 302 Found [http://test.host/availabilities/2053932785?] SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:24:08) [GET] SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:25:03) [GET] SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` Processing AvailabilitiesController#show (for 0.0.0.0 at 2009-10-16 12:25:31) [GET] SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (1.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (1.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (1.0ms) SHOW TABLES SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (1.0ms) SHOW TABLES SQL (1.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (1.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (1.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (1.0ms) BEGIN Rendering availabilities2/show SQL (0.0ms) ROLLBACK SQL (1.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (1.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (1.0ms) SHOW TABLES SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (1.0ms) SHOW TABLES SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (1.0ms) SHOW TABLES SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (1.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (2.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (0.0ms) BEGIN Availability Columns (3.0ms) SHOW FIELDS FROM `availabilities` SQL (1.0ms) ROLLBACK SQL (0.0ms) BEGIN SQL (1.0ms) ROLLBACK SQL (1.0ms) BEGIN SQL (0.0ms) ROLLBACK SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (1.0ms) SHOW TABLES SQL (1.0ms) SELECT version FROM schema_migrations Migrating to CreateAvailabilities (20091014095413) Migrating to AddAvailabilitiesIndexes (20091016152100) SQL (361.0ms) CREATE INDEX `availabilities_name_index` ON `availabilities` (`developer`) SQL (298.0ms) CREATE INDEX `availabilities_pair_search_index` ON `availabilities` (`developer`, `start_time`, `end_time`) SQL (102.0ms) INSERT INTO schema_migrations (version) VALUES ('20091016152100') SQL (1.0ms) SHOW TABLES SQL (0.0ms) SELECT version FROM schema_migrations SQL (1.0ms) SHOW TABLES SQL (3.0ms) SHOW FIELDS FROM `availabilities` SQL (3.0ms) describe `availabilities` SQL (1.0ms) SHOW KEYS FROM `availabilities` SQL (3.0ms) SHOW FIELDS FROM `possible_pairs` SQL (3.0ms) describe `possible_pairs` SQL (0.0ms) SHOW KEYS FROM `possible_pairs` SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (1.0ms) SHOW TABLES SQL (0.0ms) SELECT version FROM schema_migrations Migrating to CreateAvailabilities (20091014095413) Migrating to AddAvailabilitiesIndexes (20091016152100) SQL (1.0ms) SHOW TABLES SQL (0.0ms) SELECT version FROM schema_migrations SQL (0.0ms) SHOW TABLES SQL (2.0ms) SHOW FIELDS FROM `availabilities` SQL (2.0ms) describe `availabilities` SQL (1.0ms) SHOW KEYS FROM `availabilities` SQL (3.0ms) SHOW FIELDS FROM `possible_pairs` SQL (3.0ms) describe `possible_pairs` SQL (0.0ms) SHOW KEYS FROM `possible_pairs` SQL (0.0ms) SET NAMES 'utf8' SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 SQL (1.0ms) SHOW TABLES SQL (1.0ms) SELECT version FROM schema_migrations Migrating to CreateAvailabilities (20091014095413) Migrating to AddAvailabilitiesIndexes (20091016152100) Migrating to AmendAvailabilitiesAddProject (20091016171300) SQL (410.0ms) ALTER TABLE `availabilities` ADD `project` varchar(255) SQL (51.0ms) INSERT INTO schema_migrations (version) VALUES ('20091016171300') SQL (1.0ms) SHOW TABLES SQL (0.0ms) SELECT version FROM schema_migrations SQL (0.0ms) SHOW TABLES SQL (3.0ms) SHOW FIELDS FROM `availabilities` SQL (3.0ms) describe `availabilities` SQL (0.0ms) SHOW KEYS FROM `availabilities` SQL (3.0ms) SHOW FIELDS FROM `possible_pairs` SQL (3.0ms) describe `possible_pairs` SQL (1.0ms) SHOW KEYS FROM `possible_pairs` + SQL (0.0ms) SET NAMES 'utf8' + SQL (0.0ms) SET SQL_AUTO_IS_NULL=0 + SQL (0.0ms) BEGIN + Availability Columns (4.0ms) SHOW FIELDS FROM `availabilities` + SQL (0.0ms) ROLLBACK + SQL (0.0ms) BEGIN + SQL (0.0ms) ROLLBACK + SQL (0.0ms) BEGIN + SQL (1.0ms) ROLLBACK + SQL (1.0ms) BEGIN + SQL (1.0ms) ROLLBACK diff --git a/public/stylesheets/all.css b/public/stylesheets/all.css index 88c8904..350f1bd 100644 --- a/public/stylesheets/all.css +++ b/public/stylesheets/all.css @@ -1,50 +1,55 @@ html, body { color:black; height:100%; } body { font-family:helvetica,arial,freesans,clean,sans-serif; } table { font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:80%; border-collapse: collapse; width:95% } table th { background-color:#EAEAEA; border-bottom:1px solid #D8D8D8; color:#999999; font-weight:normal; padding:0.5em 0.5em; text-align:left; } table td { background:#F8F8F8; border-bottom:1px solid #E1E1E1; color:#484848; padding:0.5em 0.5em; } p { margin:1em; } .availabilities, .pairs { margin:0.5em 1em; } h1 { font-size:1.2em; margin:0.8em; } #header { font-size:2em; padding:20px; background-color:#DADADA; font-family:Courier new,helvetica,arial,freesans,clean,sans-serif;; +} + +input,select { + font-size:1.3em; + padding:0.2em; } \ No newline at end of file diff --git a/spec/models/availability_spec.rb b/spec/models/availability_spec.rb index c36089b..5d58679 100644 --- a/spec/models/availability_spec.rb +++ b/spec/models/availability_spec.rb @@ -1,51 +1,71 @@ require 'spec_helper' describe Availability do it "should find pairs as matching availabilities for different developers where times overlap" do availability = Availability.new(:start_time => Time.now,:end_time => Time.now) availability.developer = "currentDev" expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] Availability.stub!(:find).with(:all, :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time", {:developer => availability.developer, :start_time => availability.start_time, :end_time => availability.end_time}]).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs.should be(expected_pairs) end + describe "when a project has been specified" do + + it "should set the end time of each pair to the earlier of the two end times" do + availability = Availability.new(:start_time => Time.now,:end_time => Time.now) + availability.developer = "currentDev" + availability.project = "some proj" + expected_pairs = [Availability.new(:start_time => Time.now,:end_time => Time.now)] + Availability.stub!(:find).with(:all, + :conditions => ["developer != :developer and start_time < :end_time and end_time > :start_time and (project = :project or project = '')", + {:developer => availability.developer, + :start_time => availability.start_time, + :end_time => availability.end_time, + :project => availability.project}]).and_return(expected_pairs) + + actual_pairs = availability.pairs + + actual_pairs.should be(expected_pairs) + end + end + it "should set the start time of each pair to the later of the two start times" do availability = Availability.new(:start_time => Time.parse("2012-06-01 15:25"),:end_time => Time.now) pair_1 = Availability.new(:start_time => Time.parse("2012-06-01 15:26"),:end_time => Time.now) pair_2 = Availability.new(:start_time => Time.parse("2012-06-01 15:24"),:end_time => Time.now) expected_pairs = [pair_1,pair_2] Availability.stub!(:find).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs[0].start_time.should be (pair_1.start_time) actual_pairs[1].start_time.should be (availability.start_time) end it "should set the end time of each pair to the earlier of the two end times" do availability = Availability.new(:end_time => Time.parse("2012-06-01 15:25"),:start_time => Time.now) pair_1 = Availability.new(:end_time => Time.parse("2012-06-01 15:24"),:start_time => Time.now) pair_2 = Availability.new(:end_time => Time.parse("2012-06-01 15:26"),:start_time => Time.now) expected_pairs = [pair_1,pair_2] Availability.stub!(:find).and_return(expected_pairs) actual_pairs = availability.pairs actual_pairs[0].end_time.should be (pair_1.end_time) actual_pairs[1].end_time.should be (availability.end_time) end end
jordi-chacon/pongerl
b5ea6c62c031b42bbfe1f5cdb09a9996fa47e4b8
Fixed bug when the bar of client1 touches the ball
diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index b83a55e..0ea5624 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,279 +1,279 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, result = {0, 0}, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, {{C1, C2, State#state.ball}, NS}; not_started -> {not_started, State}; restarting -> {{restarting, State#state.result}, State} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball, status = Status} = State) -> case Status of restarting -> timer:sleep(?PAUSE_AFTER_GOAL); _ -> ok end, #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, {Reply, State2} = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game, client1} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1 + 1, GoalsC2}}}; {NewBall, end_of_game, client2} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1, GoalsC2 + 1}}}; NewBall -> {ok, State} end, {reply, Reply, State2#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?FX0 + 2, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?FX0 + ?FX - 1 - ?CX, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?FY0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?FY0 + ?FY -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Speed = Ball#ball.speed, Ball#ball{path = Path, speed = Speed}; % end of game run_step({X1, _Y1}, {_X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when X1 =:= XB -> {Ball#ball{path = Path}, end_of_game, client2}; run_step({_X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when XB + ?BX - 1 =:= X2 -> {Ball#ball{path = Path}, end_of_game, client1}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) - when XB =:= X1 + 1 -> + when XB =:= X1 + ?CX -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY - 1 of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY - 1 of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when YB =:= ?FY0 + 1 orelse YB + ?BY =:= ?FY0 + ?FY -> Degrees = get_new_degree(Ball#ball.degrees, wall), {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY, degrees = Degrees}, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, client_bar) -> 0; get_new_degree(0, client_bar) -> 180; get_new_degree(45, client_bar) -> 135; get_new_degree(135, client_bar) -> 45; get_new_degree(225, client_bar) -> 315; get_new_degree(315, client_bar) -> 225; get_new_degree(45, wall) -> 315; get_new_degree(315, wall) -> 45; get_new_degree(135, wall) -> 225; get_new_degree(225, wall) -> 135. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}; get_next_ball_position(X, Y, 45) -> {X + 1, Y - 1}; get_next_ball_position(X, Y, 135) -> {X - 1, Y - 1}; get_next_ball_position(X, Y, 225) -> {X - 1, Y + 1}; get_next_ball_position(X, Y, 315) -> {X + 1, Y + 1}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> restart_game() end.
jordi-chacon/pongerl
5a3f90ac804200eaa6d5d8adf5c37d9bd05e4490
Fixed bug when restarting the game
diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index ea70eee..b83a55e 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,282 +1,279 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, result = {0, 0}, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, {{C1, C2, State#state.ball}, NS}; not_started -> {not_started, State}; - restarting -> - {{restarting, State#state.result}, - State#state{status = {restarting, ID}}}; - {restarting, ID} = St -> - {{restarting, State#state.result}, State#state{status = St}}; - {restarting, _ID2} -> - timer:sleep(?PAUSE_AFTER_GOAL), - {{restarting, State#state.result}, - State#state{status = not_started}} + restarting -> {{restarting, State#state.result}, State} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. -do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> +do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball, + status = Status} = State) -> + case Status of + restarting -> timer:sleep(?PAUSE_AFTER_GOAL); + _ -> ok + end, #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, {Reply, State2} = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game, client1} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1 + 1, GoalsC2}}}; {NewBall, end_of_game, client2} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1, GoalsC2 + 1}}}; NewBall -> {ok, State} end, {reply, Reply, State2#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?FX0 + 2, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?FX0 + ?FX - 1 - ?CX, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?FY0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?FY0 + ?FY -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Speed = Ball#ball.speed, Ball#ball{path = Path, speed = Speed}; % end of game run_step({X1, _Y1}, {_X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when X1 =:= XB -> {Ball#ball{path = Path}, end_of_game, client2}; run_step({_X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when XB + ?BX - 1 =:= X2 -> {Ball#ball{path = Path}, end_of_game, client1}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY - 1 of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY - 1 of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when YB =:= ?FY0 + 1 orelse YB + ?BY =:= ?FY0 + ?FY -> Degrees = get_new_degree(Ball#ball.degrees, wall), {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY, degrees = Degrees}, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, client_bar) -> 0; get_new_degree(0, client_bar) -> 180; get_new_degree(45, client_bar) -> 135; get_new_degree(135, client_bar) -> 45; get_new_degree(225, client_bar) -> 315; get_new_degree(315, client_bar) -> 225; get_new_degree(45, wall) -> 315; get_new_degree(315, wall) -> 45; get_new_degree(135, wall) -> 225; get_new_degree(225, wall) -> 135. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}; get_next_ball_position(X, Y, 45) -> {X + 1, Y - 1}; get_next_ball_position(X, Y, 135) -> {X - 1, Y - 1}; get_next_ball_position(X, Y, 225) -> {X - 1, Y + 1}; get_next_ball_position(X, Y, 315) -> {X + 1, Y + 1}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> restart_game() end.
jordi-chacon/pongerl
91905e3e745773559bf63a6619ba40c6d964271f
Changed fontsize to 4 so that the quality of the graphics is better. Adapted the size of the field, scoreboard and so on to the new fontsize
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index dcc1bcc..e51dac5 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,55 +1,55 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Positions of the field --define(FX0, 22). --define(FY0, 4). +-define(FX0, 60). +-define(FY0, 10). % Dimensions of the field --define(FX, 40). --define(FY, 20). +-define(FX, 240). +-define(FY, 90). % Dimensions of the bars of the clients --define(CY, 3). --define(CX, 1). +-define(CY, 14). +-define(CX, 2). % Dimensions of the ball --define(BX, 2). --define(BY, 1). +-define(BX, 8). +-define(BY, 4). % Dimensions of the numbers of the score -define(NX, 6). -define(NY, 5). +-define(NFACTOR, 3). % Positions first number of result --define(N1X0, 9). --define(N1Y0, 11). +-define(N1X0, 30). +-define(N1Y0, 45). % Positions second number of result --define(N2X0, ?FX0 + ?FX + 7). --define(N2Y0, 11). +-define(N2X0, ?FX0 + ?FX + 10). +-define(N2Y0, 45). % Round length -define(ROUND_LENGTH, 100). - % Pause after goal -define(PAUSE_AFTER_GOAL, 3000). % Color pairs -define(CLIENT_PAIR, 1). -define(BALL_PAIR, 2). -define(FIELD_PAIR, 3). -define(RESULT_PAIR, 4). -define(BG_PAIR, 5). -record(ball, {x = (?FX + ?FX0) div 2, y = (?FY + ?FY0) div 2, - speed = 1, + speed = 2, degrees = 135, path = [{(?FX + ?FX0) div 2, (?FY + ?FY0) div 2}]}). -record(client, {id, x = 0, y = 0, path = []}). diff --git a/src/pongerl_client_utils.erl b/src/pongerl_client_utils.erl index 16b9797..a56fd21 100644 --- a/src/pongerl_client_utils.erl +++ b/src/pongerl_client_utils.erl @@ -1,193 +1,137 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client_utils). -export([draw_number/4]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). draw_number(0, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 2, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X), - cecho:addstr(" "), - cecho:move(Y +3 , X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(1, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X + 4), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X + 4), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 4, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(2, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(3, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X + 2), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 2, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(4, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y, X + 4), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X + 4), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 0, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 4, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(5, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(6, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(7, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X + 4), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 4, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(8, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(9, X, Y, _) -> cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), - cecho:move(Y, X), - cecho:addstr(" "), - cecho:move(Y + 1, X), - cecho:addstr(" "), - cecho:move(Y + 1, X + 4), - cecho:addstr(" "), - cecho:move(Y + 2, X), - cecho:addstr(" "), - cecho:move(Y + 3, X + 4), - cecho:addstr(" "), - cecho:move(Y + 4, X), - cecho:addstr(" "), + adapt_to_factor(Y, 0, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 1, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 2, X, 0, " ", ?NFACTOR), + adapt_to_factor(Y, 3, X, 4, " ", ?NFACTOR), + adapt_to_factor(Y, 4, X, 0, " ", ?NFACTOR), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); draw_number(N, X, Y, 1) -> FirstDigit = N div 10, SecondDigit = N rem 10, - draw_number(FirstDigit, X - ?NX - 1, Y, 1), + draw_number(FirstDigit, X - (?NX - 1) * ?NFACTOR , Y, 1), draw_number(SecondDigit, X, Y, 1); draw_number(N, X, Y, 2) -> FirstDigit = N div 10, SecondDigit = N rem 10, draw_number(FirstDigit, X, Y, 1), - draw_number(SecondDigit, X + ?NX + 1, Y, 1). + draw_number(SecondDigit, X + (?NX + 1) * ?NFACTOR, Y, 1). + +adapt_to_factor(Y, OffsetY, X, OffsetX, Str, Factor) -> + adapt_to_factor2(Y + OffsetY * Factor, X + OffsetX * Factor, + factor_spaces(Str, Factor), Factor). + +adapt_to_factor2(_Y, _X, _Str, 0) -> ok; +adapt_to_factor2(Y, X, Str, Left) -> + cecho:move(Y, X), + cecho:addstr(Str), + adapt_to_factor2(Y + 1, X, Str, Left - 1). + +factor_spaces(Str, N) -> + factor_spaces(Str, N, []). +factor_spaces(_Str, 0, Acc) -> + Acc; +factor_spaces(Str, N, Acc) -> + factor_spaces(Str, N - 1, Str ++ Acc). diff --git a/start.sh b/start.sh index 2dda122..21badc6 100644 --- a/start.sh +++ b/start.sh @@ -1,37 +1,37 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc execute_server() { erl -name server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl } execute_client() { profile=$(gconftool --get /apps/gnome-terminal/global/default_profile) old_font=$(gconftool --get /apps/gnome-terminal/profiles/${profile}/font) profileAtom="'"${profile}"'" font="\""$old_font"\"" - gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 8" + gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 4" # change the server host for the one you are using erl -noinput -pa ./ebin ${CECHO_EBIN} -name $1 -setcookie pongerl -eval "pongerl_client:start($profileAtom, $font, server@ardilla.lan)" +A 200 } if [ $# -eq 0 ]; then execute_server else opt=$(echo $1 | sed 's/=.*//') case $opt in "--server") execute_server ;; "--c1") execute_client "c1" ;; "--c2") execute_client "c2" ;; esac fi
jordi-chacon/pongerl
6d9baf27dfe272cd275bdaf2b00d9fc8d48a6437
Added basic degrees functionality to the ball
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 05b997a..dcc1bcc 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,55 +1,55 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Positions of the field -define(FX0, 22). -define(FY0, 4). % Dimensions of the field -define(FX, 40). -define(FY, 20). % Dimensions of the bars of the clients -define(CY, 3). -define(CX, 1). % Dimensions of the ball -define(BX, 2). -define(BY, 1). % Dimensions of the numbers of the score -define(NX, 6). -define(NY, 5). % Positions first number of result -define(N1X0, 9). -define(N1Y0, 11). % Positions second number of result -define(N2X0, ?FX0 + ?FX + 7). -define(N2Y0, 11). % Round length -define(ROUND_LENGTH, 100). % Pause after goal -define(PAUSE_AFTER_GOAL, 3000). % Color pairs -define(CLIENT_PAIR, 1). -define(BALL_PAIR, 2). -define(FIELD_PAIR, 3). -define(RESULT_PAIR, 4). -define(BG_PAIR, 5). -record(ball, {x = (?FX + ?FX0) div 2, y = (?FY + ?FY0) div 2, speed = 1, - degrees = 180, + degrees = 135, path = [{(?FX + ?FX0) div 2, (?FY + ?FY0) div 2}]}). -record(client, {id, x = 0, y = 0, path = []}). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 1cf7212..ea70eee 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,261 +1,282 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, result = {0, 0}, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, {{C1, C2, State#state.ball}, NS}; not_started -> {not_started, State}; restarting -> {{restarting, State#state.result}, State#state{status = {restarting, ID}}}; {restarting, ID} = St -> {{restarting, State#state.result}, State#state{status = St}}; {restarting, _ID2} -> - {{restarting, State#state.result}, + timer:sleep(?PAUSE_AFTER_GOAL), + {{restarting, State#state.result}, State#state{status = not_started}} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, {Reply, State2} = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game, client1} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1 + 1, GoalsC2}}}; {NewBall, end_of_game, client2} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1, GoalsC2 + 1}}}; NewBall -> {ok, State} end, {reply, Reply, State2#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?FX0 + 2, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?FX0 + ?FX - 1 - ?CX, Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?FY0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?FY0 + ?FY -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> - Ball#ball{path = Path}; + Speed = Ball#ball.speed, + Ball#ball{path = Path, speed = Speed}; % end of game run_step({X1, _Y1}, {_X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when X1 =:= XB -> {Ball#ball{path = Path}, end_of_game, client2}; run_step({_X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when XB + ?BX - 1 =:= X2 -> {Ball#ball{path = Path}, end_of_game, client1}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY - 1 of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball - NewDegrees = get_new_degree(Degrees, opposite), + NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY - 1 of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball - NewDegrees = get_new_degree(Degrees, opposite), + NewDegrees = get_new_degree(Degrees, client_bar), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); +run_step(P1, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) + when YB =:= ?FY0 + 1 orelse YB + ?BY =:= ?FY0 + ?FY -> + Degrees = get_new_degree(Ball#ball.degrees, wall), + {NX, NY} = get_next_ball_position(XB, YB, Degrees), + NewPath = [{NX, NY} | Path], + run_step(P1, P2, Ball#ball{x = NX, y = NY, degrees = Degrees}, + NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). -get_new_degree(180, opposite) -> 0; -get_new_degree(0, opposite) -> 180. +get_new_degree(180, client_bar) -> 0; +get_new_degree(0, client_bar) -> 180; +get_new_degree(45, client_bar) -> 135; +get_new_degree(135, client_bar) -> 45; +get_new_degree(225, client_bar) -> 315; +get_new_degree(315, client_bar) -> 225; +get_new_degree(45, wall) -> 315; +get_new_degree(315, wall) -> 45; +get_new_degree(135, wall) -> 225; +get_new_degree(225, wall) -> 135. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; -get_next_ball_position(X, Y, 0) -> {X + 1, Y}. +get_next_ball_position(X, Y, 0) -> {X + 1, Y}; +get_next_ball_position(X, Y, 45) -> {X + 1, Y - 1}; +get_next_ball_position(X, Y, 135) -> {X - 1, Y - 1}; +get_next_ball_position(X, Y, 225) -> {X - 1, Y + 1}; +get_next_ball_position(X, Y, 315) -> {X + 1, Y + 1}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); - end_of_game -> timer:sleep(?PAUSE_AFTER_GOAL), restart_game() + end_of_game -> restart_game() end.
jordi-chacon/pongerl
7f2da0e1084f8d72d869d3eb9b303733d7d29e2d
Adapted code to make the game distributed through a local network
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index 27b44f2..972f978 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,155 +1,155 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). --export([start/2]). +-export([start/3]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). -start(Profile, OldFont) -> +start(Profile, OldFont, Server) -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?BG_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_YELLOW), cecho:init_pair(?RESULT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_GREEN), draw_field(), draw_result(), - ID = rpc(connect_client, []), + ID = rpc(Server, connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), - spawn_link(fun() -> key_input_loop(ID, Profile, OldFont) end), - spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). + spawn_link(fun() -> key_input_loop(Server, ID, Profile, OldFont) end), + spawn_link(fun() -> draw_game_loop(Server, ID, ClientStr, BallStr) end). -key_input_loop(ID, Profile, OldFont) -> +key_input_loop(Server, ID, Profile, OldFont) -> C = cecho:getch(), case C of $a -> - ok = rpc(change_client_position, [ID, ?UP]), - key_input_loop(ID, Profile, OldFont); + ok = rpc(Server, change_client_position, [ID, ?UP]), + key_input_loop(Server, ID, Profile, OldFont); $z -> - ok = rpc(change_client_position, [ID, ?DOWN]), - key_input_loop(ID, Profile, OldFont); + ok = rpc(Server, change_client_position, [ID, ?DOWN]), + key_input_loop(Server, ID, Profile, OldFont); $q -> restore_terminal_font(Profile, OldFont), cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> - key_input_loop(ID, Profile, OldFont) + key_input_loop(Server, ID, Profile, OldFont) end. -draw_game_loop(ID, ClientStr, BallStr) -> - case rpc(get_state, [ID]) of +draw_game_loop(Server, ID, ClientStr, BallStr) -> + case rpc(Server, get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); {restarting, Result} -> draw_field(), draw_result(Result); {C1, C2, Ball} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, - draw_game_loop(ID, ClientStr, BallStr). + draw_game_loop(Server, ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> Path1 = clean_path(ID, C1), Path2 = clean_path(ID, C2), PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?BG_PAIR, Pos), cecho:attron(?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> {H, W} = cecho:getmaxyx(), cecho:attron(?ceCOLOR_PAIR(?BG_PAIR)), draw_background(0, H, W), draw_limits(), cecho:refresh(). draw_limits() -> cecho:attron(?ceCOLOR_PAIR(?FIELD_PAIR)), cecho:move(?FY0 - 1, ?FX0 - 2), cecho:hline($ , ?FX + 4), cecho:move(?FY0, ?FX0 - 2), cecho:vline($ , ?FY), cecho:move(?FY0, ?FX0 - 1), cecho:vline($ , ?FY), cecho:move(?FY0, ?FX0 + ?FX), cecho:vline($ , ?FY), cecho:move(?FY0, ?FX0 + ?FX + 1), cecho:vline($ , ?FY), cecho:move(?FY0 + ?FY, ?FX0 - 2), cecho:hline($ , ?FX + 4), cecho:attroff(?ceCOLOR_PAIR(?FIELD_PAIR)). draw_background(Height, Height, _Width) -> ok; draw_background(N, Height, Width) -> cecho:move(N, 0), cecho:hline($ , Width), draw_background(N + 1, Height, Width). draw_result() -> draw_result({0, 0}). draw_result({GC1, GC2}) -> pongerl_client_utils:draw_number(GC1, ?N1X0, ?N1Y0, 1), pongerl_client_utils:draw_number(GC2, ?N2X0, ?N2Y0, 2). clean_path(ID, #client{} = C) -> clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; clean_path(ID, #ball{} = B) -> clean_path(ID, B#ball.path, []). clean_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_path(ID, T, Acc); clean_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(ID, [{X, Y} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). restore_terminal_font(Profile, OldFont) -> ProfileStr = atom_to_list(Profile), Cmd = "gconftool --set /apps/gnome-terminal/profiles/" ++ ProfileStr ++ "/font --type string \"" ++ OldFont ++ "\"", os:cmd(Cmd). -rpc(Function, Args) -> - rpc:call(server@ardilla, pongerl_server, Function, Args). +rpc(Server, Function, Args) -> + rpc:call(Server, pongerl_server, Function, Args). diff --git a/start.sh b/start.sh index 738cfda..2dda122 100644 --- a/start.sh +++ b/start.sh @@ -1,36 +1,37 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc execute_server() { - erl -sname server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl + erl -name server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl } execute_client() { profile=$(gconftool --get /apps/gnome-terminal/global/default_profile) old_font=$(gconftool --get /apps/gnome-terminal/profiles/${profile}/font) profileAtom="'"${profile}"'" font="\""$old_font"\"" gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 8" - erl -noinput -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval "pongerl_client:start($profileAtom, $font)" +A 200 + # change the server host for the one you are using + erl -noinput -pa ./ebin ${CECHO_EBIN} -name $1 -setcookie pongerl -eval "pongerl_client:start($profileAtom, $font, server@ardilla.lan)" +A 200 } if [ $# -eq 0 ]; then execute_server else opt=$(echo $1 | sed 's/=.*//') case $opt in "--server") execute_server ;; "--c1") execute_client "c1" ;; "--c2") execute_client "c2" ;; esac fi
jordi-chacon/pongerl
6ed429abc3b0e8446f08c20171cec400cf07136f
Implemented scoreboard to show the current result of the game. It shows up to 99 goals. Changed how the limits of the fields look.
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 17c09ca..05b997a 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,39 +1,55 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). +% Positions of the field +-define(FX0, 22). +-define(FY0, 4). + % Dimensions of the field --define(X0, 0). --define(Y0, 0). --define(XF, 40). --define(YF, 20). +-define(FX, 40). +-define(FY, 20). % Dimensions of the bars of the clients -define(CY, 3). -define(CX, 1). % Dimensions of the ball -define(BX, 2). -define(BY, 1). +% Dimensions of the numbers of the score +-define(NX, 6). +-define(NY, 5). + +% Positions first number of result +-define(N1X0, 9). +-define(N1Y0, 11). + +% Positions second number of result +-define(N2X0, ?FX0 + ?FX + 7). +-define(N2Y0, 11). + % Round length -define(ROUND_LENGTH, 100). % Pause after goal --define(PAUSE_AFTER_GOAL, 2000). +-define(PAUSE_AFTER_GOAL, 3000). % Color pairs -define(CLIENT_PAIR, 1). -define(BALL_PAIR, 2). -define(FIELD_PAIR, 3). +-define(RESULT_PAIR, 4). +-define(BG_PAIR, 5). --record(ball, {x = (?XF - ?X0) div 2, - y = (?YF - ?Y0) div 2, +-record(ball, {x = (?FX + ?FX0) div 2, + y = (?FY + ?FY0) div 2, speed = 1, degrees = 180, - path = [{(?XF - ?X0) div 2, (?YF - ?Y0) div 2}]}). + path = [{(?FX + ?FX0) div 2, (?FY + ?FY0) div 2}]}). -record(client, {id, x = 0, y = 0, path = []}). diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index 2f486e7..27b44f2 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,120 +1,155 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/2]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start(Profile, OldFont) -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), - cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), + cecho:init_pair(?BG_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), + cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_YELLOW), + cecho:init_pair(?RESULT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_GREEN), draw_field(), + draw_result(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), spawn_link(fun() -> key_input_loop(ID, Profile, OldFont) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID, Profile, OldFont) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID, Profile, OldFont); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID, Profile, OldFont); $q -> restore_terminal_font(Profile, OldFont), cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> key_input_loop(ID, Profile, OldFont) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); - restarting -> - timer:sleep(?PAUSE_AFTER_GOAL div 4), - draw_field(); - {C1, C2, Ball, _Result} -> + {restarting, Result} -> + draw_field(), + draw_result(Result); + {C1, C2, Ball} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> Path1 = clean_path(ID, C1), Path2 = clean_path(ID, C2), PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, - ?FIELD_PAIR, Pos), - cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), + ?BG_PAIR, Pos), + cecho:attron(?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), - cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), + cecho:attroff(?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> - Str = generate_spaces(?XF - ?X0), - draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). + {H, W} = cecho:getmaxyx(), + cecho:attron(?ceCOLOR_PAIR(?BG_PAIR)), + draw_background(0, H, W), + draw_limits(), + cecho:refresh(). + +draw_limits() -> + cecho:attron(?ceCOLOR_PAIR(?FIELD_PAIR)), + cecho:move(?FY0 - 1, ?FX0 - 2), + cecho:hline($ , ?FX + 4), + cecho:move(?FY0, ?FX0 - 2), + cecho:vline($ , ?FY), + cecho:move(?FY0, ?FX0 - 1), + cecho:vline($ , ?FY), + cecho:move(?FY0, ?FX0 + ?FX), + cecho:vline($ , ?FY), + cecho:move(?FY0, ?FX0 + ?FX + 1), + cecho:vline($ , ?FY), + cecho:move(?FY0 + ?FY, ?FX0 - 2), + cecho:hline($ , ?FX + 4), + cecho:attroff(?ceCOLOR_PAIR(?FIELD_PAIR)). + +draw_background(Height, Height, _Width) -> ok; +draw_background(N, Height, Width) -> + cecho:move(N, 0), + cecho:hline($ , Width), + draw_background(N + 1, Height, Width). + +draw_result() -> + draw_result({0, 0}). + +draw_result({GC1, GC2}) -> + pongerl_client_utils:draw_number(GC1, ?N1X0, ?N1Y0, 1), + pongerl_client_utils:draw_number(GC2, ?N2X0, ?N2Y0, 2). clean_path(ID, #client{} = C) -> clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; clean_path(ID, #ball{} = B) -> clean_path(ID, B#ball.path, []). clean_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_path(ID, T, Acc); clean_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(ID, [{X, Y} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). restore_terminal_font(Profile, OldFont) -> ProfileStr = atom_to_list(Profile), Cmd = "gconftool --set /apps/gnome-terminal/profiles/" ++ ProfileStr ++ "/font --type string \"" ++ OldFont ++ "\"", os:cmd(Cmd). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/src/pongerl_client_utils.erl b/src/pongerl_client_utils.erl new file mode 100644 index 0000000..16b9797 --- /dev/null +++ b/src/pongerl_client_utils.erl @@ -0,0 +1,193 @@ +%%% @author Jordi Chacon <jordi.chacon@gmail.com> +%%% @copyright (C) 2010, Jordi Chacon + +-module(pongerl_client_utils). + +-export([draw_number/4]). + +-include_lib("../include/pongerl.hrl"). +-include_lib("../dep/cecho/include/cecho.hrl"). + +draw_number(0, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 2, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X), + cecho:addstr(" "), + cecho:move(Y +3 , X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(1, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X + 4), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X + 4), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(2, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(3, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X + 2), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(4, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y, X + 4), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X + 4), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(5, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(6, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(7, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X + 4), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(8, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(9, X, Y, _) -> + cecho:attron(?ceCOLOR_PAIR(?RESULT_PAIR)), + cecho:move(Y, X), + cecho:addstr(" "), + cecho:move(Y + 1, X), + cecho:addstr(" "), + cecho:move(Y + 1, X + 4), + cecho:addstr(" "), + cecho:move(Y + 2, X), + cecho:addstr(" "), + cecho:move(Y + 3, X + 4), + cecho:addstr(" "), + cecho:move(Y + 4, X), + cecho:addstr(" "), + cecho:refresh(), + cecho:attroff(?ceCOLOR_PAIR(?RESULT_PAIR)); +draw_number(N, X, Y, 1) -> + FirstDigit = N div 10, + SecondDigit = N rem 10, + draw_number(FirstDigit, X - ?NX - 1, Y, 1), + draw_number(SecondDigit, X, Y, 1); +draw_number(N, X, Y, 2) -> + FirstDigit = N div 10, + SecondDigit = N rem 10, + draw_number(FirstDigit, X, Y, 1), + draw_number(SecondDigit, X + ?NX + 1, Y, 1). + diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 052f485..1cf7212 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,255 +1,261 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, result = {0, 0}, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, - {{C1, C2, State#state.ball, State#state.result}, NS}; + {{C1, C2, State#state.ball}, NS}; not_started -> {not_started, State}; - restarting -> {restarting, State#state{status = {restarting, ID}}}; - {restarting, ID} = St -> {restarting, State#state{status = St}}; - {restarting, _ID2} -> {restarting, State#state{status = not_started}} + restarting -> + {{restarting, State#state.result}, + State#state{status = {restarting, ID}}}; + {restarting, ID} = St -> + {{restarting, State#state.result}, State#state{status = St}}; + {restarting, _ID2} -> + {{restarting, State#state.result}, + State#state{status = not_started}} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, {Reply, State2} = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game, client1} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1 + 1, GoalsC2}}}; {NewBall, end_of_game, client2} -> {GoalsC1, GoalsC2} = State#state.result, {end_of_game, State#state{result = {GoalsC1, GoalsC2 + 1}}}; NewBall -> {ok, State} end, {reply, Reply, State2#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> - X = ?X0 + 2, - Y = ?YF div 2 - ?CY div 2, + X = ?FX0 + 2, + Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> - X = ?XF - 2 - ?CX, - Y = ?YF div 2 - ?CY div 2, + X = ?FX0 + ?FX - 1 - ?CX, + Y = (?FY0 + ?FY) div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. -get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> +get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?FY0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; -get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> +get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) + when Y + ?CY < ?FY0 + ?FY -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {_X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when X1 =:= XB -> {Ball#ball{path = Path}, end_of_game, client2}; run_step({_X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) when XB + ?BX - 1 =:= X2 -> {Ball#ball{path = Path}, end_of_game, client1}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, - case YB >= Y1 andalso YB =< Y1 + ?CY of + case YB >= Y1 andalso YB =< Y1 + ?CY - 1 of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, - case YB >= Y2 andalso YB =< Y2 + ?CY of + case YB >= Y2 andalso YB =< Y2 + ?CY - 1 of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> timer:sleep(?PAUSE_AFTER_GOAL), restart_game() end.
jordi-chacon/pongerl
ea26d3891c5a269edc71a7bc72aecd579f0d4af4
Changed font to Monospace 8
diff --git a/start.sh b/start.sh index 21a6bca..738cfda 100644 --- a/start.sh +++ b/start.sh @@ -1,36 +1,36 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc execute_server() { erl -sname server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl } execute_client() { profile=$(gconftool --get /apps/gnome-terminal/global/default_profile) old_font=$(gconftool --get /apps/gnome-terminal/profiles/${profile}/font) profileAtom="'"${profile}"'" font="\""$old_font"\"" - gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 4" + gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 8" erl -noinput -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval "pongerl_client:start($profileAtom, $font)" +A 200 } if [ $# -eq 0 ]; then execute_server else opt=$(echo $1 | sed 's/=.*//') case $opt in "--server") execute_server ;; "--c1") execute_client "c1" ;; "--c2") execute_client "c2" ;; esac fi
jordi-chacon/pongerl
eb4fa1ced403a4943fcb119d727985a3ffce2024
Added functionality to change the font size of the terminal of the client to have a better quality of the graphics. The font size is restored when the game ends.
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index 11ae35c..2f486e7 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,113 +1,120 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). --export([start/0]). +-export([start/2]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). -start() -> +start(Profile, OldFont) -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), draw_field(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), - spawn_link(fun() -> key_input_loop(ID) end), + spawn_link(fun() -> key_input_loop(ID, Profile, OldFont) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). -key_input_loop(ID) -> +key_input_loop(ID, Profile, OldFont) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), - key_input_loop(ID); + key_input_loop(ID, Profile, OldFont); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), - key_input_loop(ID); + key_input_loop(ID, Profile, OldFont); $q -> + restore_terminal_font(Profile, OldFont), cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> - key_input_loop(ID) + key_input_loop(ID, Profile, OldFont) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); restarting -> timer:sleep(?PAUSE_AFTER_GOAL div 4), draw_field(); {C1, C2, Ball, _Result} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> Path1 = clean_path(ID, C1), Path2 = clean_path(ID, C2), PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?FIELD_PAIR, Pos), cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> Str = generate_spaces(?XF - ?X0), draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). clean_path(ID, #client{} = C) -> clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; clean_path(ID, #ball{} = B) -> clean_path(ID, B#ball.path, []). clean_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_path(ID, T, Acc); clean_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(ID, [{X, Y} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). + +restore_terminal_font(Profile, OldFont) -> + ProfileStr = atom_to_list(Profile), + Cmd = "gconftool --set /apps/gnome-terminal/profiles/" ++ ProfileStr ++ + "/font --type string \"" ++ OldFont ++ "\"", + os:cmd(Cmd). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/start.sh b/start.sh index a05d439..21a6bca 100644 --- a/start.sh +++ b/start.sh @@ -1,31 +1,36 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc execute_server() { erl -sname server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl } execute_client() { - erl -noinput -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval 'pongerl_client:start()' +A 200 + profile=$(gconftool --get /apps/gnome-terminal/global/default_profile) + old_font=$(gconftool --get /apps/gnome-terminal/profiles/${profile}/font) + profileAtom="'"${profile}"'" + font="\""$old_font"\"" + gconftool --set /apps/gnome-terminal/profiles/${profile}/font --type string "Monospace 4" + erl -noinput -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval "pongerl_client:start($profileAtom, $font)" +A 200 } if [ $# -eq 0 ]; then execute_server else opt=$(echo $1 | sed 's/=.*//') case $opt in "--server") execute_server ;; "--c1") execute_client "c1" ;; "--c2") execute_client "c2" ;; esac fi
jordi-chacon/pongerl
3cb7c7ac9bfac19444c8a3ab758dbefbd7c03a48
The engine now keeps track of the result of the game, how many goals each player has scored so far.
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index 71e713e..11ae35c 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,113 +1,113 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/0]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start() -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), draw_field(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), spawn_link(fun() -> key_input_loop(ID) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID); $q -> cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> key_input_loop(ID) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); restarting -> timer:sleep(?PAUSE_AFTER_GOAL div 4), draw_field(); - {C1, C2, Ball} -> + {C1, C2, Ball, _Result} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> Path1 = clean_path(ID, C1), Path2 = clean_path(ID, C2), PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?FIELD_PAIR, Pos), cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> Str = generate_spaces(?XF - ?X0), draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). clean_path(ID, #client{} = C) -> clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; clean_path(ID, #ball{} = B) -> clean_path(ID, B#ball.path, []). clean_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_path(ID, T, Acc); clean_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(ID, [{X, Y} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 6c1aea4..052f485 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,245 +1,255 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). --record(state, {client1 = empty, client2 = empty, +-record(state, {client1 = empty, client2 = empty, result = {0, 0}, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, - {{C1, C2, State#state.ball}, NS}; + {{C1, C2, State#state.ball, State#state.result}, NS}; not_started -> {not_started, State}; restarting -> {restarting, State#state{status = {restarting, ID}}}; {restarting, ID} = St -> {restarting, State#state{status = St}}; {restarting, _ID2} -> {restarting, State#state{status = not_started}} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, - Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of - {NewBall, end_of_game} -> end_of_game; - NewBall -> ok + {Reply, State2} = + case run_steps({X1, Y1}, {X2, Y2}, Ball) of + {NewBall, end_of_game, client1} -> + {GoalsC1, GoalsC2} = State#state.result, + {end_of_game, State#state{result = {GoalsC1 + 1, GoalsC2}}}; + {NewBall, end_of_game, client2} -> + {GoalsC1, GoalsC2} = State#state.result, + {end_of_game, State#state{result = {GoalsC1, GoalsC2 + 1}}}; + NewBall -> + {ok, State} end, - {reply, Reply, State#state{ball = NewBall, status = started}}. + {reply, Reply, State2#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, Y = ?YF div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, Y = ?YF div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game -run_step({X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) - when X1 =:= XB orelse XB + ?BX - 1 =:= X2 -> - {Ball#ball{path = Path}, end_of_game}; +run_step({X1, _Y1}, {_X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) + when X1 =:= XB -> + {Ball#ball{path = Path}, end_of_game, client2}; +run_step({_X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) + when XB + ?BX - 1 =:= X2 -> + {Ball#ball{path = Path}, end_of_game, client1}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> timer:sleep(?PAUSE_AFTER_GOAL), restart_game() end.
jordi-chacon/pongerl
d0bdef78fa910386dbccdc361639756fa3c001f4
Added modules to the pongerl application
diff --git a/src/pongerl.app.src b/src/pongerl.app.src index 418de3c..fe5c8aa 100644 --- a/src/pongerl.app.src +++ b/src/pongerl.app.src @@ -1,19 +1,22 @@ {application, pongerl, [ {description, "pongerl - An x-term-based version of the arcade video game Pong."}, % The Module and Args used to start this application. {mod, { pongerl_app, []} }, % All modules used by the application. {modules, [pongerl_app ,pongerl_sup + ,pongerl_server + ,pongerl_engine + ,pongerl_client ]}, % configuration parameters similar to those in the config file specified on the command line {env, [{ip, "0.0.0.0"} ,{hostname, "localhost"} ,{port, 8282} ]} ]}.
jordi-chacon/pongerl
3e1f4f90b757d7436ef555bc941cd118e84a22ab
Fixed bug that caused a goal in the right client to be shown wierdly
diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 009a880..6c1aea4 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,245 +1,245 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State = #state{client1 = C1, client2 = C2}) -> NC1 = get_initial_position_client(C1#client.id, first), NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), NewState = State#state{client1 = NC1, client2 = NC2, ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case State#state.status of started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, {{C1, C2, State#state.ball}, NS}; not_started -> {not_started, State}; restarting -> {restarting, State#state{status = {restarting, ID}}}; {restarting, ID} = St -> {restarting, State#state{status = St}}; {restarting, _ID2} -> {restarting, State#state{status = not_started}} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game} -> end_of_game; NewBall -> ok end, {reply, Reply, State#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, - Y = ?YF div 2, + Y = ?YF div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, - Y = ?YF div 2, + Y = ?YF div 2 - ?CY div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game -run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) - when X1 =:= BX orelse X2 + ?BX - 1 =:= BX -> +run_step({X1, _Y1}, {X2, _Y2}, #ball{x = XB} = Ball, Path, _Steps) + when X1 =:= XB orelse XB + ?BX - 1 =:= X2 -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> timer:sleep(?PAUSE_AFTER_GOAL), restart_game() end.
jordi-chacon/pongerl
a2d1c0d9398bf0ce50c4b879e581731c783ec874
Added status field to the game engine. It can be not_started, started or restarting. The client redraws the field when it receives a 'restarting' status
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 45bb448..17c09ca 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,36 +1,39 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Dimensions of the field -define(X0, 0). -define(Y0, 0). -define(XF, 40). -define(YF, 20). % Dimensions of the bars of the clients -define(CY, 3). -define(CX, 1). % Dimensions of the ball -define(BX, 2). -define(BY, 1). % Round length -define(ROUND_LENGTH, 100). +% Pause after goal +-define(PAUSE_AFTER_GOAL, 2000). + % Color pairs -define(CLIENT_PAIR, 1). -define(BALL_PAIR, 2). -define(FIELD_PAIR, 3). -record(ball, {x = (?XF - ?X0) div 2, y = (?YF - ?Y0) div 2, speed = 1, degrees = 180, path = [{(?XF - ?X0) div 2, (?YF - ?Y0) div 2}]}). -record(client, {id, x = 0, y = 0, path = []}). diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index e7d8c4f..71e713e 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,110 +1,113 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/0]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start() -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), draw_field(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), spawn_link(fun() -> key_input_loop(ID) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID); $q -> cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> key_input_loop(ID) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of - not_started -> + not_started -> timer:sleep(?ROUND_LENGTH); + restarting -> + timer:sleep(?PAUSE_AFTER_GOAL div 4), + draw_field(); {C1, C2, Ball} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> Path1 = clean_path(ID, C1), Path2 = clean_path(ID, C2), PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?FIELD_PAIR, Pos), cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> Str = generate_spaces(?XF - ?X0), draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). clean_path(ID, #client{} = C) -> clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; clean_path(ID, #ball{} = B) -> clean_path(ID, B#ball.path, []). clean_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_path(ID, T, Acc); clean_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(ID, [{X, Y} | T], Acc) -> clean_path(ID, T, [{X, Y} | Acc]); clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 9330943..009a880 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,239 +1,245 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). --record(state, {client1 = empty, client2 = empty, ball = #ball{}}). +-record(state, {client1 = empty, client2 = empty, + ball = #ball{}, status = not_started}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), - NewState = #state{client1 = C1, client2 = C2, ball = Ball}, + NewState = #state{client1 = C1, client2 = C2, ball = Ball, status = started}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. -do_restart_game(State) -> +do_restart_game(State = #state{client1 = C1, client2 = C2}) -> + NC1 = get_initial_position_client(C1#client.id, first), + NC2 = get_initial_position_client(C2#client.id, second), Ball = get_initial_position_ball(), - NewState = State#state{ball = Ball}, + NewState = State#state{client1 = NC1, client2 = NC2, + ball = Ball, status = restarting}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = - case C1 =/= empty andalso C2 =/= empty of - true -> + case State#state.status of + started -> NC1 = flag_and_clean_path(ID, C1), NC2 = flag_and_clean_path(ID, C2), NB = flag_and_clean_path(ID, State#state.ball), NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, {{C1, C2, State#state.ball}, NS}; - false -> - {not_started, State} + not_started -> {not_started, State}; + restarting -> {restarting, State#state{status = {restarting, ID}}}; + {restarting, ID} = St -> {restarting, State#state{status = St}}; + {restarting, _ID2} -> {restarting, State#state{status = not_started}} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game} -> end_of_game; NewBall -> ok end, - {reply, Reply, State#state{ball = NewBall}}. + {reply, Reply, State#state{ball = NewBall, status = started}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. flag_and_clean_path(ID, #client{} = C) -> NewPath = flag_and_clean_path(ID, C#client.path, []), C#client{path = NewPath}; flag_and_clean_path(ID, #ball{} = B) -> NewPath = flag_and_clean_path(ID, B#ball.path, []), B#ball{path = NewPath}. flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) when X1 =:= BX orelse X2 + ?BX - 1 =:= BX -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); - end_of_game -> restart_game() + end_of_game -> timer:sleep(?PAUSE_AFTER_GOAL), restart_game() end.
jordi-chacon/pongerl
1e3b5b51c55bac62b1d5c497500421d33ce4e1e8
Fixed a bug that happened hardly ever, when the engine was run twice without the client having asked for the status. This resulted in half of the ball not being removed from the field. Fixed by using the same method as with the client bars, coordinates in the path of the ball are removed just when both clients have read it.
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index bc4ec7e..e7d8c4f 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,107 +1,110 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/0]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start() -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), draw_field(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), spawn_link(fun() -> key_input_loop(ID) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID); $q -> cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> key_input_loop(ID) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); {C1, C2, Ball} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> - Path1 = clean_client_path(ID, C1), - Path2 = clean_client_path(ID, C2), + Path1 = clean_path(ID, C1), + Path2 = clean_path(ID, C2), + PathB = clean_path(ID, Ball), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), - draw(lists:reverse(Ball#ball.path), BallStr, ?BY, ?BALL_PAIR, true). + draw(PathB, BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?FIELD_PAIR, Pos), cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> Str = generate_spaces(?XF - ?X0), draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). -clean_client_path(ID, C) -> - clean_client_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]. -clean_client_path(ID, [{_X, _Y, ID} | T], Acc) -> - clean_client_path(ID, T, Acc); -clean_client_path(ID, [{X, Y, _ID2} | T], Acc) -> - clean_client_path(ID, T, [{X, Y} | Acc]); -clean_client_path(ID, [{X, Y} | T], Acc) -> - clean_client_path(ID, T, [{X, Y} | Acc]); -clean_client_path(_ID, [], Acc) -> +clean_path(ID, #client{} = C) -> + clean_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]; +clean_path(ID, #ball{} = B) -> + clean_path(ID, B#ball.path, []). +clean_path(ID, [{_X, _Y, ID} | T], Acc) -> + clean_path(ID, T, Acc); +clean_path(ID, [{X, Y, _ID2} | T], Acc) -> + clean_path(ID, T, [{X, Y} | Acc]); +clean_path(ID, [{X, Y} | T], Acc) -> + clean_path(ID, T, [{X, Y} | Acc]); +clean_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 38b58e1..9330943 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,234 +1,239 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, ball = #ball{}}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State) -> Ball = get_initial_position_ball(), NewState = State#state{ball = Ball}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, - {Reply, NewState} = case C1 =/= empty andalso C2 =/= empty of - true -> - NC1 = flag_and_clean_client_path(ID, C1), - NC2 = flag_and_clean_client_path(ID, C2), - NS = State#state{client1 = NC1, client2 = NC2}, - {{C1, C2, State#state.ball}, NS}; - false -> - {not_started, State} - end, + {Reply, NewState} = + case C1 =/= empty andalso C2 =/= empty of + true -> + NC1 = flag_and_clean_path(ID, C1), + NC2 = flag_and_clean_path(ID, C2), + NB = flag_and_clean_path(ID, State#state.ball), + NS = State#state{client1 = NC1, client2 = NC2, ball = NB}, + {{C1, C2, State#state.ball}, NS}; + false -> + {not_started, State} + end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game} -> end_of_game; NewBall -> ok end, {reply, Reply, State#state{ball = NewBall}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; get_client_new_position(C, _Direction) -> C. -flag_and_clean_client_path(ID, C) -> - NewPath = flag_and_clean_client_path(ID, C#client.path, []), - C#client{path = NewPath}. -flag_and_clean_client_path(_ID, [], Acc) -> +flag_and_clean_path(ID, #client{} = C) -> + NewPath = flag_and_clean_path(ID, C#client.path, []), + C#client{path = NewPath}; +flag_and_clean_path(ID, #ball{} = B) -> + NewPath = flag_and_clean_path(ID, B#ball.path, []), + B#ball{path = NewPath}. +flag_and_clean_path(_ID, [], Acc) -> lists:reverse(Acc); -flag_and_clean_client_path(ID, [{X, Y} | T], Acc) -> - flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); -flag_and_clean_client_path(ID, [{X, Y, ID} | T], Acc) -> - flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); -flag_and_clean_client_path(ID, [{_X, _Y, _ID2} | T], Acc) -> - flag_and_clean_client_path(ID, T, Acc). - -run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed} = Ball) -> - run_step(P1, P2, Ball, [{X, Y}], Speed). +flag_and_clean_path(ID, [{X, Y} | T], Acc) -> + flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); +flag_and_clean_path(ID, [{X, Y, ID} | T], Acc) -> + flag_and_clean_path(ID, T, [{X, Y, ID} | Acc]); +flag_and_clean_path(ID, [{_X, _Y, _ID2} | T], Acc) -> + flag_and_clean_path(ID, T, Acc). + +run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed, path = Path} = Ball) -> + run_step(P1, P2, Ball, [{X, Y} | Path], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) when X1 =:= BX orelse X2 + ?BX - 1 =:= BX -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> restart_game() end.
jordi-chacon/pongerl
154e32b6fca80391f7c4c3d21b4d1192b966ce42
Client bars cannot get outside the field now
diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 2affbad..38b58e1 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,233 +1,234 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {client1 = empty, client2 = empty, ball = #ball{}}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), NewState = #state{client1 = C1, client2 = C2, ball = Ball}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State) -> Ball = get_initial_position_ball(), NewState = State#state{ball = Ball}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> C1 = State#state.client1, C2 = State#state.client2, {Reply, NewState} = case C1 =/= empty andalso C2 =/= empty of true -> NC1 = flag_and_clean_client_path(ID, C1), NC2 = flag_and_clean_client_path(ID, C2), NS = State#state{client1 = NC1, client2 = NC2}, {{C1, C2, State#state.ball}, NS}; false -> {not_started, State} end, {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State = #state{client1 = C1, client2 = C2}) -> ID1 = C1#client.id, ID2 = C2#client.id, NewState = case ClientID of ID1 -> NC = get_client_new_position(C1, Direction), State#state{client1 = NC}; ID2 -> NC = get_client_new_position(C2, Direction), State#state{client2 = NC} end, {reply, ok, NewState}. do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game} -> end_of_game; NewBall -> ok end, {reply, Reply, State#state{ball = NewBall}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. -get_client_new_position(#client{y = Y, x = X} = C, ?UP) -> +get_client_new_position(#client{y = Y, x = X} = C, ?UP) when Y > ?Y0 -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; -get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) -> - C#client{y = Y + 1, path = [{X, Y} | C#client.path]}. +get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) when Y + ?CY < ?YF -> + C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; +get_client_new_position(C, _Direction) -> C. flag_and_clean_client_path(ID, C) -> NewPath = flag_and_clean_client_path(ID, C#client.path, []), C#client{path = NewPath}. flag_and_clean_client_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_client_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_client_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_client_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_client_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed} = Ball) -> run_step(P1, P2, Ball, [{X, Y}], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) when X1 =:= BX orelse X2 + ?BX - 1 =:= BX -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> restart_game() end.
jordi-chacon/pongerl
78e0f13932b1c5375dd1dfd8605047ba11b9a92f
Fixed bug that avoided the bar to be deleted from its previous position
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index 18a24a7..bc4ec7e 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,107 +1,107 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/0]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start() -> application:start(cecho), cecho:cbreak(), cecho:noecho(), cecho:curs_set(?ceCURS_INVISIBLE), cecho:start_color(), cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), draw_field(), ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), spawn_link(fun() -> key_input_loop(ID) end), spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID) -> C = cecho:getch(), case C of $a -> ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID); $z -> ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID); $q -> cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), erlang:halt(); _ -> key_input_loop(ID) end. draw_game_loop(ID, ClientStr, BallStr) -> case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); {C1, C2, Ball} -> draw_game(ID, C1, C2, Ball, ClientStr, BallStr), timer:sleep(?ROUND_LENGTH) end, draw_game_loop(ID, ClientStr, BallStr). draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> - Path1 = clean_client_path(ID, C1#client.path), - Path2 = clean_client_path(ID, C2#client.path), + Path1 = clean_client_path(ID, C1), + Path2 = clean_client_path(ID, C2), draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), draw(lists:reverse(Ball#ball.path), BallStr, ?BY, ?BALL_PAIR, true). draw([], _Str, _Height, _Pair, _RemPrev) -> ok; draw(Path, Str, Height, Pair, RemPrev) -> draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> ok; draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, ?FIELD_PAIR, Pos), cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), cecho:move(Y, X), cecho:addstr(Str), cecho:refresh(), cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, Pair, NewPrevious, RemPrev). get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> draw(Previous, Str, Height, Pair, false), {false, Pos}. draw_field() -> Str = generate_spaces(?XF - ?X0), draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). -clean_client_path(ID, Path) -> - clean_client_path(ID, Path, []). +clean_client_path(ID, C) -> + clean_client_path(ID, C#client.path, []) ++ [{C#client.x, C#client.y}]. clean_client_path(ID, [{_X, _Y, ID} | T], Acc) -> clean_client_path(ID, T, Acc); clean_client_path(ID, [{X, Y, _ID2} | T], Acc) -> clean_client_path(ID, T, [{X, Y} | Acc]); clean_client_path(ID, [{X, Y} | T], Acc) -> clean_client_path(ID, T, [{X, Y} | Acc]); clean_client_path(_ID, [], Acc) -> Acc. generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). rpc(Function, Args) -> rpc:call(server@ardilla, pongerl_server, Function, Args).
jordi-chacon/pongerl
a55f1461514de0b085623b822cf706446fbde088
Flag -noinput needed for correct behaviour of cecho library
diff --git a/start.sh b/start.sh index cf7f124..a05d439 100644 --- a/start.sh +++ b/start.sh @@ -1,31 +1,31 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc execute_server() { erl -sname server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl } execute_client() { - erl -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval 'pongerl_client:start()' +A 200 + erl -noinput -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval 'pongerl_client:start()' +A 200 } if [ $# -eq 0 ]; then execute_server else opt=$(echo $1 | sed 's/=.*//') case $opt in "--server") execute_server ;; "--c1") execute_client "c1" ;; "--c2") execute_client "c2" ;; esac fi
jordi-chacon/pongerl
8e0619ba52fe602a073ac5b1e4338f93e0e3fd29
Changed structure of state. Now there is a field for client1 and another for client2. Fixed a bug when the ball bounced on the left bar.
diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 88ede48..2affbad 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,225 +1,233 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). --record(state, {clients = [], ball = #ball{}}). +-record(state, {client1 = empty, client2 = empty, ball = #ball{}}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state(ID) -> gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call({get_state, ID}, _From, State) -> do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(ID1, first), C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), - NewState = #state{clients = [C1, C2], ball = Ball}, + NewState = #state{client1 = C1, client2 = C2, ball = Ball}, spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State) -> Ball = get_initial_position_ball(), NewState = State#state{ball = Ball}, spawn(fun() -> run_engine_caller() end), {noreply, NewState}. do_get_state(ID, State) -> - {Reply, NewState} = case State#state.clients of - [C1, C2] -> + C1 = State#state.client1, + C2 = State#state.client2, + {Reply, NewState} = case C1 =/= empty andalso C2 =/= empty of + true -> NC1 = flag_and_clean_client_path(ID, C1), NC2 = flag_and_clean_client_path(ID, C2), - NS = State#state{clients = [NC1, NC2]}, + NS = State#state{client1 = NC1, client2 = NC2}, {{C1, C2, State#state.ball}, NS}; - _ -> + false -> {not_started, State} end, {reply, Reply, NewState}. -do_change_client_position(ClientID, Direction, State) -> - C = get_client_new_position(ClientID, State#state.clients, Direction), - L1 = lists:keydelete(ClientID, 2, State#state.clients), - NewState = State#state{clients = [C | L1]}, +do_change_client_position(ClientID, Direction, + State = #state{client1 = C1, client2 = C2}) -> + ID1 = C1#client.id, + ID2 = C2#client.id, + NewState = case ClientID of + ID1 -> + NC = get_client_new_position(C1, Direction), + State#state{client1 = NC}; + ID2 -> + NC = get_client_new_position(C2, Direction), + State#state{client2 = NC} + end, {reply, ok, NewState}. -do_run_engine(#state{clients = [C1, C2], ball = Ball} =State) -> +do_run_engine(#state{client1 = C1, client2 = C2, ball = Ball} = State) -> #client{x = X1, y = Y1} = C1, #client{x = X2, y = Y2} = C2, Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of {NewBall, end_of_game} -> end_of_game; NewBall -> ok end, {reply, Reply, State#state{ball = NewBall}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(ID, first) -> X = ?X0 + 2, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}; get_initial_position_client(ID, second) -> X = ?XF - 2 - ?CX, Y = ?YF div 2, #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. -get_client_new_position(ID, [#client{id = ID, y = Y, x = X} = C | _T], ?UP) -> +get_client_new_position(#client{y = Y, x = X} = C, ?UP) -> C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; -get_client_new_position(ID, [#client{id = ID, y = Y, x = X} = C | _T], ?DOWN) -> - C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; -get_client_new_position(ID, [_C | T], Dir) -> - get_client_new_position(ID, T, Dir). +get_client_new_position(#client{y = Y, x = X} = C, ?DOWN) -> + C#client{y = Y + 1, path = [{X, Y} | C#client.path]}. flag_and_clean_client_path(ID, C) -> NewPath = flag_and_clean_client_path(ID, C#client.path, []), C#client{path = NewPath}. flag_and_clean_client_path(_ID, [], Acc) -> lists:reverse(Acc); flag_and_clean_client_path(ID, [{X, Y} | T], Acc) -> flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_client_path(ID, [{X, Y, ID} | T], Acc) -> flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); flag_and_clean_client_path(ID, [{_X, _Y, _ID2} | T], Acc) -> flag_and_clean_client_path(ID, T, Acc). run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed} = Ball) -> run_step(P1, P2, Ball, [{X, Y}], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) - when X1 =:= BX orelse X2 =:= BX -> + when X1 =:= BX orelse X2 + ?BX - 1 =:= BX -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 1 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of - true when Degrees < 90 andalso Degrees > 270 -> + true when Degrees < 90 orelse Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; true -> % client 2 has changed the direction of the ball {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> timer:sleep(?ROUND_LENGTH), case run_engine() of ok -> run_engine_caller(); end_of_game -> restart_game() end.
jordi-chacon/pongerl
0131f3b63d902e7a8fa0f15b04ba38e06db9be75
Improved start script to quickly and easily start server, client1 and client2 from it
diff --git a/start.sh b/start.sh index 848552b..cf7f124 100644 --- a/start.sh +++ b/start.sh @@ -1,10 +1,31 @@ #!/usr/bin/env sh cd `dirname $0` . ./dep.inc -echo "Starting Pongerl..." -erl \ - -sname ${NAME} \ - -pa ./ebin ${CECHO_EBIN} \ - -eval "application:start(pongerl)" \ No newline at end of file +execute_server() { + erl -sname server -pa ./ebin ${CECHO_EBIN} -eval "application:start(pongerl)" -setcookie pongerl +} + +execute_client() { + erl -pa ./ebin ${CECHO_EBIN} -sname $1 -setcookie pongerl -eval 'pongerl_client:start()' +A 200 +} + + +if [ $# -eq 0 ]; then + execute_server +else + opt=$(echo $1 | sed 's/=.*//') + case $opt in + "--server") + execute_server + ;; + "--c1") + execute_client "c1" + ;; + "--c2") + execute_client "c2" + ;; + esac +fi +
jordi-chacon/pongerl
27c70158e4eff4d839d0c72c8319aef1ba9218f9
Refactoring and bug fixing
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 5369c69..45bb448 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,26 +1,36 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Dimensions of the field -define(X0, 0). -define(Y0, 0). --define(XF, 80). +-define(XF, 40). -define(YF, 20). % Dimensions of the bars of the clients -define(CY, 3). -define(CX, 1). % Dimensions of the ball -define(BX, 2). -define(BY, 1). % Round length -define(ROUND_LENGTH, 100). +% Color pairs +-define(CLIENT_PAIR, 1). +-define(BALL_PAIR, 2). +-define(FIELD_PAIR, 3). + -record(ball, {x = (?XF - ?X0) div 2, y = (?YF - ?Y0) div 2, speed = 1, degrees = 180, - path = []}). + path = [{(?XF - ?X0) div 2, (?YF - ?Y0) div 2}]}). + +-record(client, {id, + x = 0, + y = 0, + path = []}). diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl index ba6f8e5..18a24a7 100644 --- a/src/pongerl_client.erl +++ b/src/pongerl_client.erl @@ -1,72 +1,107 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_client). -export([start/0]). -include_lib("../include/pongerl.hrl"). -include_lib("../dep/cecho/include/cecho.hrl"). start() -> application:start(cecho), - cecho:init_pair(1, ?ceCOLOR_BLACK, ?ceCOLOR_RED), - cecho:init_pair(2, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), - ID = pongerl_server:connect_client(), + cecho:cbreak(), + cecho:noecho(), + cecho:curs_set(?ceCURS_INVISIBLE), + cecho:start_color(), + cecho:init_pair(?CLIENT_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_RED), + cecho:init_pair(?BALL_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), + cecho:init_pair(?FIELD_PAIR, ?ceCOLOR_BLACK, ?ceCOLOR_BLACK), + draw_field(), + ID = rpc(connect_client, []), ClientStr = generate_spaces(?CX), BallStr = generate_spaces(?BX), - spawn_link(key_input_loop(ID)), - spawn_link(draw_game_loop(ClientStr, BallStr)). + spawn_link(fun() -> key_input_loop(ID) end), + spawn_link(fun() -> draw_game_loop(ID, ClientStr, BallStr) end). key_input_loop(ID) -> C = cecho:getch(), case C of $a -> - ok = pongerl_server:change_client_position(ID, ?UP), + ok = rpc(change_client_position, [ID, ?UP]), key_input_loop(ID); $z -> - ok = pongerl_server:change_client_position(ID, ?DOWN), + ok = rpc(change_client_position, [ID, ?DOWN]), key_input_loop(ID); $q -> + cecho:curs_set(?ceCURS_NORMAL), application:stop(cecho), - erlang:halt() + erlang:halt(); + _ -> + key_input_loop(ID) end. -draw_game_loop(ClientStr, BallStr) -> - case pongerl_server:get_state() of +draw_game_loop(ID, ClientStr, BallStr) -> + case rpc(get_state, [ID]) of not_started -> timer:sleep(?ROUND_LENGTH); {C1, C2, Ball} -> - draw_game(C1, C2, Ball, ClientStr, BallStr) + draw_game(ID, C1, C2, Ball, ClientStr, BallStr), + timer:sleep(?ROUND_LENGTH) end, - draw_game_loop(ClientStr, BallStr). + draw_game_loop(ID, ClientStr, BallStr). -draw_game(C1, C2, Ball, ClientStr, BallStr) -> - draw_client(C1, ClientStr, ?CY), - draw_client(C2, ClientStr, ?CY), - draw_ball_path(lists:reverse(Ball#ball.path), BallStr, ?BY). +draw_game(ID, C1, C2, Ball, ClientStr, BallStr) -> + Path1 = clean_client_path(ID, C1#client.path), + Path2 = clean_client_path(ID, C2#client.path), + draw(Path1, ClientStr, ?CY, ?CLIENT_PAIR, true), + draw(Path2, ClientStr, ?CY, ?CLIENT_PAIR, true), + draw(lists:reverse(Ball#ball.path), BallStr, ?BY, ?BALL_PAIR, true). -draw_client({_X, _Y}, _Str, 0) -> ok; -draw_client({X, Y}, Str, Height) -> - cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(1)), - cecho:move(X, Y), +draw([], _Str, _Height, _Pair, _RemPrev) -> + ok; +draw(Path, Str, Height, Pair, RemPrev) -> + draw(Path, Str, Height, Height, Pair, {false, hd(Path)}, RemPrev). +draw([], _Str, _HeightLeft, _Height, _Pair, _Previous, _RemPrev) -> + ok; +draw([_|T], Str, 0, Height, Pair, {_, P}, RemPrev) -> + draw(T, Str, Height, Height, Pair, {RemPrev, [P]}, RemPrev); +draw([{X, Y} = Pos|T], Str, HeightLeft, Height, Pair, Previous, RemPrev) -> + NewPrevious = get_and_maybe_draw_previous(Previous, Str, Height, + ?FIELD_PAIR, Pos), + cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), + cecho:move(Y, X), cecho:addstr(Str), - cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(1)), - draw_client({X, Y + 1}, Str, Height - 1). + cecho:refresh(), + cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(Pair)), + draw([{X, Y + 1} | T], Str, HeightLeft - 1, Height, + Pair, NewPrevious, RemPrev). + +get_and_maybe_draw_previous({false, _Prev} = P, _Str, _Height, _Pair, _Pos) -> P; +get_and_maybe_draw_previous({true, Previous}, Str, Height, Pair, Pos) -> + draw(Previous, Str, Height, Pair, false), + {false, Pos}. + +draw_field() -> + Str = generate_spaces(?XF - ?X0), + draw([{?X0, ?Y0}], Str, ?YF, ?FIELD_PAIR, false). + +clean_client_path(ID, Path) -> + clean_client_path(ID, Path, []). +clean_client_path(ID, [{_X, _Y, ID} | T], Acc) -> + clean_client_path(ID, T, Acc); +clean_client_path(ID, [{X, Y, _ID2} | T], Acc) -> + clean_client_path(ID, T, [{X, Y} | Acc]); +clean_client_path(ID, [{X, Y} | T], Acc) -> + clean_client_path(ID, T, [{X, Y} | Acc]); +clean_client_path(_ID, [], Acc) -> + Acc. -draw_ball_path([], _Str, 0) -> ok; -draw_ball_path([_|T], Str, 0) -> draw_ball_path(T, Str, ?BY); -draw_ball_path([{X, Y}|_] = Path, Str, Height) -> - cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(2)), - cecho:move(X, Y), - cecho:addstr(Str), - cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(2)), - draw_client(Path, Str, Height - 1). - generate_spaces(N) -> generate_spaces(N, ""). generate_spaces(0, Spaces) -> Spaces; generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). - +rpc(Function, Args) -> + rpc:call(server@ardilla, pongerl_server, Function, Args). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 566cef5..88ede48 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,193 +1,225 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, - get_state/0, + get_state/1, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {clients = [], ball = #ball{}}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). -get_state() -> - gen_server:call(?MODULE, get_state). +get_state(ID) -> + gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); -handle_call(get_state, _From, State) -> - do_get_state(State); +handle_call({get_state, ID}, _From, State) -> + do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> - C1 = get_initial_position_client(first), - C2 = get_initial_position_client(second), + C1 = get_initial_position_client(ID1, first), + C2 = get_initial_position_client(ID2, second), Ball = get_initial_position_ball(), - NewState = #state{clients = [{ID1, C1}, {ID2, C2}], ball = Ball}, - register(run_engine_caller, run_engine_caller()), + NewState = #state{clients = [C1, C2], ball = Ball}, + spawn(fun() -> run_engine_caller() end), {reply, ok, NewState}. do_restart_game(State) -> Ball = get_initial_position_ball(), NewState = State#state{ball = Ball}, - register(run_engine_caller, run_engine_caller()), + spawn(fun() -> run_engine_caller() end), {noreply, NewState}. -do_get_state(State) -> - case State#state.clients of - [{_, P1}, {_, P2}] -> Reply = {P1, P2, get_ball_position(State#state.ball)}; - _ -> Reply = not_started - end, - {reply, Reply, State}. +do_get_state(ID, State) -> + {Reply, NewState} = case State#state.clients of + [C1, C2] -> + NC1 = flag_and_clean_client_path(ID, C1), + NC2 = flag_and_clean_client_path(ID, C2), + NS = State#state{clients = [NC1, NC2]}, + {{C1, C2, State#state.ball}, NS}; + _ -> + {not_started, State} + end, + {reply, Reply, NewState}. do_change_client_position(ClientID, Direction, State) -> - CPos = get_client_new_position(ClientID, State#state.clients, Direction), - PL1 = proplists:delete(ClientID, State#state.clients), - NewState = State#state{clients = [{ClientID, CPos} | PL1]}, + C = get_client_new_position(ClientID, State#state.clients, Direction), + L1 = lists:keydelete(ClientID, 2, State#state.clients), + NewState = State#state{clients = [C | L1]}, {reply, ok, NewState}. -do_run_engine(#state{clients = [{_ID1, P1}, {_ID2, P2}], ball = Ball} =State) -> - case run_steps(P1, P2, Ball) of - {NewBall, end_of_game} -> run_engine_caller ! die; - NewBall -> ok +do_run_engine(#state{clients = [C1, C2], ball = Ball} =State) -> + #client{x = X1, y = Y1} = C1, + #client{x = X2, y = Y2} = C2, + Reply = case run_steps({X1, Y1}, {X2, Y2}, Ball) of + {NewBall, end_of_game} -> end_of_game; + NewBall -> ok end, - {reply, ok, State#state{ball = NewBall}}. + {reply, Reply, State#state{ball = NewBall}}. %%%=================================================================== %%% More internal functions %%%=================================================================== -get_initial_position_client(first) -> {?X0 + 2, ?Y0 div 2}; -get_initial_position_client(second) -> {?XF - 2, ?Y0 div 2}. +get_initial_position_client(ID, first) -> + X = ?X0 + 2, + Y = ?YF div 2, + #client{id = ID, x = X, y = Y, path = [{X, Y}]}; +get_initial_position_client(ID, second) -> + X = ?XF - 2 - ?CX, + Y = ?YF div 2, + #client{id = ID, x = X, y = Y, path = [{X, Y}]}. get_initial_position_ball() -> #ball{}. -get_ball_position(#ball{x = X, y = Y}) -> {X, Y}. - -get_client_new_position(ID, [{ID, {X, Y}} | _T], ?UP) -> {X, Y - 1}; -get_client_new_position(ID, [{ID, {X, Y}} | _T], ?DOWN) -> {X, Y + 1}; -get_client_new_position(ID, [{_ID, _Pos} | T], Dir) -> +get_client_new_position(ID, [#client{id = ID, y = Y, x = X} = C | _T], ?UP) -> + C#client{y = Y - 1, path = [{X, Y} | C#client.path]}; +get_client_new_position(ID, [#client{id = ID, y = Y, x = X} = C | _T], ?DOWN) -> + C#client{y = Y + 1, path = [{X, Y} | C#client.path]}; +get_client_new_position(ID, [_C | T], Dir) -> get_client_new_position(ID, T, Dir). -run_steps(P1, P2, Ball) -> - run_step(P1, P2, Ball, [], Ball#ball.speed). +flag_and_clean_client_path(ID, C) -> + NewPath = flag_and_clean_client_path(ID, C#client.path, []), + C#client{path = NewPath}. +flag_and_clean_client_path(_ID, [], Acc) -> + lists:reverse(Acc); +flag_and_clean_client_path(ID, [{X, Y} | T], Acc) -> + flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); +flag_and_clean_client_path(ID, [{X, Y, ID} | T], Acc) -> + flag_and_clean_client_path(ID, T, [{X, Y, ID} | Acc]); +flag_and_clean_client_path(ID, [{_X, _Y, _ID2} | T], Acc) -> + flag_and_clean_client_path(ID, T, Acc). + +run_steps(P1, P2, #ball{x = X, y = Y, speed = Speed} = Ball) -> + run_step(P1, P2, Ball, [{X, Y}], Speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) when X1 =:= BX orelse X2 =:= BX -> {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) - when XB =:= X1 + 1-> + when XB =:= X1 + 1 -> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of - true -> + true when Degrees > 90 andalso Degrees < 270 -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; + true -> + % client 1 has changed the direction of the ball + {NX, NY} = get_next_ball_position(XB, YB, Degrees), + NewPath = [{NX, NY} | Path], + NewBall = Ball#ball{x = NX, y = NY}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) - when XB =:= X2 - 1 -> + when XB + ?BX =:= X2 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of - true -> + true when Degrees < 90 andalso Degrees > 270 -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; + true -> + % client 2 has changed the direction of the ball + {NX, NY} = get_next_ball_position(XB, YB, Degrees), + NewPath = [{NX, NY} | Path], + NewBall = Ball#ball{x = NX, y = NY}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> - receive - die -> - timer:sleep(2000), - restart_game() - after ?ROUND_LENGTH -> - ok = run_engine(), - run_engine_caller() + timer:sleep(?ROUND_LENGTH), + case run_engine() of + ok -> run_engine_caller(); + end_of_game -> restart_game() end. diff --git a/src/pongerl_server.erl b/src/pongerl_server.erl index 75b84a7..a66153d 100644 --- a/src/pongerl_server.erl +++ b/src/pongerl_server.erl @@ -1,81 +1,82 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_server). -behaviour(gen_server). %% API -export([connect_client/0, change_client_position/2, - get_state/0]). + get_state/1]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {clients = [], last_id = 0}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. connect_client() -> gen_server:call(?MODULE, connect_client). -get_state() -> - gen_server:call(?MODULE, get_state). +get_state(ID) -> + gen_server:call(?MODULE, {get_state, ID}). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). handle_call(connect_client, _From, State) -> do_connect_client(State); -handle_call(get_state, _From, State) -> - do_get_state(State); +handle_call({get_state, ID}, _From, State) -> + do_get_state(ID, State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_connect_client(State) -> ID = State#state.last_id, Clients = [ID | State#state.clients], case Clients of [ID1, ID2] -> ok = pongerl_engine:start_game(ID1, ID2); _ -> ok end, NewState = State#state{last_id = ID + 1, clients = Clients}, {reply, ID, NewState}. -do_get_state(State) -> - Reply = pongerl_engine:get_state(), +do_get_state(ID, State) -> + Reply = pongerl_engine:get_state(ID), + io:format("~p~n", [Reply]), {reply, Reply, State}. do_change_client_position(ClientID, Direction, State) -> - ok = game_engine:change_client_position(ClientID, Direction), + ok = pongerl_engine:change_client_position(ClientID, Direction), {reply, ok, State}.
jordi-chacon/pongerl
3663deb3f326126755063666ea69e242612806d5
Fixed bug
diff --git a/src/pongerl_app.erl b/src/pongerl_app.erl index e7b0bd5..3548a9b 100644 --- a/src/pongerl_app.erl +++ b/src/pongerl_app.erl @@ -1,17 +1,17 @@ %% @author Jordi Chacon <jordi.chacon@gmail.com> %% @copyright 2010 Jordi Chacon %% @doc Callbacks for the pongerl application. -module(pongerl_app). -behaviour(application). -export([start/2, stop/1]). -include("pongerl.hrl"). start(_, _) -> - polish_sup:start_link(). + pongerl_sup:start_link(). stop(_) -> ok.
jordi-chacon/pongerl
0c21b6831f957fe73db468210a877cf6ac394f9d
Ignore ebin and dep
diff --git a/.gitignore b/.gitignore index e4e5f6c..81d2445 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*~ \ No newline at end of file +*~ +ebin/ +dep*
jordi-chacon/pongerl
d0fe4e218683e30ad3d54809ad9cb82a6e71522a
Some refactoring done in the engine
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 7348597..5369c69 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,22 +1,26 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Dimensions of the field -define(X0, 0). -define(Y0, 0). -define(XF, 80). -define(YF, 20). % Dimensions of the bars of the clients -define(CY, 3). -define(CX, 1). % Dimensions of the ball -define(BX, 2). -define(BY, 1). +% Round length +-define(ROUND_LENGTH, 100). + -record(ball, {x = (?XF - ?X0) div 2, y = (?YF - ?Y0) div 2, speed = 1, - degrees = 180}). + degrees = 180, + path = []}). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 37fbf94..566cef5 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,191 +1,193 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, restart_game/0, get_state/0, change_client_position/2, run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). --record(state, {clients = [], ball = #ball{}, path = []}). +-record(state, {clients = [], ball = #ball{}}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). restart_game() -> gen_server:cast(?MODULE, restart_game). get_state() -> gen_server:call(?MODULE, get_state). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). run_engine() -> gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call(get_state, _From, State) -> do_get_state(State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(run_engine, _From, State) -> do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(restart_game, State) -> do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(first), C2 = get_initial_position_client(second), Ball = get_initial_position_ball(), NewState = #state{clients = [{ID1, C1}, {ID2, C2}], ball = Ball}, register(run_engine_caller, run_engine_caller()), {reply, ok, NewState}. do_restart_game(State) -> Ball = get_initial_position_ball(), NewState = State#state{ball = Ball}, register(run_engine_caller, run_engine_caller()), {noreply, NewState}. do_get_state(State) -> - CPos = State#state.clients, - BallPos = get_ball_position(State#state.ball), - {reply, {CPos, BallPos}, State}. + case State#state.clients of + [{_, P1}, {_, P2}] -> Reply = {P1, P2, get_ball_position(State#state.ball)}; + _ -> Reply = not_started + end, + {reply, Reply, State}. do_change_client_position(ClientID, Direction, State) -> CPos = get_client_new_position(ClientID, State#state.clients, Direction), PL1 = proplists:delete(ClientID, State#state.clients), NewState = State#state{clients = [{ClientID, CPos} | PL1]}, {reply, ok, NewState}. do_run_engine(#state{clients = [{_ID1, P1}, {_ID2, P2}], ball = Ball} =State) -> case run_steps(P1, P2, Ball) of - {Path, NewBall} -> ok; - {Path, NewBall, end_of_game} -> run_engine_caller ! die + {NewBall, end_of_game} -> run_engine_caller ! die; + NewBall -> ok end, - {reply, ok, State#state{ball = NewBall, path = Path}}. + {reply, ok, State#state{ball = NewBall}}. %%%=================================================================== %%% More internal functions %%%=================================================================== get_initial_position_client(first) -> {?X0 + 2, ?Y0 div 2}; get_initial_position_client(second) -> {?XF - 2, ?Y0 div 2}. get_initial_position_ball() -> #ball{}. get_ball_position(#ball{x = X, y = Y}) -> {X, Y}. get_client_new_position(ID, [{ID, {X, Y}} | _T], ?UP) -> {X, Y - 1}; get_client_new_position(ID, [{ID, {X, Y}} | _T], ?DOWN) -> {X, Y + 1}; get_client_new_position(ID, [{_ID, _Pos} | T], Dir) -> get_client_new_position(ID, T, Dir). run_steps(P1, P2, Ball) -> run_step(P1, P2, Ball, [], Ball#ball.speed). % steps done run_step(_P1, _P2, Ball, Path, 0) -> - {Path, Ball}; + Ball#ball{path = Path}; % end of game run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) when X1 =:= BX orelse X2 =:= BX -> - {Path, Ball, end_of_game}; + {Ball#ball{path = Path}, end_of_game}; run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X1 + 1-> Degrees = Ball#ball.degrees, case YB >= Y1 andalso YB =< Y1 + ?CY of true -> % client 1 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; false -> % client 1 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) when XB =:= X2 - 1 -> Degrees = Ball#ball.degrees, case YB >= Y2 andalso YB =< Y2 + ?CY of true -> % client 2 touches the ball NewDegrees = get_new_degree(Degrees, opposite), NewPath = [{XB, YB} | Path], NewBall = Ball#ball{degrees = NewDegrees}; false -> % client 2 receives a goal {NX, NY} = get_next_ball_position(XB, YB, Degrees), NewPath = [{NX, NY} | Path], NewBall = Ball#ball{x = NX, y = NY} end, run_step(P1, P2, NewBall, NewPath, Steps - 1); run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> Degrees = Ball#ball.degrees, {NX, NY} = get_next_ball_position(X, Y, Degrees), NewPath = [{NX, NY} | Path], run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). get_new_degree(180, opposite) -> 0; get_new_degree(0, opposite) -> 180. get_next_ball_position(X, Y, 180) -> {X - 1, Y}; get_next_ball_position(X, Y, 0) -> {X + 1, Y}. % loop to run the game engine every xx ms run_engine_caller() -> receive die -> timer:sleep(2000), restart_game() - after 100 -> + after ?ROUND_LENGTH -> ok = run_engine(), run_engine_caller() end.
jordi-chacon/pongerl
6d0ba4a0a7fda4af779d4d7ead13938d63e291c6
First version of the client implemented
diff --git a/src/pongerl_client.erl b/src/pongerl_client.erl new file mode 100644 index 0000000..ba6f8e5 --- /dev/null +++ b/src/pongerl_client.erl @@ -0,0 +1,72 @@ +%%% @author Jordi Chacon <jordi.chacon@gmail.com> +%%% @copyright (C) 2010, Jordi Chacon + +-module(pongerl_client). + +-export([start/0]). + +-include_lib("../include/pongerl.hrl"). +-include_lib("../dep/cecho/include/cecho.hrl"). + +start() -> + application:start(cecho), + cecho:init_pair(1, ?ceCOLOR_BLACK, ?ceCOLOR_RED), + cecho:init_pair(2, ?ceCOLOR_BLACK, ?ceCOLOR_BLUE), + ID = pongerl_server:connect_client(), + ClientStr = generate_spaces(?CX), + BallStr = generate_spaces(?BX), + spawn_link(key_input_loop(ID)), + spawn_link(draw_game_loop(ClientStr, BallStr)). + +key_input_loop(ID) -> + C = cecho:getch(), + case C of + $a -> + ok = pongerl_server:change_client_position(ID, ?UP), + key_input_loop(ID); + $z -> + ok = pongerl_server:change_client_position(ID, ?DOWN), + key_input_loop(ID); + $q -> + application:stop(cecho), + erlang:halt() + end. + +draw_game_loop(ClientStr, BallStr) -> + case pongerl_server:get_state() of + not_started -> + timer:sleep(?ROUND_LENGTH); + {C1, C2, Ball} -> + draw_game(C1, C2, Ball, ClientStr, BallStr) + end, + draw_game_loop(ClientStr, BallStr). + +draw_game(C1, C2, Ball, ClientStr, BallStr) -> + draw_client(C1, ClientStr, ?CY), + draw_client(C2, ClientStr, ?CY), + draw_ball_path(lists:reverse(Ball#ball.path), BallStr, ?BY). + +draw_client({_X, _Y}, _Str, 0) -> ok; +draw_client({X, Y}, Str, Height) -> + cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(1)), + cecho:move(X, Y), + cecho:addstr(Str), + cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(1)), + draw_client({X, Y + 1}, Str, Height - 1). + +draw_ball_path([], _Str, 0) -> ok; +draw_ball_path([_|T], Str, 0) -> draw_ball_path(T, Str, ?BY); +draw_ball_path([{X, Y}|_] = Path, Str, Height) -> + cecho:attron(?ceA_BOLD bor ?ceCOLOR_PAIR(2)), + cecho:move(X, Y), + cecho:addstr(Str), + cecho:attroff(?ceA_BOLD bor ?ceCOLOR_PAIR(2)), + draw_client(Path, Str, Height - 1). + + +generate_spaces(N) -> + generate_spaces(N, ""). +generate_spaces(0, Spaces) -> Spaces; +generate_spaces(N, Spaces) -> generate_spaces(N - 1, " " ++ Spaces). + +
jordi-chacon/pongerl
3779ce02857952c7dff90c10a490e770f4d354a3
Fixed a couple of syntax errors. Compilation couldn't be done before since pongerl_engine module was yet not implemented.
diff --git a/src/pongerl_server.erl b/src/pongerl_server.erl index 7118cab..75b84a7 100644 --- a/src/pongerl_server.erl +++ b/src/pongerl_server.erl @@ -1,81 +1,81 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_server). -behaviour(gen_server). %% API -export([connect_client/0, change_client_position/2, get_state/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). -record(state, {clients = [], last_id = 0}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. connect_client() -> gen_server:call(?MODULE, connect_client). get_state() -> gen_server:call(?MODULE, get_state). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). handle_call(connect_client, _From, State) -> do_connect_client(State); handle_call(get_state, _From, State) -> do_get_state(State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_connect_client(State) -> ID = State#state.last_id, - Clients = [Id|State#state.clients], + Clients = [ID | State#state.clients], case Clients of - [ID1, ID2] -> ok = pongerl_engine:start_game(ID1, ID2), + [ID1, ID2] -> ok = pongerl_engine:start_game(ID1, ID2); _ -> ok end, - NewState = State#state{last_id = ID+ 1, clients = Clients}, - {reply, Id, NewState}. + NewState = State#state{last_id = ID + 1, clients = Clients}, + {reply, ID, NewState}. do_get_state(State) -> Reply = pongerl_engine:get_state(), {reply, Reply, State}. do_change_client_position(ClientID, Direction, State) -> ok = game_engine:change_client_position(ClientID, Direction), {reply, ok, State}. diff --git a/src/pongerl_sup.erl b/src/pongerl_sup.erl index 70c15ce..c20064a 100644 --- a/src/pongerl_sup.erl +++ b/src/pongerl_sup.erl @@ -1,53 +1,53 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_sup). -behaviour(supervisor). %% External exports -export([start_link/0, upgrade/0]). %% supervisor callbacks -export([init/1]). %% @spec start_link() -> ServerRet %% @doc API for starting the supervisor. start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). server(Name, Type) -> server(Name, Type, 2000). server(Name, Type, Shutdown) -> {Name, {Name, start_link, []}, permanent, Shutdown, Type, [Name]}. worker(Name) -> server(Name, worker). %% @spec upgrade() -> ok %% @doc Add processes if necessary. upgrade() -> {ok, {_, Specs}} = init([]), Old = sets:from_list( [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]), New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]), Kill = sets:subtract(Old, New), sets:fold(fun (Id, ok) -> supervisor:terminate_child(?MODULE, Id), supervisor:delete_child(?MODULE, Id), ok end, ok, Kill), [supervisor:start_child(?MODULE, Spec) || Spec <- Specs], ok. %% @spec init([]) -> SupervisorTree %% @doc supervisor callback. init([]) -> PongerlServer = worker(pongerl_server), PongerlEngine = worker(pongerl_engine), - {ok, {{one_for_one, 10, 10}, [PongerlEngine]}}. + {ok, {{one_for_one, 10, 10}, [PongerlServer, PongerlEngine]}}.
jordi-chacon/pongerl
8aaca7b0522b0d6c6a1660391f396252c0cf6e98
Implemented basic game engine where the ball goes back and forth always in horizontal direction. Goal detection is also implemented in this version. The engine is run every xx miliseconds by a loop process until someone scores a goal and the loop process sends an asynchronous restart_game request and dies right away.
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index 61a53d8..7348597 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,14 +1,22 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). % Dimensions of the field -define(X0, 0). -define(Y0, 0). -define(XF, 80). -define(YF, 20). +% Dimensions of the bars of the clients +-define(CY, 3). +-define(CX, 1). + +% Dimensions of the ball +-define(BX, 2). +-define(BY, 1). + -record(ball, {x = (?XF - ?X0) div 2, y = (?YF - ?Y0) div 2, speed = 1, degrees = 180}). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl index 4c341d7..37fbf94 100644 --- a/src/pongerl_engine.erl +++ b/src/pongerl_engine.erl @@ -1,94 +1,191 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_engine). -behaviour(gen_server). %% API -export([start_game/2, + restart_game/0, get_state/0, - change_client_position/2]). + change_client_position/2, + run_engine/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include_lib("../include/pongerl.hrl"). -define(SERVER, ?MODULE). --record(state, {clients = [], ball = #ball{}}). +-record(state, {clients = [], ball = #ball{}, path = []}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. start_game(ID1, ID2) -> gen_server:call(?MODULE, {start_game, ID1, ID2}). +restart_game() -> + gen_server:cast(?MODULE, restart_game). + get_state() -> gen_server:call(?MODULE, get_state). change_client_position(ClientID, Direction) -> - gen_srever:call(?MODULE, {change_client_position, ClientID, Direction}). + gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). + +run_engine() -> + gen_server:call(?MODULE, run_engine). handle_call({start_game, ID1, ID2}, _From, State) -> do_start_game(ID1, ID2, State); handle_call(get_state, _From, State) -> do_get_state(State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); +handle_call(run_engine, _From, State) -> + do_run_engine(State); handle_call(_Request, _From, State) -> {reply, error, State}. +handle_cast(restart_game, State) -> + do_restart_game(State); handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_start_game(ID1, ID2, _State) -> C1 = get_initial_position_client(first), C2 = get_initial_position_client(second), Ball = get_initial_position_ball(), NewState = #state{clients = [{ID1, C1}, {ID2, C2}], ball = Ball}, + register(run_engine_caller, run_engine_caller()), {reply, ok, NewState}. +do_restart_game(State) -> + Ball = get_initial_position_ball(), + NewState = State#state{ball = Ball}, + register(run_engine_caller, run_engine_caller()), + {noreply, NewState}. + do_get_state(State) -> CPos = State#state.clients, BallPos = get_ball_position(State#state.ball), {reply, {CPos, BallPos}, State}. do_change_client_position(ClientID, Direction, State) -> CPos = get_client_new_position(ClientID, State#state.clients, Direction), PL1 = proplists:delete(ClientID, State#state.clients), NewState = State#state{clients = [{ClientID, CPos} | PL1]}, {reply, ok, NewState}. +do_run_engine(#state{clients = [{_ID1, P1}, {_ID2, P2}], ball = Ball} =State) -> + case run_steps(P1, P2, Ball) of + {Path, NewBall} -> ok; + {Path, NewBall, end_of_game} -> run_engine_caller ! die + end, + {reply, ok, State#state{ball = NewBall, path = Path}}. + + +%%%=================================================================== +%%% More internal functions +%%%=================================================================== + get_initial_position_client(first) -> {?X0 + 2, ?Y0 div 2}; get_initial_position_client(second) -> {?XF - 2, ?Y0 div 2}. get_initial_position_ball() -> #ball{}. get_ball_position(#ball{x = X, y = Y}) -> {X, Y}. -get_client_new_position(ID, [{ID, {X, Y}} | _T], ?UP) -> {X - 1, Y}; -get_client_new_position(ID, [{ID, {X, Y}} | _T], ?DOWN) -> {X + 1, Y}; +get_client_new_position(ID, [{ID, {X, Y}} | _T], ?UP) -> {X, Y - 1}; +get_client_new_position(ID, [{ID, {X, Y}} | _T], ?DOWN) -> {X, Y + 1}; get_client_new_position(ID, [{_ID, _Pos} | T], Dir) -> get_client_new_position(ID, T, Dir). + +run_steps(P1, P2, Ball) -> + run_step(P1, P2, Ball, [], Ball#ball.speed). + +% steps done +run_step(_P1, _P2, Ball, Path, 0) -> + {Path, Ball}; +% end of game +run_step({X1, _Y1}, {X2, _Y2}, #ball{x = BX} = Ball, Path, _Steps) + when X1 =:= BX orelse X2 =:= BX -> + {Path, Ball, end_of_game}; +run_step(P1 = {X1, Y1}, P2, #ball{x = XB, y = YB} = Ball, Path, Steps) + when XB =:= X1 + 1-> + Degrees = Ball#ball.degrees, + case YB >= Y1 andalso YB =< Y1 + ?CY of + true -> + % client 1 touches the ball + NewDegrees = get_new_degree(Degrees, opposite), + NewPath = [{XB, YB} | Path], + NewBall = Ball#ball{degrees = NewDegrees}; + false -> + % client 1 receives a goal + {NX, NY} = get_next_ball_position(XB, YB, Degrees), + NewPath = [{NX, NY} | Path], + NewBall = Ball#ball{x = NX, y = NY} + end, + run_step(P1, P2, NewBall, NewPath, Steps - 1); +run_step(P1, P2 = {X2, Y2}, #ball{x = XB, y = YB} = Ball, Path, Steps) + when XB =:= X2 - 1 -> + Degrees = Ball#ball.degrees, + case YB >= Y2 andalso YB =< Y2 + ?CY of + true -> + % client 2 touches the ball + NewDegrees = get_new_degree(Degrees, opposite), + NewPath = [{XB, YB} | Path], + NewBall = Ball#ball{degrees = NewDegrees}; + false -> + % client 2 receives a goal + {NX, NY} = get_next_ball_position(XB, YB, Degrees), + NewPath = [{NX, NY} | Path], + NewBall = Ball#ball{x = NX, y = NY} + end, + run_step(P1, P2, NewBall, NewPath, Steps - 1); +run_step(P1, P2, #ball{x = X, y = Y} = Ball, Path, Steps) -> + Degrees = Ball#ball.degrees, + {NX, NY} = get_next_ball_position(X, Y, Degrees), + NewPath = [{NX, NY} | Path], + run_step(P1, P2, Ball#ball{x = NX, y = NY}, NewPath, Steps - 1). + +get_new_degree(180, opposite) -> 0; +get_new_degree(0, opposite) -> 180. + +get_next_ball_position(X, Y, 180) -> {X - 1, Y}; +get_next_ball_position(X, Y, 0) -> {X + 1, Y}. + + +% loop to run the game engine every xx ms +run_engine_caller() -> + receive + die -> + timer:sleep(2000), + restart_game() + after 100 -> + ok = run_engine(), + run_engine_caller() + end.
jordi-chacon/pongerl
2673728157584682c3fefb3de19390671a6cd271
Added basic services of pongerl_engine, the interface to the engine of pongerl. The actual game engine is still to be implemented
diff --git a/include/pongerl.hrl b/include/pongerl.hrl index e9664c7..61a53d8 100644 --- a/include/pongerl.hrl +++ b/include/pongerl.hrl @@ -1,3 +1,14 @@ % A client can move up and down -define(UP, 1). -define(DOWN, 2). + +% Dimensions of the field +-define(X0, 0). +-define(Y0, 0). +-define(XF, 80). +-define(YF, 20). + +-record(ball, {x = (?XF - ?X0) div 2, + y = (?YF - ?Y0) div 2, + speed = 1, + degrees = 180}). diff --git a/src/pongerl_engine.erl b/src/pongerl_engine.erl new file mode 100644 index 0000000..4c341d7 --- /dev/null +++ b/src/pongerl_engine.erl @@ -0,0 +1,94 @@ +%%% @author Jordi Chacon <jordi.chacon@gmail.com> +%%% @copyright (C) 2010, Jordi Chacon + +-module(pongerl_engine). + +-behaviour(gen_server). + +%% API +-export([start_game/2, + get_state/0, + change_client_position/2]). + +%% gen_server callbacks +-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-include_lib("../include/pongerl.hrl"). + +-define(SERVER, ?MODULE). + +-record(state, {clients = [], ball = #ball{}}). + + +start_link() -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). + +init([]) -> + {ok, #state{}}. + +start_game(ID1, ID2) -> + gen_server:call(?MODULE, {start_game, ID1, ID2}). + +get_state() -> + gen_server:call(?MODULE, get_state). + +change_client_position(ClientID, Direction) -> + gen_srever:call(?MODULE, {change_client_position, ClientID, Direction}). + +handle_call({start_game, ID1, ID2}, _From, State) -> + do_start_game(ID1, ID2, State); +handle_call(get_state, _From, State) -> + do_get_state(State); +handle_call({change_client_position, ClientID, Direction}, _From, State) -> + do_change_client_position(ClientID, Direction, State); +handle_call(_Request, _From, State) -> + {reply, error, State}. + +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + + +%%%=================================================================== +%%% Internal functions +%%%=================================================================== + +do_start_game(ID1, ID2, _State) -> + C1 = get_initial_position_client(first), + C2 = get_initial_position_client(second), + Ball = get_initial_position_ball(), + NewState = #state{clients = [{ID1, C1}, {ID2, C2}], ball = Ball}, + {reply, ok, NewState}. + +do_get_state(State) -> + CPos = State#state.clients, + BallPos = get_ball_position(State#state.ball), + {reply, {CPos, BallPos}, State}. + +do_change_client_position(ClientID, Direction, State) -> + CPos = get_client_new_position(ClientID, State#state.clients, Direction), + PL1 = proplists:delete(ClientID, State#state.clients), + NewState = State#state{clients = [{ClientID, CPos} | PL1]}, + {reply, ok, NewState}. + +get_initial_position_client(first) -> {?X0 + 2, ?Y0 div 2}; +get_initial_position_client(second) -> {?XF - 2, ?Y0 div 2}. + +get_initial_position_ball() -> #ball{}. + +get_ball_position(#ball{x = X, y = Y}) -> {X, Y}. + +get_client_new_position(ID, [{ID, {X, Y}} | _T], ?UP) -> {X - 1, Y}; +get_client_new_position(ID, [{ID, {X, Y}} | _T], ?DOWN) -> {X + 1, Y}; +get_client_new_position(ID, [{_ID, _Pos} | T], Dir) -> + get_client_new_position(ID, T, Dir). + diff --git a/src/pongerl_server.erl b/src/pongerl_server.erl index 654f3a1..7118cab 100644 --- a/src/pongerl_server.erl +++ b/src/pongerl_server.erl @@ -1,79 +1,81 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_server). -behaviour(gen_server). %% API -export([connect_client/0, change_client_position/2, get_state/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). +-include_lib("../include/pongerl.hrl"). + -define(SERVER, ?MODULE). -record(state, {clients = [], last_id = 0}). start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). init([]) -> {ok, #state{}}. connect_client() -> - gen_server:call(?MODULE, {connect_client}). + gen_server:call(?MODULE, connect_client). get_state() -> - gen_server:call(?MODULE, {get_state}). + gen_server:call(?MODULE, get_state). change_client_position(ClientID, Direction) -> gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). -handle_call({connect_client}, _From, State) -> +handle_call(connect_client, _From, State) -> do_connect_client(State); -handle_call({get_state}, _From, State) -> +handle_call(get_state, _From, State) -> do_get_state(State); handle_call({change_client_position, ClientID, Direction}, _From, State) -> do_change_client_position(ClientID, Direction, State); handle_call(_Request, _From, State) -> {reply, error, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_connect_client(State) -> ID = State#state.last_id, Clients = [Id|State#state.clients], case Clients of - [ID1, ID2] -> pongerl_engine:start(ID1, ID2), + [ID1, ID2] -> ok = pongerl_engine:start_game(ID1, ID2), _ -> ok - end. + end, NewState = State#state{last_id = ID+ 1, clients = Clients}, {reply, Id, NewState}. do_get_state(State) -> Reply = pongerl_engine:get_state(), {reply, Reply, State}. do_change_client_position(ClientID, Direction, State) -> - game_engine:change_client_position(ClientID, Direction), + ok = game_engine:change_client_position(ClientID, Direction), {reply, ok, State}. diff --git a/src/pongerl_sup.erl b/src/pongerl_sup.erl index 368a105..70c15ce 100644 --- a/src/pongerl_sup.erl +++ b/src/pongerl_sup.erl @@ -1,52 +1,53 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_sup). -behaviour(supervisor). %% External exports -export([start_link/0, upgrade/0]). %% supervisor callbacks -export([init/1]). %% @spec start_link() -> ServerRet %% @doc API for starting the supervisor. start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). server(Name, Type) -> server(Name, Type, 2000). server(Name, Type, Shutdown) -> {Name, {Name, start_link, []}, permanent, Shutdown, Type, [Name]}. worker(Name) -> server(Name, worker). %% @spec upgrade() -> ok %% @doc Add processes if necessary. upgrade() -> {ok, {_, Specs}} = init([]), Old = sets:from_list( [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]), New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]), Kill = sets:subtract(Old, New), sets:fold(fun (Id, ok) -> supervisor:terminate_child(?MODULE, Id), supervisor:delete_child(?MODULE, Id), ok end, ok, Kill), [supervisor:start_child(?MODULE, Spec) || Spec <- Specs], ok. %% @spec init([]) -> SupervisorTree %% @doc supervisor callback. init([]) -> PongerlServer = worker(pongerl_server), - {ok, {{one_for_one, 10, 10}, [PongerlServer]}}. + PongerlEngine = worker(pongerl_engine), + {ok, {{one_for_one, 10, 10}, [PongerlEngine]}}.
jordi-chacon/pongerl
cce83168d6bfdc1ec12ef694ba10c0d128bf7c79
Implemented basic funcionality of the pongerl main server
diff --git a/include/pongerl.hrl b/include/pongerl.hrl new file mode 100644 index 0000000..e9664c7 --- /dev/null +++ b/include/pongerl.hrl @@ -0,0 +1,3 @@ +% A client can move up and down +-define(UP, 1). +-define(DOWN, 2). diff --git a/src/pongerl_server.erl b/src/pongerl_server.erl index 7272690..654f3a1 100644 --- a/src/pongerl_server.erl +++ b/src/pongerl_server.erl @@ -1,124 +1,79 @@ %%% @author Jordi Chacon <jordi.chacon@gmail.com> %%% @copyright (C) 2010, Jordi Chacon -module(pongerl_server). -behaviour(gen_server). %% API --export([]). +-export([connect_client/0, + change_client_position/2, + get_state/0]). %% gen_server callbacks -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -define(SERVER, ?MODULE). --record(state, {}). +-record(state, {clients = [], last_id = 0}). -%%%=================================================================== -%%% API -%%%=================================================================== - - -%%-------------------------------------------------------------------- -%% @doc -%% Starts the server -%% -%% @spec start_link() -> {ok, Pid} | ignore | {error, Error} -%% @end -%%-------------------------------------------------------------------- start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). -%%%=================================================================== -%%% gen_server callbacks -%%%=================================================================== - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Initiates the server -%% -%% @spec init(Args) -> {ok, State} | -%% {ok, State, Timeout} | -%% ignore | -%% {stop, Reason} -%% @end -%%-------------------------------------------------------------------- init([]) -> {ok, #state{}}. -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Handling call messages -%% -%% @spec handle_call(Request, From, State) -> -%% {reply, Reply, State} | -%% {reply, Reply, State, Timeout} | -%% {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, Reply, State} | -%% {stop, Reason, State} -%% @end -%%-------------------------------------------------------------------- +connect_client() -> + gen_server:call(?MODULE, {connect_client}). + +get_state() -> + gen_server:call(?MODULE, {get_state}). + +change_client_position(ClientID, Direction) -> + gen_server:call(?MODULE, {change_client_position, ClientID, Direction}). + +handle_call({connect_client}, _From, State) -> + do_connect_client(State); +handle_call({get_state}, _From, State) -> + do_get_state(State); +handle_call({change_client_position, ClientID, Direction}, _From, State) -> + do_change_client_position(ClientID, Direction, State); handle_call(_Request, _From, State) -> - Reply = ok, - {reply, Reply, State}. + {reply, error, State}. -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Handling cast messages -%% -%% @spec handle_cast(Msg, State) -> {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} -%% @end -%%-------------------------------------------------------------------- handle_cast(_Msg, State) -> {noreply, State}. -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Handling all non call/cast messages -%% -%% @spec handle_info(Info, State) -> {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} -%% @end -%%-------------------------------------------------------------------- handle_info(_Info, State) -> {noreply, State}. -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% This function is called by a gen_server when it is about to -%% terminate. It should be the opposite of Module:init/1 and do any -%% necessary cleaning up. When it returns, the gen_server terminates -%% with Reason. The return value is ignored. -%% -%% @spec terminate(Reason, State) -> void() -%% @end -%%-------------------------------------------------------------------- terminate(_Reason, _State) -> ok. -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Convert process state when code is changed -%% -%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} -%% @end -%%-------------------------------------------------------------------- code_change(_OldVsn, State, _Extra) -> {ok, State}. + %%%=================================================================== %%% Internal functions %%%=================================================================== + +do_connect_client(State) -> + ID = State#state.last_id, + Clients = [Id|State#state.clients], + case Clients of + [ID1, ID2] -> pongerl_engine:start(ID1, ID2), + _ -> ok + end. + NewState = State#state{last_id = ID+ 1, clients = Clients}, + {reply, Id, NewState}. + +do_get_state(State) -> + Reply = pongerl_engine:get_state(), + {reply, Reply, State}. + +do_change_client_position(ClientID, Direction, State) -> + game_engine:change_client_position(ClientID, Direction), + {reply, ok, State}.
jordi-chacon/pongerl
3a1c073619a429a113e2c15ec204d700cdb4d9f1
.gitignore file added
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4e5f6c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ \ No newline at end of file
jordi-chacon/pongerl
8e3b66658a1b002a5719832bfef8f29874086776
pongerl_server created. Basic structure of a gen_server module added
diff --git a/src/pongerl_server.erl b/src/pongerl_server.erl new file mode 100644 index 0000000..7272690 --- /dev/null +++ b/src/pongerl_server.erl @@ -0,0 +1,124 @@ +%%% @author Jordi Chacon <jordi.chacon@gmail.com> +%%% @copyright (C) 2010, Jordi Chacon + +-module(pongerl_server). + +-behaviour(gen_server). + +%% API +-export([]). + +%% gen_server callbacks +-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-define(SERVER, ?MODULE). + +-record(state, {}). + +%%%=================================================================== +%%% API +%%%=================================================================== + + + +%%-------------------------------------------------------------------- +%% @doc +%% Starts the server +%% +%% @spec start_link() -> {ok, Pid} | ignore | {error, Error} +%% @end +%%-------------------------------------------------------------------- +start_link() -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). + +%%%=================================================================== +%%% gen_server callbacks +%%%=================================================================== + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Initiates the server +%% +%% @spec init(Args) -> {ok, State} | +%% {ok, State, Timeout} | +%% ignore | +%% {stop, Reason} +%% @end +%%-------------------------------------------------------------------- +init([]) -> + {ok, #state{}}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling call messages +%% +%% @spec handle_call(Request, From, State) -> +%% {reply, Reply, State} | +%% {reply, Reply, State, Timeout} | +%% {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, Reply, State} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_call(_Request, _From, State) -> + Reply = ok, + {reply, Reply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling cast messages +%% +%% @spec handle_cast(Msg, State) -> {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_cast(_Msg, State) -> + {noreply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling all non call/cast messages +%% +%% @spec handle_info(Info, State) -> {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_info(_Info, State) -> + {noreply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% This function is called by a gen_server when it is about to +%% terminate. It should be the opposite of Module:init/1 and do any +%% necessary cleaning up. When it returns, the gen_server terminates +%% with Reason. The return value is ignored. +%% +%% @spec terminate(Reason, State) -> void() +%% @end +%%-------------------------------------------------------------------- +terminate(_Reason, _State) -> + ok. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Convert process state when code is changed +%% +%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} +%% @end +%%-------------------------------------------------------------------- +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%%%=================================================================== +%%% Internal functions +%%%===================================================================
jordi-chacon/pongerl
8d02c690b3d89971897058e3e2aa9f448ccc3c76
Supervisor and application modules created. App file created
diff --git a/src/pongerl.app.src b/src/pongerl.app.src new file mode 100644 index 0000000..418de3c --- /dev/null +++ b/src/pongerl.app.src @@ -0,0 +1,19 @@ +{application, pongerl, + [ + {description, "pongerl - An x-term-based version of the arcade video game Pong."}, + + % The Module and Args used to start this application. + {mod, { pongerl_app, []} }, + + % All modules used by the application. + {modules, + [pongerl_app + ,pongerl_sup + ]}, + + % configuration parameters similar to those in the config file specified on the command line + {env, [{ip, "0.0.0.0"} + ,{hostname, "localhost"} + ,{port, 8282} + ]} + ]}. diff --git a/src/pongerl_app.erl b/src/pongerl_app.erl new file mode 100644 index 0000000..e7b0bd5 --- /dev/null +++ b/src/pongerl_app.erl @@ -0,0 +1,17 @@ +%% @author Jordi Chacon <jordi.chacon@gmail.com> +%% @copyright 2010 Jordi Chacon + +%% @doc Callbacks for the pongerl application. + +-module(pongerl_app). +-behaviour(application). + +-export([start/2, stop/1]). + +-include("pongerl.hrl"). + +start(_, _) -> + polish_sup:start_link(). + +stop(_) -> + ok. diff --git a/src/pongerl_sup.erl b/src/pongerl_sup.erl new file mode 100644 index 0000000..368a105 --- /dev/null +++ b/src/pongerl_sup.erl @@ -0,0 +1,52 @@ +%%% @author Jordi Chacon <jordi.chacon@gmail.com> +%%% @copyright (C) 2010, Jordi Chacon + +-module(pongerl_sup). + +-behaviour(supervisor). + +%% External exports +-export([start_link/0, upgrade/0]). + +%% supervisor callbacks +-export([init/1]). + +%% @spec start_link() -> ServerRet +%% @doc API for starting the supervisor. +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +server(Name, Type) -> + server(Name, Type, 2000). + +server(Name, Type, Shutdown) -> + {Name, {Name, start_link, []}, permanent, Shutdown, Type, [Name]}. + +worker(Name) -> server(Name, worker). + +%% @spec upgrade() -> ok +%% @doc Add processes if necessary. +upgrade() -> + {ok, {_, Specs}} = init([]), + + Old = sets:from_list( + [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]), + New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]), + Kill = sets:subtract(Old, New), + + sets:fold(fun (Id, ok) -> + supervisor:terminate_child(?MODULE, Id), + supervisor:delete_child(?MODULE, Id), + ok + end, ok, Kill), + + [supervisor:start_child(?MODULE, Spec) || Spec <- Specs], + ok. + +%% @spec init([]) -> SupervisorTree +%% @doc supervisor callback. +init([]) -> + PongerlServer = worker(pongerl_server), + {ok, {{one_for_one, 10, 10}, [PongerlServer]}}. + +
jordi-chacon/pongerl
e3f876f50c20427773f3303ccb5f2afc269adb5b
Files Makefile, Emakefile, dep.inc and start.sh added
diff --git a/Emakefile b/Emakefile new file mode 100644 index 0000000..dfec6d1 --- /dev/null +++ b/Emakefile @@ -0,0 +1,12 @@ +{ './src/*', [ + { i, "./include" }, + { i, "./dep/cecho" }, + { outdir, "./ebin" }, + debug_info +]}. +{ './test/*', [ + { i, "./include" }, + { i, "./dep/cecho" }, + { outdir, "./ebin" }, + debug_info +]}. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4c50410 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +include dep.inc + +all: + erl -make + +init: + -mkdir ebin + -mkdir dep + -git submodule init + -git submodule update + -(cd dep/cecho; make) + -chmod +x ./start.sh + cp src/pongerl.app.src ebin/pongerl.app + $(MAKE) all + +clean: + rm -rf ./ebin/*.beam diff --git a/dep.inc b/dep.inc new file mode 100644 index 0000000..5fdb96a --- /dev/null +++ b/dep.inc @@ -0,0 +1,2 @@ +NAME=pongerl +CECHO_EBIN=dep/cecho/ebin \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..848552b --- /dev/null +++ b/start.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +cd `dirname $0` + +. ./dep.inc + +echo "Starting Pongerl..." +erl \ + -sname ${NAME} \ + -pa ./ebin ${CECHO_EBIN} \ + -eval "application:start(pongerl)" \ No newline at end of file
jordi-chacon/pongerl
b55dcff256684f9efece38dea5be35c6bcc6d0c0
Added the cecho ncurses library as a submodule
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a22a753 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dep/cecho"] + path = dep/cecho + url = git://github.com/mazenharake/cecho.git diff --git a/dep/cecho b/dep/cecho new file mode 160000 index 0000000..85833d9 --- /dev/null +++ b/dep/cecho @@ -0,0 +1 @@ +Subproject commit 85833d97f6df06e0e3495c0043df025dce391883
vim-scripts/gpg.vim
c4fe826febb62e0ff937f62c5e8621a5f1ee5e35
Version 0.1: Initial upload
diff --git a/README b/README new file mode 100644 index 0000000..eb77122 --- /dev/null +++ b/README @@ -0,0 +1,9 @@ +This is a mirror of http://www.vim.org/scripts/script.php?script_id=660 + +As I know little about vim scripts, this was just a thought which proved convenient for me. But I just noticed there's a new plugin called 'gnupg.vim' after this which is much better. Please download that instead. I tried to delete this from the server. + +This little plugin helps to edit "gpg" encrypted files. I use this because it's more convenient when you do not have GUI encrypt tools. + +How to use: +just name the file with .gpg suffix, e.g. "something.gpg" and +vi -u ~/.vim/gpg.vim something.gpg diff --git a/plugin/gpg.vim b/plugin/gpg.vim new file mode 100644 index 0000000..8b23e2d --- /dev/null +++ b/plugin/gpg.vim @@ -0,0 +1,22 @@ +"Vim plugin for editing gpg encrypted files +"Maintainer: Guang Yu Liu <guangyuliu@att.com> +"Last Change: 15/05/2003 +"you need to have gpg set up already and with the following script +"in your PATH: +"1) dgpg: calls gpg to decrypt, just have this in the script: +"gpg -d 2>/dev/null ### this will decrypt the contents +" +"2) egpg: calls gpg to encrypt: +"gpg -e -r yourname@yourdomain +"### yourname@yourdomain is the yourself as the recipient +"### so that it will encrypt the contents using your public key +"### please check docs from gpg. +" +:augroup gpg +: autocmd! +: autocmd BufReadPre,FileReadPre *.gpg set bin +: autocmd BufReadPost,FileReadPost *.gpg '[,']!dgpg +: autocmd BufReadPost,FileReadPost *.gpg set nobin +: autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r") +: autocmd BufWritePre,FileWritePre *.gpg '[,']!egpg +:augroup END
rdp/google_voice_system_tray
6eb3ebe65e4c958d5e2ef4a9c9facb344c67f792
some cleanup, add real numbers
diff --git a/tray.py b/tray.py index 75a1df2..f536eb5 100644 --- a/tray.py +++ b/tray.py @@ -1,276 +1,276 @@ #!/usr/bin/env python # Module : SysTrayIcon.py # Synopsis : Windows System tray icon. # Programmer : Simon Brunning - simon@brunningonline.net # Date : 11 April 2005 # Notes : Based on (i.e. ripped off from) Mark Hammond's # win32gui_taskbar.py and win32gui_menu.py demos from PyWin32 '''TODO For now, the demo at the bottom shows how to use it...''' import os import sys import win32api import win32con import win32gui_struct from googlevoice import Voice from googlevoice.util import input import commands - - try: import winxpgui as win32gui except ImportError: import win32gui class SysTrayIcon(object): '''TODO''' QUIT = 'QUIT' SPECIAL_ACTIONS = [QUIT] FIRST_ID = 1023 def __init__(self, icon, hover_text, menu_options, on_quit=None, default_menu_index=None, window_class_name=None,): self.icon = icon self.hover_text = hover_text self.on_quit = on_quit menu_options = menu_options + (('Quit', None, self.QUIT),) self._next_action_id = self.FIRST_ID self.menu_actions_by_id = set() self.menu_options = self._add_ids_to_menu_options(list(menu_options)) self.menu_actions_by_id = dict(self.menu_actions_by_id) del self._next_action_id self.default_menu_index = (default_menu_index or 0) self.window_class_name = window_class_name or "SysTrayIconPy" message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER+20 : self.notify,} # Register the Window class. window_class = win32gui.WNDCLASS() hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.lpszClassName = self.window_class_name window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map # could also specify a wndproc. classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.notify_id = None self.refresh_icon() win32gui.PumpMessages() def _add_ids_to_menu_options(self, menu_options): result = [] for menu_option in menu_options: option_text, option_icon, option_action = menu_option if callable(option_action) or option_action in self.SPECIAL_ACTIONS: self.menu_actions_by_id.add((self._next_action_id, option_action)) result.append(menu_option + (self._next_action_id,)) elif non_string_iterable(option_action): result.append((option_text, option_icon, self._add_ids_to_menu_options(option_action), self._next_action_id)) else: print 'Unknown item', option_text, option_icon, option_action self._next_action_id += 1 return result def refresh_icon(self): # Try and find a custom icon hinst = win32gui.GetModuleHandle(None) if os.path.isfile(self.icon): icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = win32gui.LoadImage(hinst, self.icon, win32con.IMAGE_ICON, 0, 0, icon_flags) else: print "Can't find icon file - using default." hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION) if self.notify_id: message = win32gui.NIM_MODIFY else: message = win32gui.NIM_ADD self.notify_id = (self.hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP, win32con.WM_USER+20, hicon, self.hover_text) win32gui.Shell_NotifyIcon(message, self.notify_id) def restart(self, hwnd, msg, wparam, lparam): self.refresh_icon() def destroy(self, hwnd, msg, wparam, lparam): if self.on_quit: self.on_quit(self) nid = (self.hwnd, 0) win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid) win32gui.PostQuitMessage(0) # Terminate the app. def notify(self, hwnd, msg, wparam, lparam): try: if lparam==win32con.WM_LBUTTONDBLCLK: self.execute_menu_option(self.default_menu_index + self.FIRST_ID) elif lparam==win32con.WM_RBUTTONUP: self.show_menu() elif lparam==win32con.WM_LBUTTONUP: pass return True except KeyboardInterrupt: print 'destroying' self.destroy def show_menu(self): menu = win32gui.CreatePopupMenu() self.create_menu(menu, self.menu_options) #win32gui.SetMenuDefaultItem(menu, 1000, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) def create_menu(self, menu, menu_options): for option_text, option_icon, option_action, option_id in menu_options[::-1]: if option_icon: option_icon = self.prep_menu_icon(option_icon) if option_id in self.menu_actions_by_id: item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, hbmpItem=option_icon, wID=option_id) win32gui.InsertMenuItem(menu, 0, 1, item) else: submenu = win32gui.CreatePopupMenu() self.create_menu(submenu, option_action) item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, hbmpItem=option_icon, hSubMenu=submenu) win32gui.InsertMenuItem(menu, 0, 1, item) def prep_menu_icon(self, icon): # First load the icon. ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(0) hdcScreen = win32gui.GetDC(0) hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y) hbmOld = win32gui.SelectObject(hdcBitmap, hbm) # Fill the background. brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush) # unclear if brush needs to be feed. Best clue I can find is: # "GetSysColorBrush returns a cached brush instead of allocating a new # one." - implies no DeleteObject # draw the icon win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) win32gui.SelectObject(hdcBitmap, hbmOld) win32gui.DeleteDC(hdcBitmap) return hbm def command(self, hwnd, msg, wparam, lparam): id = win32gui.LOWORD(wparam) self.execute_menu_option(id) def execute_menu_option(self, id): menu_action = self.menu_actions_by_id[id] if menu_action == self.QUIT: win32gui.DestroyWindow(self.hwnd) else: menu_action(self) def non_string_iterable(obj): try: iter(obj) except TypeError: return False else: return not isinstance(obj, basestring) # Minimal self test. You'll need a bunch of ICO files in the current working # directory in order for this to work... if __name__ == '__main__': import itertools, glob icons = itertools.cycle(glob.glob('*.ico')) hover_text = "SysTrayIcon.py Demo" def hello(sysTrayIcon): print "Hello World." def simon(sysTrayIcon): print "Hello Simon." #TODO require gmail password on startup def call_number(sysTrayIcon, outgoingNumber): - print 'in call_number' + print 'in call_number', outgoingNumber voice = Voice() - gmail_name = open('/installs/gmail_name', 'r').read + gmail_name = open('/installs/gmail_name', 'r').read() print gmail_name - gmail_password = open('/installs/gmail_password', 'r').read - print gmail_password + gmail_password = open('/installs/gmail_password', 'r').read() + #print gmail_password voice.login(gmail_name, gmail_password) + # todo #forwardingNumber = open('/installs/call_here', 'r').read#'8012408783' forwardingNumber = '8012408783' voice.call(outgoingNumber, forwardingNumber) #def edit(sysTrayIcon): # import commands.getstatusoutput('notepad /installs/list.txt') def switch_icon(sysTrayIcon): sysTrayIcon.icon = icons.next() sysTrayIcon.refresh_icon() menu_options = (('Say Hello', icons.next(), hello), # ('Edit names', icons.next(), edit), - ('Call Ben', None, lambda sysTrayIcon : sysTrayIcon.call_number('8012408783') ), + ('Call Ben', None, lambda sysTrayIcon : call_number(sysTrayIcon, '(801) 787-1920') ), + ('Call Cell', None, lambda sysTrayIcon : call_number(sysTrayIcon, '+18016916597') ), ('Switch Icon', None, switch_icon), ('A sub-menu', icons.next(), (('Say Hello to Simon', icons.next(), simon), ('Switch Icon', icons.next(), switch_icon), )) ) # for line in open('/installs/list.txt').read.split("\n"): # print line def bye(sysTrayIcon): print 'Bye, then.' SysTrayIcon(icons.next(), hover_text, menu_options, on_quit=bye, default_menu_index=1)
mykal/Squeegee
e5b2438f067d9e0c7d979db3805932b02cd0cce7
Second commit
diff --git a/README b/README index e69de29..8d087e5 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +Please insert README text
Tadrion/cpp-stuff
772f0893f1f5a03d3d0c116536424e546e74d3a2
Bignum with adding and multiplication. Not very 'professional'.
diff --git a/bignum.cpp b/bignum.cpp index d7f032a..1fe823b 100644 --- a/bignum.cpp +++ b/bignum.cpp @@ -1,154 +1,124 @@ #include <cstdio> #include <vector> #include <iostream> #include <string> #include <cmath> #define MAX(a,b) (a) < (b) ? (b) : (a) #define MIN(a,b) (a) > (b) ? (b) : (a) using namespace std; bool corrIndex (int i, vector<int> v) { return (i >= 0 && i < v.size() ); } void correctSize (vector<int> *w) { int i = (*w).size() - 1; while( (*w)[i] == 0) i--; (*w).resize(i + 1); } class Bignum { public: vector<int> number; Bignum() { number = vector<int> (1,0); for (int i = 0; i < number.size(); i++) number[i] = 0; } Bignum(unsigned int n) { number = vector<int> (MAX (ceil(log10((double)n)), 1) + 1, 0); int i = 0; while(n > 0) { number[i] = n % 10; n /= 10; i++; } } Bignum(vector<int> v) { number = v; } string toString() { string str = string(number.size(),'0'); int length = number.size(); for (int i = 0; i < length; i++) { str[i] = number[length - i - 1] + '0'; } return str; } void corSize() { correctSize(&(number)); } }; void correctBignumSize (Bignum *b) { correctSize( & ( (*b).number ) ); } Bignum operator+ (Bignum a, Bignum b) { int length = (MAX( (a.number.size()), (b.number.size()))); vector<int> res = vector<int> (); int tmp,shift = 0; for (int i = 0; i <= length; i++) { if(corrIndex(i,a.number) && corrIndex(i,b.number) ) tmp = a.number[i] + b.number[i] + shift; else if (corrIndex(i,a.number)) tmp = a.number[i] + shift; else if (corrIndex(i,b.number)) tmp = b.number[i] + shift; else tmp = shift; res.push_back (tmp % 10); if (tmp >= 10) shift = 1; else shift = 0; } correctSize(&res); return Bignum(res); } Bignum operator* (Bignum a, Bignum b) { vector<int> tmp = vector<int> (); int tmp2; Bignum tmp3; Bignum res = Bignum(0); Bignum res2 = Bignum(0); int shift = 0; a.corSize(); b.corSize(); for(int i = 0; i < b.number.size(); i++) { shift = 0; for(int k = 0; k < i; k++) tmp.push_back(0); for(int j = 0; j < a.number.size(); j++) { tmp2 = b.number[i] * a.number[j] + shift; tmp.push_back(tmp2 % 10); shift = tmp2 / 10; } if (shift > 0) tmp.push_back(shift); - // printf("Mnoze razy %d \n",b.number[i]); - // for(int i = tmp.size() - 1; i >= 0; i--) - // printf("%d ",tmp[i]); - // printf("\n"); res = res + Bignum(tmp); tmp.resize(0); } res.corSize(); return res; } int main() { - Bignum mybig,mybig2,mybig3; - mybig = Bignum(13); - mybig2 = Bignum(13); - mybig3 = Bignum(1); - - for(int i = 0; i <= 50; i++) { - - // cout << i << " " << mybig3.toString() << " = " << mybig.toString() << " * " - // << mybig2.toString() << endl; - - cout << i << " " << mybig3.toString() << endl; - - mybig = mybig3; - mybig3 = mybig3 * mybig2; - } - - // mybig3 = Bignum(1); - // mybig = Bignum(13); - // mybig2 = Bignum(371293); - // mybig3 = mybig * mybig2; - - // cout << mybig3.toString() << endl; - - - //mybig3 = mybig3 * mybig3; - //cout << mybig3.toString() << endl; return 0; }
zeroLaming/zerolaming.github.com
dac58b3ee3cf5660610f0aa78fc83eeb95fe5f0b
Basic Page
diff --git a/README b/README index e69de29..f14a856 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +GITHUB HOMEPAGE diff --git a/index.html b/index.html index d4b1f4a..d1cdcfc 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,24 @@ <html> <head> <title>Mike Laming's Github</title> + <link rel="stylesheet" type="text/css" href="style.css" /> </head> - <body> -Initial +<h1> + <span class="pinkHighlight"> + Mike Laming's Github + </span> +</h1> + +<p class="empty"> + <a href="http://github.com/zeroLaming">Nothing here, yet.</a> +</p> + +<p class="other"> + <span class="fade">Elsewhere</span> + <span class="site-mike"><a href="http://mikelaming.com">mikelaming.com</a></span> + <span class="site-twitter"><a href="http://twitter.com/mikelaming">@mikelaming</a></span> +</p> + </body> -</html> +</html> \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..f3b403b --- /dev/null +++ b/style.css @@ -0,0 +1,39 @@ +html,body { + font-family: 'Helvetica', Arial, sans-serif; + font-size: 13px; + background-color: #333; +} + +a:link { + color: #000; + text-decoration: none; +} + +h1 { + font-size: 70px; +} + +span.pinkHighlight { + background-color: #FF0088; +} + +p.empty { + font-size: 60px; + background-color: #CCC; +} + +p.other { + font-size: 40px; +} + +span.fade { + color: #666; +} + +span.site-mike { + background-color: green; +} + +span.site-twitter { + background-color: blue; +} \ No newline at end of file
zeroLaming/zerolaming.github.com
8e35961f68a11673a38bff8342b58a731f58d1a1
Initial
diff --git a/index.html b/index.html new file mode 100644 index 0000000..d4b1f4a --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ +<html> +<head> + <title>Mike Laming's Github</title> +</head> + +<body> +Initial +</body> +</html>
jakobmattsson/onDomReady
e54f5ae23e70c5e39502e072774430baceb7cd95
Refactored the code a bit
diff --git a/ondomready.js b/ondomready.js index 7317dc7..afada42 100644 --- a/ondomready.js +++ b/ondomready.js @@ -1,100 +1,101 @@ /* onDomReady, Copyright © 2010 Jakob Mattsson This is a small implementation of an onDomReady-function, for situations when frameworks are no-no. It's loosely based on jQuery's implementation of $.ready, Copyright (c) 2010 John Resig, http://jquery.com/ */ (function() { - var isReady = false; + + var onDomReadyIdentifier = 'onDomReady'; var isBound = false; var readyList = []; + if (window[onDomReadyIdentifier] && typeof window[onDomReadyIdentifier] == 'function') { + return; + } + var whenReady = function() { - if (isReady) { - return; - } - // Make sure body exists, at least, in case IE gets a little overzealous. // This is taked directly from jQuery's implementation. if (!document.body) { return setTimeout(whenReady, 13); } - - isReady = true; - + for (var i=0; i<readyList.length; i++) { readyList[i](); } + readyList = []; }; var bindReady = function() { - if (isBound) { - return; - } - isBound = true; - - // Catch cases where onDomReady is called after the browser event has already occurred. - if (document.readyState === "complete") { - return whenReady(); - } - // Mozilla, Opera and webkit nightlies currently support this event if (document.addEventListener) { var DOMContentLoaded = function() { document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false); whenReady(); }; document.addEventListener("DOMContentLoaded", DOMContentLoaded, false); window.addEventListener("load", whenReady, false); // fallback // If IE event model is used } else if (document.attachEvent) { var onreadystatechange = function() { if (document.readyState === "complete") { document.detachEvent("onreadystatechange", onreadystatechange); whenReady(); } }; document.attachEvent("onreadystatechange", onreadystatechange); window.attachEvent("onload", whenReady); // fallback // If IE and not a frame, continually check to see if the document is ready var toplevel = false; try { toplevel = window.frameElement == null; } catch(e) {} // The DOM ready check for Internet Explorer if (document.documentElement.doScroll && toplevel) { var doScrollCheck = function() { - if (isReady) { + + // stop searching if we have no functions to call + // (or, in other words, if they have already been called) + if (readyList.length == 0) { return; } try { // If IE is used, use the trick by Diego Perini // http://javascript.nwbox.com/IEContentLoaded/ document.documentElement.doScroll("left"); } catch(e) { setTimeout(doScrollCheck, 1); return; } // and execute any waiting functions whenReady(); } doScrollCheck(); } } }; - window.onDomReady = function(callback) { - bindReady(); + window[onDomReadyIdentifier] = function(callback) { + // Push the given callback onto the list of functions to execute when ready. + // If the dom has alredy loaded, call 'whenReady' right away. + // Otherwise bind the ready-event if it hasn't been done already readyList.push(callback); - } + if (document.readyState == "complete") { + whenReady(); + } else if (!isBound) { + bindReady(); + isBound = true; + } + }; })();
jakobmattsson/onDomReady
7b4d77339588263d3a9850eae5aec9ecc12f6d36
Corrected spelling error
diff --git a/README b/README index 871fab1..8c1312f 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ A small implementation of a onDomReady-function, for situations when frameworks are no-no. -Loosly based on jQuery's implementation of $.ready +Loosely based on jQuery's implementation of $.ready
wharris/obfuscated_fizzbuzz
0479adc1d9ee210e5273c814913f1482b4e71121
Use the correct name in the comment.
diff --git a/fizzbuzz.py b/fizzbuzz.py index 7b5226b..4ff1962 100755 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,74 +1,74 @@ #!/usr/bin/env python # encoding: utf-8 -# colourwords.py - play fizzbuzz. +# fizzbuzz.py - play fizzbuzz. # Copyright (C) 2008 Will Harris # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. debug=False def deb(s): if debug: print s def run(program, stack): deb(" %r" % stack) pc = 0 while pc < len(program): ch = program[pc] pc += 1 if ch == '%': y, x = stack.pop(), stack.pop() stack.append(x%y) elif ch in '0123456789': stack.append(ord(ch) - ord('0')) elif ch in 'abcdef': stack.append(ord(ch) - ord('a') + 10) elif ch == "<": stack.append(stack.pop() << stack.pop()) elif ch == '=': stack.append(stack.pop() == stack.pop()) elif ch == 'P': print ("%s" % stack.pop()), elif ch == 'C': stack.append(chr(stack.pop())) elif ch == '+': stack.append(stack.pop() + stack.pop()) elif ch == '?': deb(" ----") t, f, c = stack.pop(), stack.pop(), stack.pop() deb(" %(t)r if %(c)r else %(f)s" % locals()) stack.append(t if c else f) elif ch == 'D': stack.append(stack[-1]) elif ch == 'S': x, y = stack.pop(), stack.pop() stack.append(x) stack.append(y) elif ch == '!': i = stack.pop() c = stack.pop() if c: pc = i else: continue deb("%s %r" % (ch, stack)) return stack program = ( "1DDf%0=SD3%0=SD5%0=S47<a+C47<a+C+47<5+C+46<2+C+?47<a+C47<a+C+46<9+C+46<6+C+?" "47<a+C47<a+C+47<5+C+46<2+C+47<a+C+47<a+C+46<9+C+46<6+C+?P1+D46<4+=10==1!") run(program, [])
wharris/obfuscated_fizzbuzz
1212fffb4308a956253d00681834fbde2e8be84b
Specifiy encodeing.
diff --git a/fizzbuzz.py b/fizzbuzz.py index 7d74b3e..7b5226b 100755 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,73 +1,74 @@ #!/usr/bin/env python +# encoding: utf-8 # colourwords.py - play fizzbuzz. # Copyright (C) 2008 Will Harris # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. debug=False def deb(s): if debug: print s def run(program, stack): deb(" %r" % stack) pc = 0 while pc < len(program): ch = program[pc] pc += 1 if ch == '%': y, x = stack.pop(), stack.pop() stack.append(x%y) elif ch in '0123456789': stack.append(ord(ch) - ord('0')) elif ch in 'abcdef': stack.append(ord(ch) - ord('a') + 10) elif ch == "<": stack.append(stack.pop() << stack.pop()) elif ch == '=': stack.append(stack.pop() == stack.pop()) elif ch == 'P': print ("%s" % stack.pop()), elif ch == 'C': stack.append(chr(stack.pop())) elif ch == '+': stack.append(stack.pop() + stack.pop()) elif ch == '?': deb(" ----") t, f, c = stack.pop(), stack.pop(), stack.pop() deb(" %(t)r if %(c)r else %(f)s" % locals()) stack.append(t if c else f) elif ch == 'D': stack.append(stack[-1]) elif ch == 'S': x, y = stack.pop(), stack.pop() stack.append(x) stack.append(y) elif ch == '!': i = stack.pop() c = stack.pop() if c: pc = i else: continue deb("%s %r" % (ch, stack)) return stack program = ( "1DDf%0=SD3%0=SD5%0=S47<a+C47<a+C+47<5+C+46<2+C+?47<a+C47<a+C+46<9+C+46<6+C+?" "47<a+C47<a+C+47<5+C+46<2+C+47<a+C+47<a+C+46<9+C+46<6+C+?P1+D46<4+=10==1!") run(program, [])
wharris/obfuscated_fizzbuzz
dcf1fc6ebe5aa25e4e1add4cd1e521bc513a19cf
Licence under GPLv2.
diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/fizzbuzz.py b/fizzbuzz.py index a4faebc..7d74b3e 100755 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,55 +1,73 @@ #!/usr/bin/env python + +# colourwords.py - play fizzbuzz. +# Copyright (C) 2008 Will Harris +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + debug=False def deb(s): if debug: print s def run(program, stack): deb(" %r" % stack) pc = 0 while pc < len(program): ch = program[pc] pc += 1 if ch == '%': y, x = stack.pop(), stack.pop() stack.append(x%y) elif ch in '0123456789': stack.append(ord(ch) - ord('0')) elif ch in 'abcdef': stack.append(ord(ch) - ord('a') + 10) elif ch == "<": stack.append(stack.pop() << stack.pop()) elif ch == '=': stack.append(stack.pop() == stack.pop()) elif ch == 'P': print ("%s" % stack.pop()), elif ch == 'C': stack.append(chr(stack.pop())) elif ch == '+': stack.append(stack.pop() + stack.pop()) elif ch == '?': deb(" ----") t, f, c = stack.pop(), stack.pop(), stack.pop() deb(" %(t)r if %(c)r else %(f)s" % locals()) stack.append(t if c else f) elif ch == 'D': stack.append(stack[-1]) elif ch == 'S': x, y = stack.pop(), stack.pop() stack.append(x) stack.append(y) elif ch == '!': i = stack.pop() c = stack.pop() if c: pc = i else: continue deb("%s %r" % (ch, stack)) return stack program = ( "1DDf%0=SD3%0=SD5%0=S47<a+C47<a+C+47<5+C+46<2+C+?47<a+C47<a+C+46<9+C+46<6+C+?" "47<a+C47<a+C+47<5+C+46<2+C+47<a+C+47<a+C+46<9+C+46<6+C+?P1+D46<4+=10==1!") run(program, [])
wharris/obfuscated_fizzbuzz
a0a15cca5ed29a786f8f04ae40937e8219608982
Initial revision.
diff --git a/fizzbuzz.py b/fizzbuzz.py new file mode 100755 index 0000000..a4faebc --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +debug=False +def deb(s): + if debug: + print s + +def run(program, stack): + deb(" %r" % stack) + pc = 0 + while pc < len(program): + ch = program[pc] + pc += 1 + if ch == '%': + y, x = stack.pop(), stack.pop() + stack.append(x%y) + elif ch in '0123456789': + stack.append(ord(ch) - ord('0')) + elif ch in 'abcdef': + stack.append(ord(ch) - ord('a') + 10) + elif ch == "<": + stack.append(stack.pop() << stack.pop()) + elif ch == '=': + stack.append(stack.pop() == stack.pop()) + elif ch == 'P': + print ("%s" % stack.pop()), + elif ch == 'C': + stack.append(chr(stack.pop())) + elif ch == '+': + stack.append(stack.pop() + stack.pop()) + elif ch == '?': + deb(" ----") + t, f, c = stack.pop(), stack.pop(), stack.pop() + deb(" %(t)r if %(c)r else %(f)s" % locals()) + stack.append(t if c else f) + elif ch == 'D': + stack.append(stack[-1]) + elif ch == 'S': + x, y = stack.pop(), stack.pop() + stack.append(x) + stack.append(y) + elif ch == '!': + i = stack.pop() + c = stack.pop() + if c: + pc = i + else: + continue + deb("%s %r" % (ch, stack)) + return stack + +program = ( +"1DDf%0=SD3%0=SD5%0=S47<a+C47<a+C+47<5+C+46<2+C+?47<a+C47<a+C+46<9+C+46<6+C+?" +"47<a+C47<a+C+47<5+C+46<2+C+47<a+C+47<a+C+46<9+C+46<6+C+?P1+D46<4+=10==1!") + +run(program, [])
trustthevote/drupal2wordpress
5df451aa5bea9874e7073772c749116f301adb27
initial checkin of Mike Smullin's script
diff --git a/drupal2wordpress.sql b/drupal2wordpress.sql new file mode 100644 index 0000000..3b717a7 --- /dev/null +++ b/drupal2wordpress.sql @@ -0,0 +1,80 @@ +# Changelog + +# 02.06.2009 - Updated by Mike Smullin http://www.mikesmullin.com/development/migrate-convert-import-drupal-5-to-wordpress-27/ +# 05.15.2007 - Updated by D’Arcy Norman http://www.darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wordpress-2/ +# 05.19.2006 - Created by Dave Dash http://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress/ + +# This assumes that both wordpress and drupal are in separate databases. The wordpress database is called "wordpress" and the Drupal database is called "drupal" + +# first, nuke previous content in wordpress database +TRUNCATE TABLE wordpress.wp_comments; +TRUNCATE TABLE wordpress.wp_links; +TRUNCATE TABLE wordpress.wp_postmeta; +TRUNCATE TABLE wordpress.wp_posts; +TRUNCATE TABLE wordpress.wp_term_relationships; +TRUNCATE TABLE wordpress.wp_term_taxonomy; +TRUNCATE TABLE wordpress.wp_terms; + +# categories +INSERT INTO wordpress.wp_terms (term_id, `name`, slug, term_group) +SELECT + d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0 +FROM drupal.term_data d +INNER JOIN drupal.term_hierarchy h + USING(tid) +; + +INSERT INTO wordpress.wp_term_taxonomy (term_id, taxonomy, description, parent) +SELECT + d.tid `term_id`, + 'category' `taxonomy`, + d.description `description`, + h.parent `parent` +FROM drupal.term_data d +INNER JOIN drupal.term_hierarchy h + USING(tid) +; + +# posts; keeping private posts hidden +INSERT INTO wordpress.wp_posts (id, post_date, post_content, post_title, post_excerpt, post_name, post_modified, post_type, `post_status`) +SELECT DISTINCT + n.nid `id`, + FROM_UNIXTIME(n.created) `post_date`, + r.body `post_content`, + n.title `post_title`, + r.teaser `post_excerpt`, + IF(SUBSTR(a.dst, 11, 1) = '/', SUBSTR(a.dst, 12), a.dst) `post_name`, + FROM_UNIXTIME(n.changed) `post_modified`, + n.type `post_type`, + IF(n.status = 1, 'publish', 'private') `post_status` +FROM drupal.node n +INNER JOIN drupal.node_revisions r + USING(vid) +LEFT OUTER JOIN drupal.url_alias a + ON a.src = CONCAT('node/', n.nid) +WHERE n.type IN ('post', 'page') +; + +# post -> category relationships +INSERT INTO wordpress.wp_term_relationships (object_id, term_taxonomy_id) +SELECT nid, tid FROM drupal.term_node; + +# category count updating +UPDATE wp_term_taxonomy tt +SET `count` = ( + SELECT COUNT(tr.object_id) + FROM wp_term_relationships tr + WHERE tr.term_taxonomy_id = tt.term_taxonomy_id +); + +# comments; keeping unapproved comments hidden +INSERT INTO wordpress.wp_comments (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved) +SELECT nid, FROM_UNIXTIME(timestamp), comment, thread, name, mail, homepage, status FROM drupal.comments; + +# update comments count on wp_posts table +UPDATE `wp_posts` SET `comment_count` = (SELECT COUNT(`comment_post_id`) FROM `wp_comments` WHERE `wp_posts`.`id` = `wp_comments`.`comment_post_id`); + +# fix breaks in post content +UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '<!--break-->', '<!--more-->'); +# fix images in post content +UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '"/files/', '"/wp-content/uploads/');
benb/transposon-rake
fb220e9b7bf577a3143319f778e336b29c46e17e
Made min_mapped_{length|depth} configurable
diff --git a/rakefile.transposon b/rakefile.transposon index feb8986..7c6c0c9 100644 --- a/rakefile.transposon +++ b/rakefile.transposon @@ -1,495 +1,496 @@ require 'rubygems' require 'ostruct' require 'fastq' require 'md5' allruns = ["3293_2","3293_3","3293_5","3293_6"] #locations of important binaries ssaha_pileup = "./ssaha_pileup" ssaha2='~hp3/sw/arch/x86_64-linux/bin/ssaha2-2.4' #regex of the tag we want to pull out tagregex = /^[NG][GN][TN][TN][AN][AN]/ task :process_fastq => allruns.map{|i| i+"_1.fastqsel"} + allruns.map{|i| i + "_2.fastqsel"} +min_mapped_length = 50 +min_mapped_depth = 5.0 class PairFastq def initialize(r1,r2) @r1=r1 @r2=r2 end def next [@r1.next,@r2.next] end def has_next? @r1.has_next? && @r2.has_next? end def each while self.has_next? yield self.next end end end #Clip the reads: rule(/_1.fastqde/ => [proc {|task_name| task_name.sub(/de$/,'') }, proc {|task_name| task_name.sub(/_1.fastqde$/,'_2.fastq') }]) do |t| #This code is SO SLOW you should probably use something else puts(t.prerequisites[0]) r1= Fastq.new(t.prerequisites[0]) r2 = Fastq.new(t.prerequisites[1]) o1=File.new(t.prerequisites[0]+"dedupe.tmp","w") o2=File.new(t.prerequisites[1]+"dedupe.tmp","w") pair = PairFastq.new(r1,r2) seen={} pair.each do |rp| rphash = rp[0].seq + "," + rp[1].seq if seen[rphash] == nil seen[rphash]=1 o1.puts(rp[0].to_s) o2.puts(rp[1].to_s) end end mv(t.prerequisites[0]+"dedupe.tmp",t.prerequisites[0]+"de") mv(t.prerequisites[1]+"dedupe.tmp",t.prerequisites[1]+"de") end rule '.fastqclip' => '.fastqde' do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") if (t.name =~ /_1.fastq/) #So, please trim all read 1s that have AGATCGGAAGAG - i.e. at the point #that the sequence becomes this, remove all the bases that follow. seq = /AGATCGGAAGAG.*/ else #For these sequences, read 2 will need to be trimmed back too. This will #start with mouse sequence, and will then run into the transposon #sequence: TTAACCCTAGAAAG . . . . seq = /TTAACCCTAGAAAG.*/ end f.each{|r| if (r.seq =~ seq) clip = seq.match(r.seq).begin(0) if clip > 0 out.puts(r.name.chomp + "\n" + r.seq[0..clip] + "\n+\n" + r.qual[0..clip]) else out.puts(r.name.chomp + "\n" + "NNNN" + "\n+\n" + "!!!!") end else out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) end } mv(t.name+".tmp",t.name) end def fastqout(out,record) out.puts(record.name.chomp + "\n" + record.seq + "\n+\n" + record.qual) end #Select the sequences that start with the tag rule(/_1.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') } ]) do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f.each{|r| out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) if (r.seq =~ tagregex ) if r.seq=~ tagregex } mv(t.name+".tmp",t.name) end #remove sequences in _2 that aren't in _1 rule(/_2.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') }, proc {|task_name| task_name.sub(/_2.fastqsel$/,'_1.fastqsel') } ]) do |t| f1 = Fastq.new(t.prerequisites[1]) f2 = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f1.each{|r1| ok = false while !ok r2 = f2.next if r1.name.sub(/\/1$/,"/2")==r2.name fastqout(out,r2) ok=true end end } mv(t.name+".tmp",t.name) end #produce the alignment rule(/.ssaha.*/ => [proc{|t| t.sub(/.ssaha/,'_1.fastqsel')},proc{|t| t.sub(/.ssaha/,'_2.fastqsel')}]) do |t| puts t.name command = ssaha2 + ' -rtype solexa -score 20 -kmer 13 -skip 2 -output cigar -pair 2,500 -outfile ' + t.name+'.abnormal NCBI_M37.fa ' + t.prerequisites[0] + " " + t.prerequisites[0].gsub(/_1.fastq/,"_2.fastq") +" > " + t.name + ".tmp" puts command sh command mv(t.name+".tmp",t.name) end class HashDir def hashpath(file) hashdir(file) + '/' + file end def hashdir(file) hashtag = file.sub(/_[12]\./,".").sub(/\..*_/,"") return MD5.new(hashtag).hexdigest[0..1] end end hasher = HashDir.new task :allssaha => Dir.glob("*_1.fastq").map{|n| n.sub(/._1.fastq$/,'.ssaha')} task :split => "split.stamp" file "split.stamp" do |t| Dir.glob("*.fastqsel").each do |f| puts "split -l 400000 " + f + " " + f +"_" end Dir.glob("*.fastqsel_[a-z][a-z]").each do |f| hashdir = hasher.hashdir(f) sh "mkdir -p #{hashdir}" mv f, hashdir+"/"+f end sh "touch split.stamp" end task :merge => "merge.task" file "merge.task" do |t| files = Dir.glob("*/*.ssaha_[a-z][a-z]").sort_by{|a| a.sub(/.*\//,"")} files.map{|f| f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"")}.uniq.each do |f| sh "rm -f " + f end files.each do |f| sh "cat " + f + " >> " + f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"") end sh "touch merge.task" end require "tempfile" class File def each(count) while (!eof) c=count x=[] while(c>0 && !eof) x.push(readline) c-=1 end yield x end end end class Rake::FileTask def tmpname name+".tmp" end def tmpout File.new(tmpname,"w") end def fintmp mv name+".tmp", name end end rule ".cigar" => ".ssaha" do |t| sh " grep \/1 #{t.prerequisites[0]} > #{t.name}" end rule ".pileup" => [proc {|n| n.sub(/.pileup/,"_1.fastqsel")},".cigar"] do |t| #script = Tempfile.new("script") #script.chmod(0700) #script.puts("./ssaha_pileup -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}") #script.close #sh "msub 60000 -o pileup.out.%J -q hugemem -K " + script.path #script.delete sh ssaha_pileup + " -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}" t.fintmp end task :allpileup=>allruns.map{|i| i+".pileup"} task :allfastq=>allruns.map{|i| i+".fastqgood"} task :allsum=>allruns.map{|i| i+".summary-ann"} class PileupSum @chr @pos @startpos @cov @out @started def set_out(output) @out=output end def initialize @chr="" @pos=0 @startpos=0 @cov=[] @started=false end def consume(line) spl = line.split newchr = spl[1] newpos = spl[2].to_i newcov = spl[3].to_i if (newpos-@pos > 1 || @chr!=newchr) flush(newcov,newpos,newchr) else @started=true @cov.push(newcov) @pos=newpos @chr=newchr end end def flush(newcov,newpos,newchr) if (@started) fin end @cov=[newcov] @startpos=newpos @pos=newpos @chr=newchr end def fin @out.puts @chr + " " + @startpos.to_s + " " + (@pos + 1 - @startpos).to_s + " " + mean(@cov).to_s end def mean(cov) i=0.0 cov.each{|a| i+=a} i/cov.length end end rule ".summary" => [".pileup"] do |t| summ = PileupSum.new summ.set_out(t.tmpout) File.open(t.prerequisites[0]).each_line{|line| next unless line[0..3]=="cons" summ.consume(line) } summ.fin t.fintmp end require 'ensembl' include Ensembl::Core class Annotate def initialize DBConnection.connect('mus_musculus',54) end def annotate(string) #1 4199590 23 1.0 spl = string.split buffer = 100000 out = "" slice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - buffer ,spl[2].to_i + spl[1].to_i + buffer ,1) nearslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - 1000 ,spl[2].to_i + spl[1].to_i + 1000 ,1) realslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i ,spl[2].to_i + spl[1].to_i,1) slice.genes.find_all{|g| g.slice.overlaps?(realslice)}.each do |gene| out = out + "g:"+gene.stable_id+"," gene.transcripts.find_all{|t| t.slice.overlaps?(realslice)}.each do |t| out=out+"t:"+t.stable_id+"_"+t.strand.to_s + "," t.exons.find_all{|e| e.slice.overlaps?(realslice)}.each do |e| out = out + "e:"+e.stable_id+"," end t.introns.find_all{|i| i.slice.overlaps?(realslice)}.each do |i| out = out + "i_" #if t.strand==1 # out=out+i.previous_exon.end_phase.to_s #else # out=out+i.previous_exon.end_phase.to_s #end #with my patches out=out+i.previous_exon.end_phase.to_s out = out +"," end end end slice.genes.find_all{|g| (g.slice.overlaps?(nearslice) && !g.slice.overlaps?(realslice))}.each do |gene| out = out + "n:"+gene.stable_id+"," end return out end end rule ".summary-ann" => [".summary-ann-raw",".pileup_dir"] do |t| output = t.tmpout - threshold = 5.0 dirF=Hash.new{|h,k| h[k]=Hash.new(0)} dirR=Hash.new{|h,k| h[k]=Hash.new(0)} File.open(t.prerequisites[1]).each_line{|l| s = l.split dirF[s[0]][s[1].to_i]=s[2].to_i dirR[s[0]][s[1].to_i]=s[3].to_i } File.open(t.prerequisites[0]).each_line.find_all{|l| s = l.split - (s[2].to_i > 50 && s[3].to_f > threshold ) + (s[2].to_i > min_mapped_length && s[3].to_f > min_mapped_depth ) }.each{|line| s = line.split f = dirF[s[0]] r = dirR[s[0]] fTot = 0.0 rTot = 0.0 (s[1].to_i .. s[1].to_i + s[2].to_i).each do |i| fTot+=f[i] rTot+=r[i] end rTot/=s[2].to_f fTot/=s[2].to_f output.puts(line.chomp + " " + fTot.to_s + " " + rTot.to_s) } t.fintmp end ann = Annotate.new rule ".summary-ann-raw" => ".summary" do |t| output = t.tmpout File.open(t.prerequisites[0]).each_line{|line| output.puts(line.chomp + " " + ann.annotate(line)) } t.fintmp end rule ".summary-fin" => ".summary-ann" do |t| #want seqs with correct strand output = t.tmpout File.open(t.prerequisites[0]).each_line.find_all{ |line| s = line.split if s.length > 6 && !(s[4]=~/t:/).nil? # then gene hit if s[5].to_f < 0.001 || s[6].to_f < 0.001 if s[5].to_f > 0.001 #assume forward if (s[4]=~/_1/).nil? false else true end else #negative if (s[4]=~/_-1/).nil? false else true end end else false end else true end }.each{|line| output.puts(line) } t.fintmp end rule ".pileup_dir" => ".cigargood" do |t| require 'ostruct' #cigar::50 IL13_2618:1:1:6:1924/1 3 54 + 4 116467134 116467185 + 52 M 52 dir={} dir["+"]=Hash.new{|h,k| h[k]=Hash.new(0)} dir["-"]=Hash.new{|h,k| h[k]=Hash.new(0)} vals=[] File.open(t.prerequisites[0]).each_line do |l| s = l.split #ignores indels but should be okay start = s[6].to_i stop = s[7].to_i chr = s[5] d = dir[s[4]] (start..stop).each{|i| d[chr][i]=d[chr][i]+1 } end out = t.tmpout (dir["+"].keys + dir["-"].keys).sort.uniq.each do |chr| (dir["+"][chr].keys + dir["-"][chr].keys).sort.uniq.each do |pos| out.puts chr + " " + pos.to_s + " " + dir["+"][chr][pos].to_s + " " + dir["-"][chr][pos].to_s + "\n" end end t.fintmp end rule ".hotspot-csv" => ".summary-fin" do |t| # 1 15816457 53 35.3396226415094 g:ENSMUSG00000025925,t:ENSMUST00000093770_1,t:ENSMUST00000027057_1, 35.3396226415094 0.0 out = t.tmpout genehash = Hash.new{|h,k| h[k]=[]} File.open(t.prerequisites[0]).each_line.find_all{|l| l=~/g:/}.each do |l| s = l.split genes = s[4].split(",").find_all{|g| g[0..1]=="g:"} genes.each{|g| genehash[g].push(s[0]+","+s[1]+","+s[2]+","+s[3]) } end genehash.each.sort_by{|k,v| v.length}.each{|k,v| out.puts(v.length.to_s + "," + k + "," + v.join(",")) } t.fintmp end task :allhotspot => allruns.map{|l| l+".hotspot-csv"} file "allhotspots.csv" => :allhotspot do |t| out = t.tmpout allruns.map{|l| l+".hotspot-csv"}.each{|file| out.puts(file.gsub(".hotspot-csv","")) File.open(file).each_line{|l| out.puts(l)} } t.fintmp end rule ".GGCTAA" => ".fastq" do |t| if t.prerequisites[0]=~/_[0-9]_2.fastq/ leftfile= t.name.gsub(/_2\./,'.') sh "rake " + leftfile sh "fastqpair " + leftfile + " " +t.prerequisites[0] + " > " + t.tmpname t.fintmp else sh "grep ^GGCTAG -A 2 -B 1 " + t.prerequisites[0] + " | grep -v -- ^--$ > " + t.tmpname t.fintmp end end rule ".GGCTAA-out" => ".GGCTAA" do |t| pair = t.prerequisites[0].gsub(/\./,'_2.') sh "rake " + pair sh "/nfs/team117/hp3/sw/arch/ia64-linux/bin/ssaha2-2.3.1 -rtype solexa -kmer 13 -skip 2 -score 20 -output cigar -outfile " + t.name + "abnormal -diff 0 -pair 2,500 NCBI_M37.fa " + t.prerequisites[0] + " " + pair + " > " + t.tmpname t.fintmp end task :normalGGCTAA do |t| allruns.each{|i| mv i+".GGCTAA", i+".fastq" if File.exists?(i) } Dir.glob("*.GGCTAA-*").each{|i| mv i, i.gsub("GGCTAA-","") } Dir.glob("*.GGCTAA").each{|i| mv i, i.gsub("GGCTAA","fastq") } end
benb/transposon-rake
41caebb0dc4aa7c7abff30c9ff632cada1fa650b
Bugfix
diff --git a/rakefile.transposon b/rakefile.transposon index 6b1421a..feb8986 100644 --- a/rakefile.transposon +++ b/rakefile.transposon @@ -1,497 +1,495 @@ require 'rubygems' -require 'amatch' require 'ostruct' require 'fastq' require 'md5' -include Amatch allruns = ["3293_2","3293_3","3293_5","3293_6"] #locations of important binaries ssaha_pileup = "./ssaha_pileup" ssaha2='~hp3/sw/arch/x86_64-linux/bin/ssaha2-2.4' #regex of the tag we want to pull out tagregex = /^[NG][GN][TN][TN][AN][AN]/ task :process_fastq => allruns.map{|i| i+"_1.fastqsel"} + allruns.map{|i| i + "_2.fastqsel"} class PairFastq def initialize(r1,r2) @r1=r1 @r2=r2 end def next [@r1.next,@r2.next] end def has_next? @r1.has_next? && @r2.has_next? end def each while self.has_next? yield self.next end end end #Clip the reads: rule(/_1.fastqde/ => [proc {|task_name| task_name.sub(/de$/,'') }, proc {|task_name| task_name.sub(/_1.fastqde$/,'_2.fastq') }]) do |t| #This code is SO SLOW you should probably use something else puts(t.prerequisites[0]) r1= Fastq.new(t.prerequisites[0]) r2 = Fastq.new(t.prerequisites[1]) o1=File.new(t.prerequisites[0]+"dedupe.tmp","w") o2=File.new(t.prerequisites[1]+"dedupe.tmp","w") pair = PairFastq.new(r1,r2) seen={} pair.each do |rp| rphash = rp[0].seq + "," + rp[1].seq if seen[rphash] == nil seen[rphash]=1 o1.puts(rp[0].to_s) o2.puts(rp[1].to_s) end end - mv(t.prerequisites[0]+"dedupe.tmp",t.prerequisites[0]+"dedupe") - mv(t.prerequisites[1]+"dedupe.tmp",t.prerequisites[1]+"dedupe") + mv(t.prerequisites[0]+"dedupe.tmp",t.prerequisites[0]+"de") + mv(t.prerequisites[1]+"dedupe.tmp",t.prerequisites[1]+"de") end rule '.fastqclip' => '.fastqde' do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") if (t.name =~ /_1.fastq/) #So, please trim all read 1s that have AGATCGGAAGAG - i.e. at the point #that the sequence becomes this, remove all the bases that follow. seq = /AGATCGGAAGAG.*/ else #For these sequences, read 2 will need to be trimmed back too. This will #start with mouse sequence, and will then run into the transposon #sequence: TTAACCCTAGAAAG . . . . seq = /TTAACCCTAGAAAG.*/ end f.each{|r| if (r.seq =~ seq) clip = seq.match(r.seq).begin(0) if clip > 0 out.puts(r.name.chomp + "\n" + r.seq[0..clip] + "\n+\n" + r.qual[0..clip]) else out.puts(r.name.chomp + "\n" + "NNNN" + "\n+\n" + "!!!!") end else out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) end } mv(t.name+".tmp",t.name) end def fastqout(out,record) out.puts(record.name.chomp + "\n" + record.seq + "\n+\n" + record.qual) end #Select the sequences that start with the tag rule(/_1.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') } ]) do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f.each{|r| out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) if (r.seq =~ tagregex ) if r.seq=~ tagregex } mv(t.name+".tmp",t.name) end #remove sequences in _2 that aren't in _1 rule(/_2.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') }, proc {|task_name| task_name.sub(/_2.fastqsel$/,'_1.fastqsel') } ]) do |t| f1 = Fastq.new(t.prerequisites[1]) f2 = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f1.each{|r1| ok = false while !ok r2 = f2.next if r1.name.sub(/\/1$/,"/2")==r2.name fastqout(out,r2) ok=true end end } mv(t.name+".tmp",t.name) end #produce the alignment rule(/.ssaha.*/ => [proc{|t| t.sub(/.ssaha/,'_1.fastqsel')},proc{|t| t.sub(/.ssaha/,'_2.fastqsel')}]) do |t| puts t.name command = ssaha2 + ' -rtype solexa -score 20 -kmer 13 -skip 2 -output cigar -pair 2,500 -outfile ' + t.name+'.abnormal NCBI_M37.fa ' + t.prerequisites[0] + " " + t.prerequisites[0].gsub(/_1.fastq/,"_2.fastq") +" > " + t.name + ".tmp" puts command sh command mv(t.name+".tmp",t.name) end class HashDir def hashpath(file) hashdir(file) + '/' + file end def hashdir(file) hashtag = file.sub(/_[12]\./,".").sub(/\..*_/,"") return MD5.new(hashtag).hexdigest[0..1] end end hasher = HashDir.new task :allssaha => Dir.glob("*_1.fastq").map{|n| n.sub(/._1.fastq$/,'.ssaha')} task :split => "split.stamp" file "split.stamp" do |t| Dir.glob("*.fastqsel").each do |f| puts "split -l 400000 " + f + " " + f +"_" end Dir.glob("*.fastqsel_[a-z][a-z]").each do |f| hashdir = hasher.hashdir(f) sh "mkdir -p #{hashdir}" mv f, hashdir+"/"+f end sh "touch split.stamp" end task :merge => "merge.task" file "merge.task" do |t| files = Dir.glob("*/*.ssaha_[a-z][a-z]").sort_by{|a| a.sub(/.*\//,"")} files.map{|f| f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"")}.uniq.each do |f| sh "rm -f " + f end files.each do |f| sh "cat " + f + " >> " + f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"") end sh "touch merge.task" end require "tempfile" class File def each(count) while (!eof) c=count x=[] while(c>0 && !eof) x.push(readline) c-=1 end yield x end end end class Rake::FileTask def tmpname name+".tmp" end def tmpout File.new(tmpname,"w") end def fintmp mv name+".tmp", name end end rule ".cigar" => ".ssaha" do |t| sh " grep \/1 #{t.prerequisites[0]} > #{t.name}" end rule ".pileup" => [proc {|n| n.sub(/.pileup/,"_1.fastqsel")},".cigar"] do |t| #script = Tempfile.new("script") #script.chmod(0700) #script.puts("./ssaha_pileup -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}") #script.close #sh "msub 60000 -o pileup.out.%J -q hugemem -K " + script.path #script.delete sh ssaha_pileup + " -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}" t.fintmp end task :allpileup=>allruns.map{|i| i+".pileup"} task :allfastq=>allruns.map{|i| i+".fastqgood"} task :allsum=>allruns.map{|i| i+".summary-ann"} class PileupSum @chr @pos @startpos @cov @out @started def set_out(output) @out=output end def initialize @chr="" @pos=0 @startpos=0 @cov=[] @started=false end def consume(line) spl = line.split newchr = spl[1] newpos = spl[2].to_i newcov = spl[3].to_i if (newpos-@pos > 1 || @chr!=newchr) flush(newcov,newpos,newchr) else @started=true @cov.push(newcov) @pos=newpos @chr=newchr end end def flush(newcov,newpos,newchr) if (@started) fin end @cov=[newcov] @startpos=newpos @pos=newpos @chr=newchr end def fin @out.puts @chr + " " + @startpos.to_s + " " + (@pos + 1 - @startpos).to_s + " " + mean(@cov).to_s end def mean(cov) i=0.0 cov.each{|a| i+=a} i/cov.length end end rule ".summary" => [".pileup"] do |t| summ = PileupSum.new summ.set_out(t.tmpout) File.open(t.prerequisites[0]).each_line{|line| next unless line[0..3]=="cons" summ.consume(line) } summ.fin t.fintmp end require 'ensembl' include Ensembl::Core class Annotate def initialize DBConnection.connect('mus_musculus',54) end def annotate(string) #1 4199590 23 1.0 spl = string.split buffer = 100000 out = "" slice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - buffer ,spl[2].to_i + spl[1].to_i + buffer ,1) nearslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - 1000 ,spl[2].to_i + spl[1].to_i + 1000 ,1) realslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i ,spl[2].to_i + spl[1].to_i,1) slice.genes.find_all{|g| g.slice.overlaps?(realslice)}.each do |gene| out = out + "g:"+gene.stable_id+"," gene.transcripts.find_all{|t| t.slice.overlaps?(realslice)}.each do |t| out=out+"t:"+t.stable_id+"_"+t.strand.to_s + "," t.exons.find_all{|e| e.slice.overlaps?(realslice)}.each do |e| out = out + "e:"+e.stable_id+"," end t.introns.find_all{|i| i.slice.overlaps?(realslice)}.each do |i| out = out + "i_" #if t.strand==1 # out=out+i.previous_exon.end_phase.to_s #else # out=out+i.previous_exon.end_phase.to_s #end #with my patches out=out+i.previous_exon.end_phase.to_s out = out +"," end end end slice.genes.find_all{|g| (g.slice.overlaps?(nearslice) && !g.slice.overlaps?(realslice))}.each do |gene| out = out + "n:"+gene.stable_id+"," end return out end end rule ".summary-ann" => [".summary-ann-raw",".pileup_dir"] do |t| output = t.tmpout threshold = 5.0 dirF=Hash.new{|h,k| h[k]=Hash.new(0)} dirR=Hash.new{|h,k| h[k]=Hash.new(0)} File.open(t.prerequisites[1]).each_line{|l| s = l.split dirF[s[0]][s[1].to_i]=s[2].to_i dirR[s[0]][s[1].to_i]=s[3].to_i } File.open(t.prerequisites[0]).each_line.find_all{|l| s = l.split (s[2].to_i > 50 && s[3].to_f > threshold ) }.each{|line| s = line.split f = dirF[s[0]] r = dirR[s[0]] fTot = 0.0 rTot = 0.0 (s[1].to_i .. s[1].to_i + s[2].to_i).each do |i| fTot+=f[i] rTot+=r[i] end rTot/=s[2].to_f fTot/=s[2].to_f output.puts(line.chomp + " " + fTot.to_s + " " + rTot.to_s) } t.fintmp end ann = Annotate.new rule ".summary-ann-raw" => ".summary" do |t| output = t.tmpout File.open(t.prerequisites[0]).each_line{|line| output.puts(line.chomp + " " + ann.annotate(line)) } t.fintmp end rule ".summary-fin" => ".summary-ann" do |t| #want seqs with correct strand output = t.tmpout File.open(t.prerequisites[0]).each_line.find_all{ |line| s = line.split if s.length > 6 && !(s[4]=~/t:/).nil? # then gene hit if s[5].to_f < 0.001 || s[6].to_f < 0.001 if s[5].to_f > 0.001 #assume forward if (s[4]=~/_1/).nil? false else true end else #negative if (s[4]=~/_-1/).nil? false else true end end else false end else true end }.each{|line| output.puts(line) } t.fintmp end rule ".pileup_dir" => ".cigargood" do |t| require 'ostruct' #cigar::50 IL13_2618:1:1:6:1924/1 3 54 + 4 116467134 116467185 + 52 M 52 dir={} dir["+"]=Hash.new{|h,k| h[k]=Hash.new(0)} dir["-"]=Hash.new{|h,k| h[k]=Hash.new(0)} vals=[] File.open(t.prerequisites[0]).each_line do |l| s = l.split #ignores indels but should be okay start = s[6].to_i stop = s[7].to_i chr = s[5] d = dir[s[4]] (start..stop).each{|i| d[chr][i]=d[chr][i]+1 } end out = t.tmpout (dir["+"].keys + dir["-"].keys).sort.uniq.each do |chr| (dir["+"][chr].keys + dir["-"][chr].keys).sort.uniq.each do |pos| out.puts chr + " " + pos.to_s + " " + dir["+"][chr][pos].to_s + " " + dir["-"][chr][pos].to_s + "\n" end end t.fintmp end rule ".hotspot-csv" => ".summary-fin" do |t| # 1 15816457 53 35.3396226415094 g:ENSMUSG00000025925,t:ENSMUST00000093770_1,t:ENSMUST00000027057_1, 35.3396226415094 0.0 out = t.tmpout genehash = Hash.new{|h,k| h[k]=[]} File.open(t.prerequisites[0]).each_line.find_all{|l| l=~/g:/}.each do |l| s = l.split genes = s[4].split(",").find_all{|g| g[0..1]=="g:"} genes.each{|g| genehash[g].push(s[0]+","+s[1]+","+s[2]+","+s[3]) } end genehash.each.sort_by{|k,v| v.length}.each{|k,v| out.puts(v.length.to_s + "," + k + "," + v.join(",")) } t.fintmp end task :allhotspot => allruns.map{|l| l+".hotspot-csv"} file "allhotspots.csv" => :allhotspot do |t| out = t.tmpout allruns.map{|l| l+".hotspot-csv"}.each{|file| out.puts(file.gsub(".hotspot-csv","")) File.open(file).each_line{|l| out.puts(l)} } t.fintmp end rule ".GGCTAA" => ".fastq" do |t| if t.prerequisites[0]=~/_[0-9]_2.fastq/ leftfile= t.name.gsub(/_2\./,'.') sh "rake " + leftfile sh "fastqpair " + leftfile + " " +t.prerequisites[0] + " > " + t.tmpname t.fintmp else sh "grep ^GGCTAG -A 2 -B 1 " + t.prerequisites[0] + " | grep -v -- ^--$ > " + t.tmpname t.fintmp end end rule ".GGCTAA-out" => ".GGCTAA" do |t| pair = t.prerequisites[0].gsub(/\./,'_2.') sh "rake " + pair sh "/nfs/team117/hp3/sw/arch/ia64-linux/bin/ssaha2-2.3.1 -rtype solexa -kmer 13 -skip 2 -score 20 -output cigar -outfile " + t.name + "abnormal -diff 0 -pair 2,500 NCBI_M37.fa " + t.prerequisites[0] + " " + pair + " > " + t.tmpname t.fintmp end task :normalGGCTAA do |t| allruns.each{|i| mv i+".GGCTAA", i+".fastq" if File.exists?(i) } Dir.glob("*.GGCTAA-*").each{|i| mv i, i.gsub("GGCTAA-","") } Dir.glob("*.GGCTAA").each{|i| mv i, i.gsub("GGCTAA","fastq") } end
benb/transposon-rake
fcff1041458ea1240fecd7bb56aa2572e0deae09
Use FastqRecord to_s method
diff --git a/rakefile.transposon b/rakefile.transposon index 64b8ccf..6b1421a 100644 --- a/rakefile.transposon +++ b/rakefile.transposon @@ -1,497 +1,497 @@ require 'rubygems' require 'amatch' require 'ostruct' require 'fastq' require 'md5' include Amatch allruns = ["3293_2","3293_3","3293_5","3293_6"] #locations of important binaries ssaha_pileup = "./ssaha_pileup" ssaha2='~hp3/sw/arch/x86_64-linux/bin/ssaha2-2.4' #regex of the tag we want to pull out tagregex = /^[NG][GN][TN][TN][AN][AN]/ task :process_fastq => allruns.map{|i| i+"_1.fastqsel"} + allruns.map{|i| i + "_2.fastqsel"} class PairFastq def initialize(r1,r2) @r1=r1 @r2=r2 end def next [@r1.next,@r2.next] end def has_next? @r1.has_next? && @r2.has_next? end def each while self.has_next? yield self.next end end end #Clip the reads: rule(/_1.fastqde/ => [proc {|task_name| task_name.sub(/de$/,'') }, proc {|task_name| task_name.sub(/_1.fastqde$/,'_2.fastq') }]) do |t| #This code is SO SLOW you should probably use something else puts(t.prerequisites[0]) r1= Fastq.new(t.prerequisites[0]) r2 = Fastq.new(t.prerequisites[1]) o1=File.new(t.prerequisites[0]+"dedupe.tmp","w") o2=File.new(t.prerequisites[1]+"dedupe.tmp","w") pair = PairFastq.new(r1,r2) seen={} pair.each do |rp| rphash = rp[0].seq + "," + rp[1].seq if seen[rphash] == nil seen[rphash]=1 - o1.puts(Fastq.tofastqstr(rp[0])) - o2.puts(Fastq.tofastqstr(rp[1])) + o1.puts(rp[0].to_s) + o2.puts(rp[1].to_s) end end mv(t.prerequisites[0]+"dedupe.tmp",t.prerequisites[0]+"dedupe") mv(t.prerequisites[1]+"dedupe.tmp",t.prerequisites[1]+"dedupe") end rule '.fastqclip' => '.fastqde' do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") if (t.name =~ /_1.fastq/) #So, please trim all read 1s that have AGATCGGAAGAG - i.e. at the point #that the sequence becomes this, remove all the bases that follow. seq = /AGATCGGAAGAG.*/ else #For these sequences, read 2 will need to be trimmed back too. This will #start with mouse sequence, and will then run into the transposon #sequence: TTAACCCTAGAAAG . . . . seq = /TTAACCCTAGAAAG.*/ end f.each{|r| if (r.seq =~ seq) clip = seq.match(r.seq).begin(0) if clip > 0 out.puts(r.name.chomp + "\n" + r.seq[0..clip] + "\n+\n" + r.qual[0..clip]) else out.puts(r.name.chomp + "\n" + "NNNN" + "\n+\n" + "!!!!") end else out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) end } mv(t.name+".tmp",t.name) end def fastqout(out,record) out.puts(record.name.chomp + "\n" + record.seq + "\n+\n" + record.qual) end #Select the sequences that start with the tag rule(/_1.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') } ]) do |t| f = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f.each{|r| out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) if (r.seq =~ tagregex ) if r.seq=~ tagregex } mv(t.name+".tmp",t.name) end #remove sequences in _2 that aren't in _1 rule(/_2.fastqsel$/ => [ proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') }, proc {|task_name| task_name.sub(/_2.fastqsel$/,'_1.fastqsel') } ]) do |t| f1 = Fastq.new(t.prerequisites[1]) f2 = Fastq.new(t.prerequisites[0]) out = File.new(t.name + ".tmp","w") f1.each{|r1| ok = false while !ok r2 = f2.next if r1.name.sub(/\/1$/,"/2")==r2.name fastqout(out,r2) ok=true end end } mv(t.name+".tmp",t.name) end #produce the alignment rule(/.ssaha.*/ => [proc{|t| t.sub(/.ssaha/,'_1.fastqsel')},proc{|t| t.sub(/.ssaha/,'_2.fastqsel')}]) do |t| puts t.name command = ssaha2 + ' -rtype solexa -score 20 -kmer 13 -skip 2 -output cigar -pair 2,500 -outfile ' + t.name+'.abnormal NCBI_M37.fa ' + t.prerequisites[0] + " " + t.prerequisites[0].gsub(/_1.fastq/,"_2.fastq") +" > " + t.name + ".tmp" puts command sh command mv(t.name+".tmp",t.name) end class HashDir def hashpath(file) hashdir(file) + '/' + file end def hashdir(file) hashtag = file.sub(/_[12]\./,".").sub(/\..*_/,"") return MD5.new(hashtag).hexdigest[0..1] end end hasher = HashDir.new task :allssaha => Dir.glob("*_1.fastq").map{|n| n.sub(/._1.fastq$/,'.ssaha')} task :split => "split.stamp" file "split.stamp" do |t| Dir.glob("*.fastqsel").each do |f| puts "split -l 400000 " + f + " " + f +"_" end Dir.glob("*.fastqsel_[a-z][a-z]").each do |f| hashdir = hasher.hashdir(f) sh "mkdir -p #{hashdir}" mv f, hashdir+"/"+f end sh "touch split.stamp" end task :merge => "merge.task" file "merge.task" do |t| files = Dir.glob("*/*.ssaha_[a-z][a-z]").sort_by{|a| a.sub(/.*\//,"")} files.map{|f| f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"")}.uniq.each do |f| sh "rm -f " + f end files.each do |f| sh "cat " + f + " >> " + f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"") end sh "touch merge.task" end require "tempfile" class File def each(count) while (!eof) c=count x=[] while(c>0 && !eof) x.push(readline) c-=1 end yield x end end end class Rake::FileTask def tmpname name+".tmp" end def tmpout File.new(tmpname,"w") end def fintmp mv name+".tmp", name end end rule ".cigar" => ".ssaha" do |t| sh " grep \/1 #{t.prerequisites[0]} > #{t.name}" end rule ".pileup" => [proc {|n| n.sub(/.pileup/,"_1.fastqsel")},".cigar"] do |t| #script = Tempfile.new("script") #script.chmod(0700) #script.puts("./ssaha_pileup -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}") #script.close #sh "msub 60000 -o pileup.out.%J -q hugemem -K " + script.path #script.delete sh ssaha_pileup + " -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}" t.fintmp end task :allpileup=>allruns.map{|i| i+".pileup"} task :allfastq=>allruns.map{|i| i+".fastqgood"} task :allsum=>allruns.map{|i| i+".summary-ann"} class PileupSum @chr @pos @startpos @cov @out @started def set_out(output) @out=output end def initialize @chr="" @pos=0 @startpos=0 @cov=[] @started=false end def consume(line) spl = line.split newchr = spl[1] newpos = spl[2].to_i newcov = spl[3].to_i if (newpos-@pos > 1 || @chr!=newchr) flush(newcov,newpos,newchr) else @started=true @cov.push(newcov) @pos=newpos @chr=newchr end end def flush(newcov,newpos,newchr) if (@started) fin end @cov=[newcov] @startpos=newpos @pos=newpos @chr=newchr end def fin @out.puts @chr + " " + @startpos.to_s + " " + (@pos + 1 - @startpos).to_s + " " + mean(@cov).to_s end def mean(cov) i=0.0 cov.each{|a| i+=a} i/cov.length end end rule ".summary" => [".pileup"] do |t| summ = PileupSum.new summ.set_out(t.tmpout) File.open(t.prerequisites[0]).each_line{|line| next unless line[0..3]=="cons" summ.consume(line) } summ.fin t.fintmp end require 'ensembl' include Ensembl::Core class Annotate def initialize DBConnection.connect('mus_musculus',54) end def annotate(string) #1 4199590 23 1.0 spl = string.split buffer = 100000 out = "" slice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - buffer ,spl[2].to_i + spl[1].to_i + buffer ,1) nearslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - 1000 ,spl[2].to_i + spl[1].to_i + 1000 ,1) realslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i ,spl[2].to_i + spl[1].to_i,1) slice.genes.find_all{|g| g.slice.overlaps?(realslice)}.each do |gene| out = out + "g:"+gene.stable_id+"," gene.transcripts.find_all{|t| t.slice.overlaps?(realslice)}.each do |t| out=out+"t:"+t.stable_id+"_"+t.strand.to_s + "," t.exons.find_all{|e| e.slice.overlaps?(realslice)}.each do |e| out = out + "e:"+e.stable_id+"," end t.introns.find_all{|i| i.slice.overlaps?(realslice)}.each do |i| out = out + "i_" #if t.strand==1 # out=out+i.previous_exon.end_phase.to_s #else # out=out+i.previous_exon.end_phase.to_s #end #with my patches out=out+i.previous_exon.end_phase.to_s out = out +"," end end end slice.genes.find_all{|g| (g.slice.overlaps?(nearslice) && !g.slice.overlaps?(realslice))}.each do |gene| out = out + "n:"+gene.stable_id+"," end return out end end rule ".summary-ann" => [".summary-ann-raw",".pileup_dir"] do |t| output = t.tmpout threshold = 5.0 dirF=Hash.new{|h,k| h[k]=Hash.new(0)} dirR=Hash.new{|h,k| h[k]=Hash.new(0)} File.open(t.prerequisites[1]).each_line{|l| s = l.split dirF[s[0]][s[1].to_i]=s[2].to_i dirR[s[0]][s[1].to_i]=s[3].to_i } File.open(t.prerequisites[0]).each_line.find_all{|l| s = l.split (s[2].to_i > 50 && s[3].to_f > threshold ) }.each{|line| s = line.split f = dirF[s[0]] r = dirR[s[0]] fTot = 0.0 rTot = 0.0 (s[1].to_i .. s[1].to_i + s[2].to_i).each do |i| fTot+=f[i] rTot+=r[i] end rTot/=s[2].to_f fTot/=s[2].to_f output.puts(line.chomp + " " + fTot.to_s + " " + rTot.to_s) } t.fintmp end ann = Annotate.new rule ".summary-ann-raw" => ".summary" do |t| output = t.tmpout File.open(t.prerequisites[0]).each_line{|line| output.puts(line.chomp + " " + ann.annotate(line)) } t.fintmp end rule ".summary-fin" => ".summary-ann" do |t| #want seqs with correct strand output = t.tmpout File.open(t.prerequisites[0]).each_line.find_all{ |line| s = line.split if s.length > 6 && !(s[4]=~/t:/).nil? # then gene hit if s[5].to_f < 0.001 || s[6].to_f < 0.001 if s[5].to_f > 0.001 #assume forward if (s[4]=~/_1/).nil? false else true end else #negative if (s[4]=~/_-1/).nil? false else true end end else false end else true end }.each{|line| output.puts(line) } t.fintmp end rule ".pileup_dir" => ".cigargood" do |t| require 'ostruct' #cigar::50 IL13_2618:1:1:6:1924/1 3 54 + 4 116467134 116467185 + 52 M 52 dir={} dir["+"]=Hash.new{|h,k| h[k]=Hash.new(0)} dir["-"]=Hash.new{|h,k| h[k]=Hash.new(0)} vals=[] File.open(t.prerequisites[0]).each_line do |l| s = l.split #ignores indels but should be okay start = s[6].to_i stop = s[7].to_i chr = s[5] d = dir[s[4]] (start..stop).each{|i| d[chr][i]=d[chr][i]+1 } end out = t.tmpout (dir["+"].keys + dir["-"].keys).sort.uniq.each do |chr| (dir["+"][chr].keys + dir["-"][chr].keys).sort.uniq.each do |pos| out.puts chr + " " + pos.to_s + " " + dir["+"][chr][pos].to_s + " " + dir["-"][chr][pos].to_s + "\n" end end t.fintmp end rule ".hotspot-csv" => ".summary-fin" do |t| # 1 15816457 53 35.3396226415094 g:ENSMUSG00000025925,t:ENSMUST00000093770_1,t:ENSMUST00000027057_1, 35.3396226415094 0.0 out = t.tmpout genehash = Hash.new{|h,k| h[k]=[]} File.open(t.prerequisites[0]).each_line.find_all{|l| l=~/g:/}.each do |l| s = l.split genes = s[4].split(",").find_all{|g| g[0..1]=="g:"} genes.each{|g| genehash[g].push(s[0]+","+s[1]+","+s[2]+","+s[3]) } end genehash.each.sort_by{|k,v| v.length}.each{|k,v| out.puts(v.length.to_s + "," + k + "," + v.join(",")) } t.fintmp end task :allhotspot => allruns.map{|l| l+".hotspot-csv"} file "allhotspots.csv" => :allhotspot do |t| out = t.tmpout allruns.map{|l| l+".hotspot-csv"}.each{|file| out.puts(file.gsub(".hotspot-csv","")) File.open(file).each_line{|l| out.puts(l)} } t.fintmp end rule ".GGCTAA" => ".fastq" do |t| if t.prerequisites[0]=~/_[0-9]_2.fastq/ leftfile= t.name.gsub(/_2\./,'.') sh "rake " + leftfile sh "fastqpair " + leftfile + " " +t.prerequisites[0] + " > " + t.tmpname t.fintmp else sh "grep ^GGCTAG -A 2 -B 1 " + t.prerequisites[0] + " | grep -v -- ^--$ > " + t.tmpname t.fintmp end end rule ".GGCTAA-out" => ".GGCTAA" do |t| pair = t.prerequisites[0].gsub(/\./,'_2.') sh "rake " + pair sh "/nfs/team117/hp3/sw/arch/ia64-linux/bin/ssaha2-2.3.1 -rtype solexa -kmer 13 -skip 2 -score 20 -output cigar -outfile " + t.name + "abnormal -diff 0 -pair 2,500 NCBI_M37.fa " + t.prerequisites[0] + " " + pair + " > " + t.tmpname t.fintmp end task :normalGGCTAA do |t| allruns.each{|i| mv i+".GGCTAA", i+".fastq" if File.exists?(i) } Dir.glob("*.GGCTAA-*").each{|i| mv i, i.gsub("GGCTAA-","") } Dir.glob("*.GGCTAA").each{|i| mv i, i.gsub("GGCTAA","fastq") } end
benb/transposon-rake
df77a32dfa650862849781d3c7c7a4f4ac8f21b3
FastqRecord object
diff --git a/fastq.rb b/fastq.rb index 41d7459..b534c11 100755 --- a/fastq.rb +++ b/fastq.rb @@ -1,28 +1,41 @@ #!/usr/bin/env ruby require 'rubygems' require 'ostruct' class Fastq def initialize(file) @f=File.open(file,'r') end def each while self.has_next? yield self.next end end def next name = @f.readline.sub("^@","").chomp seq = @f.readline.chomp @f.readline qual=@f.readline.chomp - return OpenStruct.new(:name => name, :seq => seq, :qual => qual) + return FastqRecord.new(name,seq,qual) end def has_next? return !@f.eof? end def self.tofastqstr(r) r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual end end +class FastqRecord + attr_reader :name, :seq, :qual + def initialize(name,seq,qual) + @name=name + @seq=seq + @qual=qual + end + def to_s + @name + "\n" + @seq + "\n+\n" + @qual + end + +end +
benb/transposon-rake
f413e83b6c9050533a1682c0f173df0ec569d375
Remove amatch dependency
diff --git a/fastq.rb b/fastq.rb index 65aa1c0..41d7459 100755 --- a/fastq.rb +++ b/fastq.rb @@ -1,96 +1,28 @@ #!/usr/bin/env ruby require 'rubygems' -require 'amatch' require 'ostruct' -include Amatch -class String - def each_substring(len) - (0..length).each{|i| - yield [self[i..i+len-1],i] - } - end -end class Fastq def initialize(file) @f=File.open(file,'r') end def each while self.has_next? yield self.next end end def next name = @f.readline.sub("^@","").chomp seq = @f.readline.chomp @f.readline qual=@f.readline.chomp return OpenStruct.new(:name => name, :seq => seq, :qual => qual) end def has_next? return !@f.eof? end def self.tofastqstr(r) r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual end end -class TrimmedFastq - def initialize(fastq,qs,qe) - @f=fastq - @queriesStart=qs - @queriesEnd=qe - end - def each - @f.each do |record| - @queriesStart.each{|q| - lastPos = -1 - bestDist = 3 - record.seq.each_substring(q.pattern.length){|str,pos| - if (q.match(str)<bestDist) - lastPos = pos + q.pattern.length - bestDist = q.match(str) - end - } - if (lastPos > -1) - # puts "lastPos " + lastPos.to_s - # puts "seq " + record.seq - # puts "dropping " + record.seq[0..lastPos-1] - # puts "keeping " + record.seq[lastPos..record.seq.length-1] - record.seq=record.seq[lastPos..record.seq.length-1] - record.qual=record.qual[lastPos..record.qual.length-1] - end - } - record.seq="" if record.seq==nil - @queriesEnd.each{|q| - lastPos = record.seq.length - bestDist = 3 - - record.seq.each_substring(q.pattern.length){|str,pos| - if (q.match(str)<bestDist) - puts q.pattern + " matches " + str - lastPos=pos - bestDist = q.match(str) - end - } - if (lastPos < record.seq.length) - record.seq=record.seq[0..lastPos-1] - record.qual=record.qual[0..lastPos-1] - end - } - record.seq="" if record.seq==nil - record.qual="" if record.qual==nil - yield record - end - end -end - -#queriesStart = [Levenshtein.new("CT")] -#queriesEnd = [Levenshtein.new("GA")] - - -#f = Fastq.new("test.fastq") -#ft = TrimmedFastq.new(f,queriesStart,queriesEnd) -#ft.each{|r| -# puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) -#}
benb/transposon-rake
e3cbb4a7ea9dd8417aec5edbf674ede7788ba2e2
Adding Rakefile
diff --git a/fastq.rb b/fastq.rb index b8b6fb6..65aa1c0 100755 --- a/fastq.rb +++ b/fastq.rb @@ -1,96 +1,96 @@ #!/usr/bin/env ruby require 'rubygems' require 'amatch' require 'ostruct' include Amatch class String def each_substring(len) (0..length).each{|i| yield [self[i..i+len-1],i] } end end class Fastq def initialize(file) @f=File.open(file,'r') end def each - line=0 - @f.each do |l| - line+=1 - case line - when 1 - @name=l.sub("^@","") - when 2 - @seq=l.chomp - when 3 - when 4 - @qual=l.chomp - end - if (line==4) - line = 0 - yield OpenStruct.new(:name => @name, :seq => @seq, :qual => @qual) - end + while self.has_next? + yield self.next end end + def next + name = @f.readline.sub("^@","").chomp + seq = @f.readline.chomp + @f.readline + qual=@f.readline.chomp + return OpenStruct.new(:name => name, :seq => seq, :qual => qual) + end + def has_next? + return !@f.eof? + end + def self.tofastqstr(r) + r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual + end end class TrimmedFastq def initialize(fastq,qs,qe) @f=fastq @queriesStart=qs @queriesEnd=qe end def each @f.each do |record| @queriesStart.each{|q| lastPos = -1 bestDist = 3 record.seq.each_substring(q.pattern.length){|str,pos| if (q.match(str)<bestDist) lastPos = pos + q.pattern.length bestDist = q.match(str) end } if (lastPos > -1) # puts "lastPos " + lastPos.to_s # puts "seq " + record.seq # puts "dropping " + record.seq[0..lastPos-1] # puts "keeping " + record.seq[lastPos..record.seq.length-1] record.seq=record.seq[lastPos..record.seq.length-1] record.qual=record.qual[lastPos..record.qual.length-1] end } record.seq="" if record.seq==nil @queriesEnd.each{|q| lastPos = record.seq.length bestDist = 3 record.seq.each_substring(q.pattern.length){|str,pos| if (q.match(str)<bestDist) - # puts q.pattern + " matches " + str + puts q.pattern + " matches " + str lastPos=pos bestDist = q.match(str) end } if (lastPos < record.seq.length) record.seq=record.seq[0..lastPos-1] record.qual=record.qual[0..lastPos-1] end } record.seq="" if record.seq==nil + record.qual="" if record.qual==nil yield record end end end -queriesStart = [Levenshtein.new("CT")] -queriesEnd = [Levenshtein.new("GA")] +#queriesStart = [Levenshtein.new("CT")] +#queriesEnd = [Levenshtein.new("GA")] -f = Fastq.new("test.fastq") -ft = TrimmedFastq.new(f,queriesStart,queriesEnd) -ft.each{|r| - puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) -} +#f = Fastq.new("test.fastq") +#ft = TrimmedFastq.new(f,queriesStart,queriesEnd) +#ft.each{|r| +# puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) +#} diff --git a/rakefile.transposon b/rakefile.transposon new file mode 100644 index 0000000..64b8ccf --- /dev/null +++ b/rakefile.transposon @@ -0,0 +1,497 @@ +require 'rubygems' +require 'amatch' +require 'ostruct' +require 'fastq' +require 'md5' +include Amatch + + +allruns = ["3293_2","3293_3","3293_5","3293_6"] + +#locations of important binaries +ssaha_pileup = "./ssaha_pileup" +ssaha2='~hp3/sw/arch/x86_64-linux/bin/ssaha2-2.4' + +#regex of the tag we want to pull out +tagregex = /^[NG][GN][TN][TN][AN][AN]/ + +task :process_fastq => allruns.map{|i| i+"_1.fastqsel"} + allruns.map{|i| i + "_2.fastqsel"} + +class PairFastq + def initialize(r1,r2) + @r1=r1 + @r2=r2 + end + def next + [@r1.next,@r2.next] + end + def has_next? + @r1.has_next? && @r2.has_next? + end + def each + while self.has_next? + yield self.next + end + end +end +#Clip the reads: +rule(/_1.fastqde/ => + [proc {|task_name| task_name.sub(/de$/,'') }, + proc {|task_name| task_name.sub(/_1.fastqde$/,'_2.fastq') }]) do |t| + #This code is SO SLOW you should probably use something else + puts(t.prerequisites[0]) + r1= Fastq.new(t.prerequisites[0]) + r2 = Fastq.new(t.prerequisites[1]) + o1=File.new(t.prerequisites[0]+"dedupe.tmp","w") + o2=File.new(t.prerequisites[1]+"dedupe.tmp","w") + pair = PairFastq.new(r1,r2) + seen={} + pair.each do |rp| + rphash = rp[0].seq + "," + rp[1].seq + if seen[rphash] == nil + seen[rphash]=1 + o1.puts(Fastq.tofastqstr(rp[0])) + o2.puts(Fastq.tofastqstr(rp[1])) + end + end + mv(t.prerequisites[0]+"dedupe.tmp",t.prerequisites[0]+"dedupe") + mv(t.prerequisites[1]+"dedupe.tmp",t.prerequisites[1]+"dedupe") +end + + + +rule '.fastqclip' => '.fastqde' do |t| + f = Fastq.new(t.prerequisites[0]) + out = File.new(t.name + ".tmp","w") + if (t.name =~ /_1.fastq/) + #So, please trim all read 1s that have AGATCGGAAGAG - i.e. at the point + #that the sequence becomes this, remove all the bases that follow. + seq = /AGATCGGAAGAG.*/ + else + #For these sequences, read 2 will need to be trimmed back too. This will + #start with mouse sequence, and will then run into the transposon + #sequence: TTAACCCTAGAAAG . . . . + seq = /TTAACCCTAGAAAG.*/ + + end + f.each{|r| + if (r.seq =~ seq) + clip = seq.match(r.seq).begin(0) + if clip > 0 + out.puts(r.name.chomp + "\n" + r.seq[0..clip] + "\n+\n" + r.qual[0..clip]) + else + out.puts(r.name.chomp + "\n" + "NNNN" + "\n+\n" + "!!!!") + end + else + out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) + end + + } + mv(t.name+".tmp",t.name) +end + +def fastqout(out,record) + out.puts(record.name.chomp + "\n" + record.seq + "\n+\n" + record.qual) +end + +#Select the sequences that start with the tag +rule(/_1.fastqsel$/ => [ + proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') } + ]) do |t| + f = Fastq.new(t.prerequisites[0]) + out = File.new(t.name + ".tmp","w") + f.each{|r| + out.puts(r.name.chomp + "\n" + r.seq + "\n+\n" + r.qual) if (r.seq =~ tagregex ) if r.seq=~ tagregex + } + mv(t.name+".tmp",t.name) + end + + + +#remove sequences in _2 that aren't in _1 +rule(/_2.fastqsel$/ => [ + proc {|task_name| task_name.sub(/.fastqsel$/,'.fastqclip') }, + proc {|task_name| task_name.sub(/_2.fastqsel$/,'_1.fastqsel') } + ]) do |t| + f1 = Fastq.new(t.prerequisites[1]) + f2 = Fastq.new(t.prerequisites[0]) + out = File.new(t.name + ".tmp","w") + f1.each{|r1| + ok = false + while !ok + r2 = f2.next + if r1.name.sub(/\/1$/,"/2")==r2.name + fastqout(out,r2) + ok=true + end + end + } + mv(t.name+".tmp",t.name) + end + +#produce the alignment +rule(/.ssaha.*/ => [proc{|t| t.sub(/.ssaha/,'_1.fastqsel')},proc{|t| t.sub(/.ssaha/,'_2.fastqsel')}]) do |t| + puts t.name + command = ssaha2 + ' -rtype solexa -score 20 -kmer 13 -skip 2 -output cigar -pair 2,500 -outfile ' + t.name+'.abnormal NCBI_M37.fa ' + t.prerequisites[0] + " " + t.prerequisites[0].gsub(/_1.fastq/,"_2.fastq") +" > " + t.name + ".tmp" + puts command + sh command + mv(t.name+".tmp",t.name) +end + + +class HashDir + def hashpath(file) + hashdir(file) + '/' + file + end + def hashdir(file) + hashtag = file.sub(/_[12]\./,".").sub(/\..*_/,"") + return MD5.new(hashtag).hexdigest[0..1] + end +end +hasher = HashDir.new + +task :allssaha => Dir.glob("*_1.fastq").map{|n| n.sub(/._1.fastq$/,'.ssaha')} + +task :split => "split.stamp" +file "split.stamp" do |t| + Dir.glob("*.fastqsel").each do |f| + puts "split -l 400000 " + f + " " + f +"_" + end + Dir.glob("*.fastqsel_[a-z][a-z]").each do |f| + hashdir = hasher.hashdir(f) + sh "mkdir -p #{hashdir}" + mv f, hashdir+"/"+f + end + sh "touch split.stamp" +end + + + +task :merge => "merge.task" +file "merge.task" do |t| + files = Dir.glob("*/*.ssaha_[a-z][a-z]").sort_by{|a| a.sub(/.*\//,"")} + files.map{|f| f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"")}.uniq.each do |f| + sh "rm -f " + f + end + files.each do |f| + sh "cat " + f + " >> " + f.sub(/_[a-z][a-z]/,"").sub(/.*\//,"") + end + sh "touch merge.task" +end + +require "tempfile" +class File + def each(count) + while (!eof) + c=count + x=[] + while(c>0 && !eof) + x.push(readline) + c-=1 + end + yield x + end + end +end +class Rake::FileTask + def tmpname + name+".tmp" + end + def tmpout + File.new(tmpname,"w") + end + def fintmp + mv name+".tmp", name + end +end + +rule ".cigar" => ".ssaha" do |t| + sh " grep \/1 #{t.prerequisites[0]} > #{t.name}" +end + +rule ".pileup" => [proc {|n| n.sub(/.pileup/,"_1.fastqsel")},".cigar"] do |t| + #script = Tempfile.new("script") + #script.chmod(0700) + #script.puts("./ssaha_pileup -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}") + #script.close + #sh "msub 60000 -o pileup.out.%J -q hugemem -K " + script.path + #script.delete + sh ssaha_pileup + " -cons 1 -cover 0 #{t.prerequisites[1]} NCBI_M37.fa #{t.prerequisites[0]} > #{t.tmpname}" + t.fintmp +end + +task :allpileup=>allruns.map{|i| i+".pileup"} +task :allfastq=>allruns.map{|i| i+".fastqgood"} +task :allsum=>allruns.map{|i| i+".summary-ann"} +class PileupSum + @chr + @pos + @startpos + @cov + @out + @started + def set_out(output) + @out=output + end + + def initialize + @chr="" + @pos=0 + @startpos=0 + @cov=[] + @started=false + end + def consume(line) + spl = line.split + newchr = spl[1] + newpos = spl[2].to_i + newcov = spl[3].to_i + if (newpos-@pos > 1 || @chr!=newchr) + flush(newcov,newpos,newchr) + else + @started=true + @cov.push(newcov) + @pos=newpos + @chr=newchr + end + end + def flush(newcov,newpos,newchr) + if (@started) + fin + end + @cov=[newcov] + @startpos=newpos + @pos=newpos + @chr=newchr + end + def fin + @out.puts @chr + " " + @startpos.to_s + " " + (@pos + 1 - @startpos).to_s + " " + mean(@cov).to_s + end + + def mean(cov) + i=0.0 + cov.each{|a| i+=a} + i/cov.length + end + +end + + +rule ".summary" => [".pileup"] do |t| + summ = PileupSum.new + summ.set_out(t.tmpout) + File.open(t.prerequisites[0]).each_line{|line| + next unless line[0..3]=="cons" + summ.consume(line) + } + summ.fin + t.fintmp +end + +require 'ensembl' +include Ensembl::Core +class Annotate + def initialize + DBConnection.connect('mus_musculus',54) + end + + def annotate(string) + #1 4199590 23 1.0 + spl = string.split + buffer = 100000 + + out = "" + + slice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - buffer ,spl[2].to_i + spl[1].to_i + buffer ,1) + nearslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i - 1000 ,spl[2].to_i + spl[1].to_i + 1000 ,1) + realslice = Slice.fetch_by_region('chromosome',spl[0],spl[1].to_i ,spl[2].to_i + spl[1].to_i,1) + slice.genes.find_all{|g| g.slice.overlaps?(realslice)}.each do |gene| + out = out + "g:"+gene.stable_id+"," + gene.transcripts.find_all{|t| t.slice.overlaps?(realslice)}.each do |t| + out=out+"t:"+t.stable_id+"_"+t.strand.to_s + "," + t.exons.find_all{|e| e.slice.overlaps?(realslice)}.each do |e| + out = out + "e:"+e.stable_id+"," + end + t.introns.find_all{|i| i.slice.overlaps?(realslice)}.each do |i| + out = out + "i_" + + #if t.strand==1 + # out=out+i.previous_exon.end_phase.to_s + #else + # out=out+i.previous_exon.end_phase.to_s + #end + #with my patches + out=out+i.previous_exon.end_phase.to_s + out = out +"," + end + + end + end + slice.genes.find_all{|g| (g.slice.overlaps?(nearslice) && !g.slice.overlaps?(realslice))}.each do |gene| + out = out + "n:"+gene.stable_id+"," + end + return out + end +end + + +rule ".summary-ann" => [".summary-ann-raw",".pileup_dir"] do |t| + output = t.tmpout + threshold = 5.0 + dirF=Hash.new{|h,k| h[k]=Hash.new(0)} + dirR=Hash.new{|h,k| h[k]=Hash.new(0)} + File.open(t.prerequisites[1]).each_line{|l| + s = l.split + dirF[s[0]][s[1].to_i]=s[2].to_i + dirR[s[0]][s[1].to_i]=s[3].to_i + } + File.open(t.prerequisites[0]).each_line.find_all{|l| + s = l.split + (s[2].to_i > 50 && s[3].to_f > threshold ) + }.each{|line| + s = line.split + f = dirF[s[0]] + r = dirR[s[0]] + fTot = 0.0 + rTot = 0.0 + (s[1].to_i .. s[1].to_i + s[2].to_i).each do |i| + fTot+=f[i] + rTot+=r[i] + end + rTot/=s[2].to_f + fTot/=s[2].to_f + output.puts(line.chomp + " " + fTot.to_s + " " + rTot.to_s) + } + t.fintmp +end + +ann = Annotate.new +rule ".summary-ann-raw" => ".summary" do |t| + output = t.tmpout + File.open(t.prerequisites[0]).each_line{|line| + output.puts(line.chomp + " " + ann.annotate(line)) + } + t.fintmp +end + +rule ".summary-fin" => ".summary-ann" do |t| + #want seqs with correct strand + output = t.tmpout + File.open(t.prerequisites[0]).each_line.find_all{ |line| + s = line.split + if s.length > 6 && !(s[4]=~/t:/).nil? # then gene hit + if s[5].to_f < 0.001 || s[6].to_f < 0.001 + if s[5].to_f > 0.001 #assume forward + if (s[4]=~/_1/).nil? + false + else + true + end + else #negative + if (s[4]=~/_-1/).nil? + false + else + true + end + + end + else + false + end + else + true + end + }.each{|line| + output.puts(line) + } + t.fintmp +end + +rule ".pileup_dir" => ".cigargood" do |t| + require 'ostruct' + + #cigar::50 IL13_2618:1:1:6:1924/1 3 54 + 4 116467134 116467185 + 52 M 52 + dir={} + dir["+"]=Hash.new{|h,k| h[k]=Hash.new(0)} + dir["-"]=Hash.new{|h,k| h[k]=Hash.new(0)} + vals=[] + File.open(t.prerequisites[0]).each_line do |l| + s = l.split + #ignores indels but should be okay + start = s[6].to_i + stop = s[7].to_i + chr = s[5] + d = dir[s[4]] + (start..stop).each{|i| + d[chr][i]=d[chr][i]+1 + } + end + out = t.tmpout + (dir["+"].keys + dir["-"].keys).sort.uniq.each do |chr| + (dir["+"][chr].keys + dir["-"][chr].keys).sort.uniq.each do |pos| + out.puts chr + " " + pos.to_s + " " + dir["+"][chr][pos].to_s + " " + dir["-"][chr][pos].to_s + "\n" + end + end + t.fintmp +end + +rule ".hotspot-csv" => ".summary-fin" do |t| + # 1 15816457 53 35.3396226415094 g:ENSMUSG00000025925,t:ENSMUST00000093770_1,t:ENSMUST00000027057_1, 35.3396226415094 0.0 + out = t.tmpout + genehash = Hash.new{|h,k| h[k]=[]} + File.open(t.prerequisites[0]).each_line.find_all{|l| l=~/g:/}.each do |l| + s = l.split + genes = s[4].split(",").find_all{|g| g[0..1]=="g:"} + genes.each{|g| + genehash[g].push(s[0]+","+s[1]+","+s[2]+","+s[3]) + } + end + genehash.each.sort_by{|k,v| v.length}.each{|k,v| + out.puts(v.length.to_s + "," + k + "," + v.join(",")) + } + t.fintmp +end +task :allhotspot => allruns.map{|l| l+".hotspot-csv"} + +file "allhotspots.csv" => :allhotspot do |t| + out = t.tmpout + allruns.map{|l| l+".hotspot-csv"}.each{|file| + out.puts(file.gsub(".hotspot-csv","")) + File.open(file).each_line{|l| out.puts(l)} + } + t.fintmp +end + +rule ".GGCTAA" => ".fastq" do |t| + if t.prerequisites[0]=~/_[0-9]_2.fastq/ + leftfile= t.name.gsub(/_2\./,'.') + sh "rake " + leftfile + sh "fastqpair " + leftfile + " " +t.prerequisites[0] + " > " + t.tmpname + t.fintmp + else + sh "grep ^GGCTAG -A 2 -B 1 " + t.prerequisites[0] + " | grep -v -- ^--$ > " + t.tmpname + t.fintmp + end +end + +rule ".GGCTAA-out" => ".GGCTAA" do |t| + pair = t.prerequisites[0].gsub(/\./,'_2.') + sh "rake " + pair + + sh "/nfs/team117/hp3/sw/arch/ia64-linux/bin/ssaha2-2.3.1 -rtype solexa -kmer 13 -skip 2 -score 20 -output cigar -outfile " + t.name + "abnormal -diff 0 -pair 2,500 NCBI_M37.fa " + t.prerequisites[0] + " " + pair + " > " + t.tmpname + t.fintmp + +end + +task :normalGGCTAA do |t| + allruns.each{|i| + mv i+".GGCTAA", i+".fastq" if File.exists?(i) + } + Dir.glob("*.GGCTAA-*").each{|i| + mv i, i.gsub("GGCTAA-","") + } + Dir.glob("*.GGCTAA").each{|i| + mv i, i.gsub("GGCTAA","fastq") + } +end +
inhortte/randomrip
fc52643e688b52be557acc11da558e096cf4ae62
v 0.01 - initial work on the gui
diff --git a/bin/randomrip b/bin/randomrip new file mode 100755 index 0000000..b85710e --- /dev/null +++ b/bin/randomrip @@ -0,0 +1,12 @@ +#!/usr/bin/ruby +$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +require 'randomrip' + +artist = "Fred Frith" +title = "Pacifica" +tracks = [ "Pacifica Part 1", "Pacifica Part 2", "Unknown", "I Hit Tony On The Head With A Giant Red Hammer" ] + +GUI.new(artist, title, tracks) + + + diff --git a/lib/randomrip.rb b/lib/randomrip.rb new file mode 100644 index 0000000..ef776a3 --- /dev/null +++ b/lib/randomrip.rb @@ -0,0 +1 @@ +require 'randomrip/gui' diff --git a/lib/randomrip/gui.rb b/lib/randomrip/gui.rb new file mode 100644 index 0000000..a398261 --- /dev/null +++ b/lib/randomrip/gui.rb @@ -0,0 +1,113 @@ +require 'tk' + +class GUI + def initialize(artist, title, tracks) + @tracks = tracks + @entry_width = 40 # in characters. + @entry_height = 25 + @frame_width = 475 + + root = TkRoot.new do + title "ReR Megacorp" + minsize(500,200) + end + + title_artist_frame = TkFrame.new do + relief 'groove' + borderwidth 1 + pack('pady' => 10) + end + + TkLabel.new(title_artist_frame) do + text 'Artist' + padx 5 + grid('row' => 0, 'column' => 0) + end + eartist = TkEntry.new(title_artist_frame) + vartist = TkVariable.new + eartist.textvariable = vartist + vartist.value = artist + eartist.grid('row' => 0, 'column' => 1) + + TkLabel.new(title_artist_frame) do + text 'Title' + padx 5 + grid('row' => 1, 'column' => 0) + end + etitle = TkEntry.new(title_artist_frame) + vtitle = TkVariable.new + etitle.textvariable = vtitle + vtitle.value = title + etitle.grid('row' => 1, 'column' => 1) + + tracks_frame = TkFrame.new do + relief 'groove' + borderwidth 1 + pack +# place('height' => tracks.size * 34, +# 'width' => 500, +# 'x' => 10, +# 'y' => 70) + end + + @track_widgets = [] + + (0..(tracks.size - 1)).each { |i| + row = i + 1 + + TkLabel.new(tracks_frame) do + text "Track " + (i+1).to_s + padx 5 + grid('row' => row, 'column' => 1) + end + entry = TkEntry.new(tracks_frame) + var = TkVariable.new + entry.textvariable = var + var.value = tracks[i] + entry.width = @entry_width + entry.grid('row' => row, 'column' => 2) + TkLabel.new(tracks_frame) do + text "Rip?" + padx 5 + grid('row' => row, 'column' => 3) + end + check_var = TkVariable.new + check_var.value = 1 + check = TkCheckButton.new(tracks_frame) do + variable check_var + padx 5 + grid('row' => row, 'column' => 4) + command(select) + end + check.bind('ButtonPress-1', proc { self.clickCheck(i) }) + @track_widgets += [{ 'entry' => entry, 'check' => check }] + } + + TkButton.new(root) do + text 'Dump' + borderwidth 5 + underline 0 + state 'normal' + cursor 'watch' + foreground 'red' + activebackground 'green' + relief 'groove' + command(proc { self.dump }) + pack("side" => "bottom", "padx"=> "50", "pady"=> "10") + end + + Tk.mainloop + end +p + def clickCheck(which) + puts "checkbox#" + which.to_s + " value: " + @track_widgets[which]['check'].variable.value + @track_widgets[which]['check'].variable.value = @track_widgets[which]['check'].variable.value == 1 ? 0 : 1 + end + + def dump + @track_widgets.each { |tw| + puts tw['entry'].variable.value + " " + tw['check'].variable.value + } + end +end +
foxbunny/Timetrack
3f392f16d8c53c8fd1fc58e9aff66476ab977de1
Changed prompt for timer stop to include a message on how to abort
diff --git a/.tt.py.swp b/.tt.py.swp index 79f36ff..fd262ab 100644 Binary files a/.tt.py.swp and b/.tt.py.swp differ diff --git a/tt.py b/tt.py index 264d03e..4f9e148 100755 --- a/tt.py +++ b/tt.py @@ -1,245 +1,245 @@ #!/usr/bin/env python """ Simple-stupid time tracker script ================================= Timetrack opyright (C) 2010, Branko Vukelic <studio@brankovukelic.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import sys import getopt import os import re import sqlite3 HOME_DIR = os.path.expanduser('~') DEFAULT_FILE = os.path.join(HOME_DIR, 'timesheet.db') PID_RE = re.compile(r'^[A-Za-z]{3}$') def optpair(opts): """ Pair option switches and their own arguments """ optdict = {} for sw, a in opts: optdict[sw] = a return optdict def check_pid(pname): """ Check project name, return true if it is correct """ if PID_RE.match(pname): return True return False def generate_timestamp(): from datetime import datetime timenow = datetime.now() return (datetime.strftime(timenow, '%Y-%m-%d %H:%M:%S'), timenow) def getduration(seconds): seconds = int(seconds) hours = seconds // 3600 seconds = seconds - hours * 3600 minutes = seconds // 60 seconds = seconds - minutes * 60 return (hours, minutes, seconds) def get_pids(connection): """ Get unique PIDs from database """ pids = [] c = connection.cursor() c.execute("SELECT DISTINCT pid FROM timesheet ORDER BY pid ASC;") for pid in c: pids.append(pid[0]) c.close() return pids def get_times(connection, pidfilter): """ Return a dictionary of PIDs with [job, time] pairs """ if pidfilter: pids = [pidfilter] else: pids = get_pids(connection) pid_times = {} for pid in pids: c = connection.cursor() c.execute("SELECT desc, TOTAL(dur) FROM timesheet WHERE pid = ? GROUP BY desc;", (pid,)) results = [] for result in c: results.append(result) pid_times[pid] = results c.close() return pid_times def read_stats(connection, pidfilter): pid_times = get_times(connection, pidfilter) if not pid_times: print "No data in database. Exiting." return True for k in pid_times.keys(): print "" print "==========================" print "PID: %s" % k print "==========================" print "" for j in pid_times[k]: print "Job: %s" % j[0] print "Time: %02d:%02d:%02d" % getduration(j[1]) print "" print "==========================" print "" def export_tsv(connection, filename, pidfilter): pid_times = get_times(connection, pidfilter) if not pid_times: print "No data in database. Exiting." return True f = open(filename, 'w') # Write header f.write('PID\tJob\tTime\n') for k in pid_times.keys(): for j in pid_times[k]: f.write('%s\t%s\t%s\n' % (k, j[0], j[1])) f.close() def clean_string(s): """ Escapes characters in a string for SQL """ return s.replace(';', '\\;').replace('\'', '\\\'') def add_data(connection, pidfilter): """ Gives user a prompt and writes data to the fhandle file """ import readline print "Press Ctrl+C to exit." try: while True: pid = pidfilter while not check_pid(pid): pid = raw_input("PID: ") if not check_pid(pid): print "'%s' is not a valid pid, please use a 3 letter sequence" % pid print "Project ID is %s" % pid desc = raw_input("Job: ") desc = clean_string(desc) if pid and desc: timestamp, starttime = generate_timestamp() print "Timer started at %s" % timestamp - raw_input("Press Enter to stop the timer") + raw_input("Press Enter to stop the timer or Ctrl+C to abort") endtimestamp, endtime = generate_timestamp() print "Timer stopped at %s" % endtimestamp delta = endtime - starttime dsecs = delta.seconds print "Total duration was %s seconds" % dsecs args = (timestamp, pid, desc, dsecs) c = connection.cursor() try: c.execute("INSERT INTO timesheet (timestamp, pid, desc, dur) VALUES (?, ?, ?, ?)", args) except: connection.rollback() print "DB error: Data was not written" raise else: connection.commit() c.close() print "\n" except KeyboardInterrupt: connection.rollback() def usage(): print """Timetrack Copyright (c) 2010, Branko Vukelic Released under GNU/GPL v3, see LICENSE file for details. Usage: tt.py [-a] [-r] [-t FILE] [-p PID] [--add] [--read] [--tsv FILE] [--pid PID] [dbfile] -r --read : Display the stats. -a --add : Start timer session (default action). -t --tsv : Export into a tab-separated table (TSV). FILE is the filename to use for exporting. -p --pid : With argument 'PID' (3 letters, no numbers or non-alphanumeric characters. Limits all operations to a single PID. dbfile : Use this file as database, instead of default file. If the specified file does not exist, it will be creadted. More information at: http://github.com/foxbunny/timetrack """ def main(argv): try: opts, args = getopt.getopt(argv, 'rat:p:', ['read', 'add', 'tsv=', 'pid=']) except getopt.GetoptError: usage() sys.exit(2) optdict = optpair(opts) statsfile = len(args) and args[0] or DEFAULT_FILE print "Using stats file '%s'" % statsfile pidfilter = optdict.get('-p', '') or optdict.get('--pid', '') if pidfilter: if check_pid(pidfilter): print "Using project ID filter '%s'" % pidfilter else: print "Project ID filter '%s' is invalid and will be ignored." % pidfilter print "Opening connection to database." try: connection = sqlite3.connect(statsfile) except: print "Database error. Exiting." sys.exit(2) print "Initialize table if none exists" c = connection.cursor() try: c.execute("""CREATE TABLE IF NOT EXISTS timesheet ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME DEFAULT (datetime('now')), pid VARCHAR(3) NOT NULL, desc VARCHAR(255) NOT NULL, dur INTEGER NOT NULL);""") except: connection.rollback() raise else: connection.commit() c.close() if ('-r' in optdict.keys()) or ('--read' in optdict.keys()): read_stats(connection, pidfilter) elif ('-t' in optdict.keys()) or ('--tsv' in optdict.keys()): filename = optdict.get('-t', None) or optdict.get('--tsv') export_tsv(connection, filename, pidfilter) else: add_data(connection, pidfilter) print "Closing connection to database" connection.close() sys.exit(1) if __name__ == '__main__': main(sys.argv[1:])
foxbunny/Timetrack
f3176420188f9e4ffd59a7d715e98fe5dc27f89c
Changed labels for on-screen report.
diff --git a/tt.py b/tt.py index c3c102b..264d03e 100755 --- a/tt.py +++ b/tt.py @@ -1,245 +1,245 @@ #!/usr/bin/env python """ Simple-stupid time tracker script ================================= Timetrack opyright (C) 2010, Branko Vukelic <studio@brankovukelic.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import sys import getopt import os import re import sqlite3 HOME_DIR = os.path.expanduser('~') DEFAULT_FILE = os.path.join(HOME_DIR, 'timesheet.db') PID_RE = re.compile(r'^[A-Za-z]{3}$') def optpair(opts): """ Pair option switches and their own arguments """ optdict = {} for sw, a in opts: optdict[sw] = a return optdict def check_pid(pname): """ Check project name, return true if it is correct """ if PID_RE.match(pname): return True return False def generate_timestamp(): from datetime import datetime timenow = datetime.now() return (datetime.strftime(timenow, '%Y-%m-%d %H:%M:%S'), timenow) def getduration(seconds): seconds = int(seconds) hours = seconds // 3600 seconds = seconds - hours * 3600 minutes = seconds // 60 seconds = seconds - minutes * 60 return (hours, minutes, seconds) def get_pids(connection): """ Get unique PIDs from database """ pids = [] c = connection.cursor() c.execute("SELECT DISTINCT pid FROM timesheet ORDER BY pid ASC;") for pid in c: pids.append(pid[0]) c.close() return pids def get_times(connection, pidfilter): """ Return a dictionary of PIDs with [job, time] pairs """ if pidfilter: pids = [pidfilter] else: pids = get_pids(connection) pid_times = {} for pid in pids: c = connection.cursor() c.execute("SELECT desc, TOTAL(dur) FROM timesheet WHERE pid = ? GROUP BY desc;", (pid,)) results = [] for result in c: results.append(result) pid_times[pid] = results c.close() return pid_times def read_stats(connection, pidfilter): pid_times = get_times(connection, pidfilter) if not pid_times: print "No data in database. Exiting." return True for k in pid_times.keys(): print "" print "==========================" print "PID: %s" % k print "==========================" print "" for j in pid_times[k]: - print "Job: %s" % j[0] - print "Total duration: %02d:%02d:%02d" % getduration(j[1]) + print "Job: %s" % j[0] + print "Time: %02d:%02d:%02d" % getduration(j[1]) print "" print "==========================" print "" def export_tsv(connection, filename, pidfilter): pid_times = get_times(connection, pidfilter) if not pid_times: print "No data in database. Exiting." return True f = open(filename, 'w') # Write header f.write('PID\tJob\tTime\n') for k in pid_times.keys(): for j in pid_times[k]: f.write('%s\t%s\t%s\n' % (k, j[0], j[1])) f.close() def clean_string(s): """ Escapes characters in a string for SQL """ return s.replace(';', '\\;').replace('\'', '\\\'') def add_data(connection, pidfilter): """ Gives user a prompt and writes data to the fhandle file """ import readline print "Press Ctrl+C to exit." try: while True: pid = pidfilter while not check_pid(pid): pid = raw_input("PID: ") if not check_pid(pid): print "'%s' is not a valid pid, please use a 3 letter sequence" % pid print "Project ID is %s" % pid desc = raw_input("Job: ") desc = clean_string(desc) if pid and desc: timestamp, starttime = generate_timestamp() print "Timer started at %s" % timestamp raw_input("Press Enter to stop the timer") endtimestamp, endtime = generate_timestamp() print "Timer stopped at %s" % endtimestamp delta = endtime - starttime dsecs = delta.seconds print "Total duration was %s seconds" % dsecs args = (timestamp, pid, desc, dsecs) c = connection.cursor() try: c.execute("INSERT INTO timesheet (timestamp, pid, desc, dur) VALUES (?, ?, ?, ?)", args) except: connection.rollback() print "DB error: Data was not written" raise else: connection.commit() c.close() print "\n" except KeyboardInterrupt: connection.rollback() def usage(): print """Timetrack Copyright (c) 2010, Branko Vukelic Released under GNU/GPL v3, see LICENSE file for details. Usage: tt.py [-a] [-r] [-t FILE] [-p PID] [--add] [--read] [--tsv FILE] [--pid PID] [dbfile] -r --read : Display the stats. -a --add : Start timer session (default action). -t --tsv : Export into a tab-separated table (TSV). FILE is the filename to use for exporting. -p --pid : With argument 'PID' (3 letters, no numbers or non-alphanumeric characters. Limits all operations to a single PID. dbfile : Use this file as database, instead of default file. If the specified file does not exist, it will be creadted. More information at: http://github.com/foxbunny/timetrack """ def main(argv): try: opts, args = getopt.getopt(argv, 'rat:p:', ['read', 'add', 'tsv=', 'pid=']) except getopt.GetoptError: usage() sys.exit(2) optdict = optpair(opts) statsfile = len(args) and args[0] or DEFAULT_FILE print "Using stats file '%s'" % statsfile pidfilter = optdict.get('-p', '') or optdict.get('--pid', '') if pidfilter: if check_pid(pidfilter): print "Using project ID filter '%s'" % pidfilter else: print "Project ID filter '%s' is invalid and will be ignored." % pidfilter print "Opening connection to database." try: connection = sqlite3.connect(statsfile) except: print "Database error. Exiting." sys.exit(2) print "Initialize table if none exists" c = connection.cursor() try: c.execute("""CREATE TABLE IF NOT EXISTS timesheet ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME DEFAULT (datetime('now')), pid VARCHAR(3) NOT NULL, desc VARCHAR(255) NOT NULL, dur INTEGER NOT NULL);""") except: connection.rollback() raise else: connection.commit() c.close() if ('-r' in optdict.keys()) or ('--read' in optdict.keys()): read_stats(connection, pidfilter) elif ('-t' in optdict.keys()) or ('--tsv' in optdict.keys()): filename = optdict.get('-t', None) or optdict.get('--tsv') export_tsv(connection, filename, pidfilter) else: add_data(connection, pidfilter) print "Closing connection to database" connection.close() sys.exit(1) if __name__ == '__main__': main(sys.argv[1:])
foxbunny/Timetrack
d5c333b9097155abece517da88971a5d86738529
Added a message if no data is found in the database
diff --git a/.tt.py.swp b/.tt.py.swp new file mode 100644 index 0000000..79f36ff Binary files /dev/null and b/.tt.py.swp differ diff --git a/tt.py b/tt.py index 53ed4ef..c3c102b 100755 --- a/tt.py +++ b/tt.py @@ -1,237 +1,245 @@ #!/usr/bin/env python """ Simple-stupid time tracker script ================================= Timetrack opyright (C) 2010, Branko Vukelic <studio@brankovukelic.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import sys import getopt import os import re import sqlite3 HOME_DIR = os.path.expanduser('~') DEFAULT_FILE = os.path.join(HOME_DIR, 'timesheet.db') PID_RE = re.compile(r'^[A-Za-z]{3}$') def optpair(opts): """ Pair option switches and their own arguments """ optdict = {} for sw, a in opts: optdict[sw] = a return optdict def check_pid(pname): """ Check project name, return true if it is correct """ if PID_RE.match(pname): return True return False def generate_timestamp(): from datetime import datetime timenow = datetime.now() return (datetime.strftime(timenow, '%Y-%m-%d %H:%M:%S'), timenow) def getduration(seconds): seconds = int(seconds) hours = seconds // 3600 seconds = seconds - hours * 3600 minutes = seconds // 60 seconds = seconds - minutes * 60 return (hours, minutes, seconds) def get_pids(connection): """ Get unique PIDs from database """ pids = [] c = connection.cursor() c.execute("SELECT DISTINCT pid FROM timesheet ORDER BY pid ASC;") for pid in c: pids.append(pid[0]) c.close() return pids def get_times(connection, pidfilter): """ Return a dictionary of PIDs with [job, time] pairs """ if pidfilter: pids = [pidfilter] else: pids = get_pids(connection) pid_times = {} for pid in pids: c = connection.cursor() c.execute("SELECT desc, TOTAL(dur) FROM timesheet WHERE pid = ? GROUP BY desc;", (pid,)) results = [] for result in c: results.append(result) pid_times[pid] = results c.close() return pid_times def read_stats(connection, pidfilter): pid_times = get_times(connection, pidfilter) + if not pid_times: + print "No data in database. Exiting." + return True + for k in pid_times.keys(): print "" print "==========================" print "PID: %s" % k print "==========================" print "" for j in pid_times[k]: print "Job: %s" % j[0] print "Total duration: %02d:%02d:%02d" % getduration(j[1]) print "" print "==========================" print "" def export_tsv(connection, filename, pidfilter): pid_times = get_times(connection, pidfilter) + + if not pid_times: + print "No data in database. Exiting." + return True f = open(filename, 'w') # Write header f.write('PID\tJob\tTime\n') for k in pid_times.keys(): for j in pid_times[k]: f.write('%s\t%s\t%s\n' % (k, j[0], j[1])) f.close() def clean_string(s): """ Escapes characters in a string for SQL """ return s.replace(';', '\\;').replace('\'', '\\\'') def add_data(connection, pidfilter): """ Gives user a prompt and writes data to the fhandle file """ import readline print "Press Ctrl+C to exit." try: while True: pid = pidfilter while not check_pid(pid): pid = raw_input("PID: ") if not check_pid(pid): print "'%s' is not a valid pid, please use a 3 letter sequence" % pid print "Project ID is %s" % pid desc = raw_input("Job: ") desc = clean_string(desc) if pid and desc: timestamp, starttime = generate_timestamp() print "Timer started at %s" % timestamp raw_input("Press Enter to stop the timer") endtimestamp, endtime = generate_timestamp() print "Timer stopped at %s" % endtimestamp delta = endtime - starttime dsecs = delta.seconds print "Total duration was %s seconds" % dsecs args = (timestamp, pid, desc, dsecs) c = connection.cursor() try: c.execute("INSERT INTO timesheet (timestamp, pid, desc, dur) VALUES (?, ?, ?, ?)", args) except: connection.rollback() print "DB error: Data was not written" raise else: connection.commit() c.close() print "\n" except KeyboardInterrupt: connection.rollback() def usage(): print """Timetrack Copyright (c) 2010, Branko Vukelic Released under GNU/GPL v3, see LICENSE file for details. Usage: tt.py [-a] [-r] [-t FILE] [-p PID] [--add] [--read] [--tsv FILE] [--pid PID] [dbfile] -r --read : Display the stats. -a --add : Start timer session (default action). -t --tsv : Export into a tab-separated table (TSV). FILE is the filename to use for exporting. -p --pid : With argument 'PID' (3 letters, no numbers or non-alphanumeric characters. Limits all operations to a single PID. dbfile : Use this file as database, instead of default file. If the specified file does not exist, it will be creadted. More information at: http://github.com/foxbunny/timetrack """ def main(argv): try: opts, args = getopt.getopt(argv, 'rat:p:', ['read', 'add', 'tsv=', 'pid=']) except getopt.GetoptError: usage() sys.exit(2) optdict = optpair(opts) statsfile = len(args) and args[0] or DEFAULT_FILE print "Using stats file '%s'" % statsfile pidfilter = optdict.get('-p', '') or optdict.get('--pid', '') if pidfilter: if check_pid(pidfilter): print "Using project ID filter '%s'" % pidfilter else: print "Project ID filter '%s' is invalid and will be ignored." % pidfilter print "Opening connection to database." try: connection = sqlite3.connect(statsfile) except: print "Database error. Exiting." sys.exit(2) print "Initialize table if none exists" c = connection.cursor() try: c.execute("""CREATE TABLE IF NOT EXISTS timesheet ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME DEFAULT (datetime('now')), pid VARCHAR(3) NOT NULL, desc VARCHAR(255) NOT NULL, dur INTEGER NOT NULL);""") except: connection.rollback() raise else: connection.commit() c.close() if ('-r' in optdict.keys()) or ('--read' in optdict.keys()): read_stats(connection, pidfilter) elif ('-t' in optdict.keys()) or ('--tsv' in optdict.keys()): filename = optdict.get('-t', None) or optdict.get('--tsv') export_tsv(connection, filename, pidfilter) else: add_data(connection, pidfilter) print "Closing connection to database" connection.close() sys.exit(1) if __name__ == '__main__': main(sys.argv[1:])