Commit 4ae41f61 authored by surma Lodur's avatar surma Lodur
Browse files

Rewards und Quests können ausgelöst werden

parent d6da8546
<div class="btn btn-default btn-lg col-md-2 quest-button">
<div class="row">
<div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= quest.image_url %>"> </span>
</div>
<div class="col-xs-7">
<%= quest.title %>
</div>
<div class="col-xs-2">
<%= quest.points %>
<a
data-method="post" rel="nofollow"
href="<%= solve_quest_path(:hacker => hacker, :quest => quest) %>"
>
<div class="btn btn-default btn-lg col-md-2 quest-button">
<div class="row">
<div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= quest.image_url %>"> </span>
</div>
<div class="col-xs-7">
<%= quest.title %>
</div>
<div class="col-xs-2">
<%= quest.points %>
</div>
</div>
</div>
</div>
</a>
<div class="btn btn-default col-md-3 reward-button">
<div class="row">
<div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= reward.image_url %>"> </span>
</div>
<div class="col-xs-7">
<%= reward.title %>
</div>
<div class="col-xs-2">
<%= reward.points %>
<a
data-method="post" rel="nofollow"
href="<%= earn_reward_path(:hacker => hacker, :reward => reward) %>"
>
<div class="btn btn-default col-md-3 reward-button">
<div class="row">
<div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= reward.image_url %>"> </span>
</div>
<div class="col-xs-7">
<%= reward.title %>
</div>
<div class="col-xs-2">
<%= reward.points %>
</div>
</div>
</div>
</div>
</a>
......@@ -33,12 +33,12 @@
<h2>Punkte erarbeitet</h2>
<div class="container-fluid">
<%= render :partial => 'quests', :locals => {:quests => @quests} %>
<%= render :partial => 'quests', :locals => {:quests => @quests, :hacker => @hacker} %>
</div>
<h2>Punkte einlösen</h2>
<div class="container-fluid">
<%= render :partial => 'rewards', :locals => {:rewards => @rewards} %>
<%= render :partial => 'rewards', :locals => {:rewards => @rewards, :hacker => @hacker} %>
</div>
<h2>Verlauf</h2>
......
......@@ -13,6 +13,15 @@
</div>
</nav>
<div class="container">
<% if flash[:success] %>
<div class="alert alert-success"><%= flash[:success] %></div>
<% end %>
<% if flash[:error] %>
<div class="alert alert-danger"><%= flash[:error] %></div>
<% end %>
<% if flash[:warning] %>
<div class="alert alert-warning"><%= flash[:warning] %></div>
<% end %>
<%= yield %>
</div>
......@@ -21,7 +30,7 @@
<nav class="navbar navbar-default navbar-fixed-bottom" role="navigation">
<div class="container">
<ul class="nav navbar-nav">
<li><%= login_or_username %> </li>
<%= li_login_or_userpanel %>
<li class="divider"></li>
<li><%= link_to 'Historie', chronicle_path %></li>
</ul>
......
......@@ -9,7 +9,13 @@ SpacePunkte::Application.routes.draw do
member do
post :solve
end
end
end # quests
resources :rewards, :only => [] do
member do
post :earn
end
end # rewards
end
end
......
# encoding: UTF-8
require 'spec_helper'
describe QuestsController do
let(:hacker) do
FactoryGirl.create(:hacker)
end
let(:user) do
FactoryGirl.create(:hacker)
end
let(:quest) do
FactoryGirl.create(:quest)
end
before do
request.env['HTTP_REFERER'] = 'test.de'
end
context 'not logged in' do
describe 'POST solve' do
it 'should solve a quest' do
hacker.earnings.should be_blank
post :solve, :id => hacker.id, :quest => quest.id
hacker.reload.should have(1).earnings
hacker.earnings.last.user.should be_blank
end
end # POST solve
end # not logged in
context 'logged in' do
before do
controller.stub(:current_hacker).and_return(user)
end
describe 'POST solve' do
it 'should solve a quest' do
hacker.earnings.should be_blank
post :solve, :id => hacker.id, :quest => quest.id
hacker.reload.should have(1).earnings
hacker.earnings.last.user.should be_eql(user)
end
end # POST solve
end # logged in
end
# encoding: UTF-8
require 'spec_helper'
describe RewardsController do
let(:hacker) do
FactoryGirl.create(:hacker)
end
let(:user) do
FactoryGirl.create(:hacker)
end
let(:reward) do
FactoryGirl.create(:reward)
end
before do
request.env['HTTP_REFERER'] = 'test.de'
end
context 'not logged in' do
describe 'POST earn' do
it 'should earn a reward' do
hacker.redemptions.should be_blank
post :earn, :id => hacker.id, :reward => reward.id
response.should be_redirect
hacker.reload.should have(1).redemptions
hacker.redemptions.last.user.should be_blank
end
end # POST earn
end # not logged in
context 'logged in' do
before do
controller.stub(:current_hacker).and_return(user)
end
describe 'POST earn' do
it 'should earn a reward' do
hacker.redemptions.should be_blank
post :earn, :id => hacker.id, :reward => reward.id
response.should be_redirect
hacker.reload.should have(1).redemptions
hacker.redemptions.last.user.should be_eql(user)
end
end # POST earn
end # logged in
end
require 'spec_helper'
describe Reward do
pending "add some examples to (or delete) #{__FILE__}"
let(:hacker) do
FactoryGirl.create(:hacker)
end
let(:user) do
FactoryGirl.create(:user)
end
subject do
FactoryGirl.create(:reward)
end
it 'should earn a reward' do
hacker.should have(0).redemptions
subject.earn(hacker)
hacker.reload.should have(1).redemptions
end
end
......@@ -7,6 +7,9 @@ require 'rspec/autorun'
require 'factory_girl_rails'
require 'ffaker'
require 'database_cleaner'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
......@@ -43,4 +46,18 @@ RSpec.configure do |config|
# --seed 1234
config.order = "random"
config.include Devise::TestHelpers, :type => :controller
DatabaseCleaner.strategy = :transaction
config.before(:all) do
DatabaseCleaner.clean_with :truncation
end
config.before do
DatabaseCleaner.start # usually this is called in setup of a test
end
config.after do
DatabaseCleaner.clean
end
end
Supports Markdown
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