Commit a007163d authored by surma Lodur's avatar surma Lodur

added solve to quest and fix devise test

parent 0046d906
class EarningsController < ApplicationController
before_filter :set_earning, :only => [:cancel]
# TODO user should be set
def cancel
if hacker_signed_in?
@earning.cancel!(current_hacker)
else
@earning.cancel!
end
redirect_to :back
end
#################
## Protected ##
#################
protected
def set_earning
......
# encoding: UTF-8
#
class QuestsController < ApplicationController
before_filter :set_hacker, :only => [:solve]
before_filter :set_quest, :only => [:solve]
######################
## Member Methods ##
######################
def solve
@quest.solve(hacker, current_user)
end
#################
## Protected ##
#################
protected
def set_quest
@quest = Quest.find(params[:id])
end # #set_quest
def set_hacker
@hacker = Hacker.find(params[:hacker_id])
end # #set_hacker
end
......@@ -8,6 +8,11 @@ class Quest < ActiveRecord::Base
validates :points, :numericality => {:greater_than => 0}
def solve(hacker)
end
def solve(hacker, user = nil)
hacker.earnings.create({
:user => user,
:points => self.points,
:chronicle_text => self.description
})
end # #solve
end
......@@ -3,7 +3,15 @@ SpacePunkte::Application.routes.draw do
root :to => 'hackers#index'
resources :hackers
resources :hackers do
member do
resources :quests, :only => [] do
member do
post :solve
end
end
end
end
resource :chronicle, :only => [:show]
......
......@@ -42,4 +42,5 @@ RSpec.configure do |config|
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Devise::TestHelpers, :type => :controller
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment