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

cancel as a user

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