Permalink
Browse files

merge leaders controller into mastermind controller

  • Loading branch information...
1 parent ddc48e7 commit 3fa66c06be85ee6ec17839425a27adeaaa00cca2 @avalanche123 committed May 23, 2011
@@ -1,5 +0,0 @@
-class LeadersController < ::ApplicationController
- def index
- @leaders = User.find_top_ten
- end
-end
@@ -1,6 +1,6 @@
class MastermindController < ApplicationController
- before_filter :authenticate_user!, :except => :index
- before_filter :initialize_game, :except => :index
+ before_filter :authenticate_user!, :only => [:play, :guess]
+ before_filter :initialize_game, :only => [:play, :guess]
def index
if user_signed_in?
@@ -9,6 +9,10 @@ def index
end
end
+ def leaders
+ @leaders = User.find_top_ten
+ end
+
def play
end
View
@@ -1,7 +1,7 @@
Mastermind::Application.routes.draw do
root :to => "mastermind#index", :via => :get
devise_for :users
- match '/leaders' => 'leaders#index', :via => :get
+ match '/leaders' => 'mastermind#leaders', :via => :get
match '/play' => 'mastermind#play', :via => :get
match '/guess' => 'mastermind#guess', :via => :post
@@ -0,0 +1,26 @@
+Given /^current code is "([^"]*)"$/ do |code|
+ game = Game.find_by_finished(false)
+ game.code = code.split("-").join
+ game.save!
+end
+
+When /^I submit code "([^"]*)"( (\d+) times)?$/ do |code, text, times|
+ if not times.nil?
+ times.to_i.times do
+ When %{I submit code "#{code}"}
+ end
+ else
+ code.split("-").each_with_index do |number, n|
+ When %{I select "#{number}" from "guess[#{n}]"}
+ end
+ And %{I press "Guess"}
+ end
+end
+
+class StubCodemaker
+ attr_accessor :make
+
+ def initialize(code)
+ @make = code
+ end
+end
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe LeadersController do
- describe "GET 'index'" do
- leaders ||= []
-
- before(:each) do
- User.stub(:find_top_ten).and_return(leaders)
- get :index
- end
-
- it "assigns @leaders" do
- assigns[:leaders].should eq(leaders)
- end
-
- it "renders 'index'" do
- response.should render_template("index")
- end
- end
-end
@@ -27,6 +27,23 @@
end
end
+ describe "GET 'leaders'" do
+ leaders ||= []
+
+ before(:each) do
+ User.stub(:find_top_ten).and_return(leaders)
+ get :leaders
+ end
+
+ it "assigns @leaders" do
+ assigns[:leaders].should eq(leaders)
+ end
+
+ it "renders 'leaders'" do
+ response.should render_template("leaders")
+ end
+ end
+
describe "GET 'play'" do
context "when user is logged in" do
code ||= '0110'
@@ -1,35 +0,0 @@
-require 'spec_helper'
-
-describe "leaders/index.html.erb" do
- let(:leaders) do
- (1..10).map do |id|
- games_won = [1, rand(10)].max
- games_lost = [1, rand(10)].max
- games_total = games_lost + games_won
- guesses_average = (games_lost * 8 + games_won * rand(8)) / (games_total)
-
- mock_model(User, {:email => "user#{id}@example.com",
- :games_won => games_won,
- :games_lost => games_lost,
- :average_guess_count => guesses_average}).as_null_object
- end
- end
-
- it "displays leader board" do
- assign(:leaders, leaders)
- render
-
- rendered.should contain('Leader board')
- rendered.should contain('Email')
- rendered.should contain('Wins')
- rendered.should contain('Loses')
- rendered.should contain('ANG')
-
- leaders.each do |leader|
- rendered.should contain(leader.email)
- rendered.should contain(leader.games_won.to_s)
- rendered.should contain(leader.games_lost.to_s)
- rendered.should contain(leader.average_guess_count.to_s)
- end
- end
-end

0 comments on commit 3fa66c0

Please sign in to comment.