Commit 0046d906 authored by surma Lodur's avatar surma Lodur

cancel as a user

parent 030d513d
......@@ -39,6 +39,7 @@ group :development do
gem 'ffaker'
gem 'factory_girl_rails', :require => false
gem 'rspec-rails'
gem 'guard', :git => 'https://github.com/guard/guard.git'
gem 'guard-rspec'
gem 'guard-bundler'
end
......
GIT
remote: https://github.com/guard/guard.git
revision: 055c8da9bf593163289bf84327735ec26a9a1f2e
specs:
guard (2.4.0)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
GEM
remote: https://rubygems.org/
specs:
......@@ -33,6 +44,9 @@ GEM
builder (3.1.4)
celluloid (0.15.2)
timers (~> 1.1.0)
celluloid-io (0.15.0)
celluloid (>= 0.15.0)
nio4r (>= 0.5.0)
choice (0.1.6)
coderay (1.1.0)
coffee-rails (4.0.1)
......@@ -59,12 +73,6 @@ GEM
ffaker (1.23.0)
ffi (1.9.3)
formatador (0.2.4)
guard (2.4.0)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-bundler (2.0.0)
bundler (~> 1.0)
guard (~> 2.2)
......@@ -80,8 +88,10 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
listen (2.4.1)
libv8 (3.16.14.3)
listen (2.5.0)
celluloid (>= 0.15.2)
celluloid-io (>= 0.15.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.4)
......@@ -92,6 +102,7 @@ GEM
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.4)
nio4r (1.0.0)
orm_adapter (0.5.0)
polyglot (0.3.3)
pry (0.9.12.6)
......@@ -125,6 +136,7 @@ GEM
ffi (>= 0.5.0)
rdoc (4.1.1)
json (~> 1.4)
ref (1.0.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
......@@ -161,6 +173,9 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.8)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thor (0.18.1)
thread_safe (0.1.3)
atomic
......@@ -187,6 +202,7 @@ DEPENDENCIES
devise
factory_girl_rails
ffaker
guard!
guard-bundler
guard-rspec
jbuilder (~> 1.2)
......@@ -197,5 +213,6 @@ DEPENDENCIES
sass-rails (~> 4.0.0)
sdoc
sqlite3
therubyracer
turbolinks
uglifier (>= 1.3.0)
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard :rspec do
guard(
:rspec
) do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
......
......@@ -4,7 +4,11 @@ class EarningsController < ApplicationController
# TODO user should be set
def cancel
@earning.cancel!
if hacker_signed_in?
@earning.cancel!(current_hacker)
else
@earning.cancel!
end
redirect_to :back
end
......
......@@ -9,7 +9,7 @@ class Cancel < ActiveRecord::Base
belongs_to :hacker
# Benutzer der diese Buchung durchführt hat
belongs_to :user
belongs_to :user, :class_name => 'Hacker'
belongs_to(:subject, {
......
......@@ -20,8 +20,9 @@ class Earning < ActiveRecord::Base
})
def cancel!
def cancel!(hacker = nil)
self.create_cancel({
:user => hacker,
:subject => self,
:chronicle_text => "Korrektur: #{self.chronicle_text}"
})
......
......@@ -7,4 +7,7 @@ class Quest < ActiveRecord::Base
validates :points, :title, :presence => true
validates :points, :numericality => {:greater_than => 0}
def solve(hacker)
end
end
......@@ -21,8 +21,9 @@ class Redemption < ActiveRecord::Base
})
def cancel!
def cancel!(hacker = nil)
self.create_cancel({
:user => hacker,
:subject => self,
:chronicle_text => "Korrektur: #{self.chronicle_text}"
})
......
require 'spec_helper'
describe EarningsController do
let(:earning) { FactoryGirl.create(:earning) }
let(:hacker) { FactoryGirl.create(:hacker, :cool_kim) }
before do
request.env['HTTP_REFERER'] = 'test.de'
end
context 'not logged in' do
describe 'POST cancel' do
it 'should allow to cancel' do
earning.cancel.should be_blank
post :cancel, :id => earning.id
response.should be_redirect
earning.reload.cancel.should be_present
earning.cancel.user.should be_blank
end
end # POST cancel
end # not logged in
context 'logged in' do
before do
controller.stub(:current_hacker).and_return(hacker)
end
describe 'POST cancel' do
it 'should allow to cancel' do
earning.cancel.should be_blank
post :cancel, :id => earning.id
response.should be_redirect
earning.reload.cancel.should be_present
earning.cancel.user.should be_eql(hacker)
end
end # POST cancel
end # logged in
end
......@@ -8,5 +8,9 @@ FactoryGirl.define do
nickname { generate(:nickname) }
email { Faker::Internet.email }
password {'test1234'}
trait :cool_kim do
nickname 'KimCM'
end
end
end
......@@ -6,11 +6,22 @@ describe Earning do
})
end
let(:hacker) do
FactoryGirl.create(:hacker)
end
describe '#cancel!' do
it 'should create a cancel Object' do
earning.cancel.should be_blank
earning.cancel!.should be_true
earning.cancel.should be_present
Cancel.should have(1).cancel
end
it 'should cancel by a given user' do
earning.cancel!(hacker)
earning.cancel.should be_present
earning.cancel.user.should be(hacker)
end
end # #cancel!
end
require 'spec_helper'
describe Quest do
pending "add some examples to (or delete) #{__FILE__}"
let(:hacker) do
FactoryGirl.create(:hacker)
end
subject do
FactoryGirl.build(:quest)
end
describe '#solve' do
it 'should produce a reward' do
hacker.reload.should have(0).earnings
subject.solve(hacker)
hacker.reload.should have(1).earnings
end
it 'should produce text into reward'
it 'should assign reward to quest'
end # #solve
end
......@@ -15,6 +15,10 @@ describe Redemption do
let(:normal_redemption) do
FactoryGirl.create(:redemption)
end
let(:hacker) do
FactoryGirl.create(:hacker)
end
context 'associations' do
it 'should have a user which is instance of hacker' do
redemption.build_user.should be_kind_of(Hacker)
......@@ -35,5 +39,15 @@ describe Redemption do
normal_redemption.cancel!.should be_true
normal_redemption.cancel.should be_present
end
it 'should allow anonym cancel' do
normal_redemption.cancel!.should be_true
normal_redemption.cancel.user.should be_blank
end
it 'should allow to cancel as user' do
normal_redemption.cancel!(hacker).should be_true
normal_redemption.cancel.user.should be(hacker)
end
end # #cancel!
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