Commit 0b2e64e7 authored by Kim Meiser's avatar Kim Meiser
parents 57fd4cbd dbef0f9a
......@@ -2,6 +2,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
gem 'rails-i18n'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
......
......@@ -129,6 +129,9 @@ GEM
activesupport (>= 3.0)
choice (~> 0.1.6)
ruby-graphviz (~> 1.0.4)
rails-i18n (4.0.1)
i18n (~> 0.6)
rails (~> 4.0)
railties (4.0.2)
actionpack (= 4.0.2)
activesupport (= 4.0.2)
......@@ -215,6 +218,7 @@ DEPENDENCIES
kaminari
rails (= 4.0.2)
rails-erd
rails-i18n
rspec-rails
sass-rails (~> 4.0.0)
sdoc
......
......@@ -14,4 +14,14 @@
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap/tooltip
//= require bootstrap/popover
//= require_tree .
jQuery(document).ready(function(){
jQuery('[data-popup-top]').popover({
placement: 'top',
trigger: 'hover',
delay: {show: 1000, hide: 0}
});
});
# encoding: UTF-8
module ApplicationHelper
require 'digest/md5'
......@@ -17,4 +18,15 @@ module ApplicationHelper
content_tag(:li, link_to('Ausloggen', destroy_hacker_session_path, :method => :delete))
end
end
def triggered_by(hacker)
html = "ausgelöst durch "
if hacker
# html << image_tag(gravatar_url_for(hacker.email, 24))
html << hacker.nickname
else
html << "Anonymous"
end
return escape_javascript(html)#.html_safe
end
end
......@@ -12,6 +12,7 @@ class Quest < ActiveRecord::Base
hacker.earnings.create({
:user => user,
:points => self.points,
:quest => self,
:chronicle_text => self.title
})
end # #solve
......
......@@ -3,8 +3,25 @@
## (Eintausch gegen Naturalien)
class Redemption < ActiveRecord::Base
###################
## Validations ##
###################
validates :hacker_id, :reward_id, :points, :presence => true
validates :points, :numericality => {:greater_than => 0}
validates(:hacker_remaining_points, {
:numericality => {
:greater_than_or_equal_to => lambda {|i| i.points }
},
:on => :create
})
#####################
## Associactions ##
#####################
# Begünstigter: Derjenige, dessen "Punktekonto" diese Punkte abgezogen werden
# Beispiel: User x ist angemeldet und löst für hacker y 10 Punkte ein,
......@@ -21,6 +38,12 @@ class Redemption < ActiveRecord::Base
})
delegate(:remaining_points, {
:to => :hacker,
:prefix => :hacker
})
def cancel!(hacker = nil)
self.create_cancel({
:user => hacker,
......
<div class="list-group-item row list-group-item-success">
<div class="list-group-item row list-group-item-success"
data-popup-top="true" data-content="<%= triggered_by(entry.user) %>"
>
<span class="col-md-1">
<%= image_tag gravatar_url_for(entry.hacker.email, 24) %>
</span>
......
<div class="list-group-item list-group-item-warning row">
<div class="list-group-item list-group-item-warning row"
data-popup-top="true" data-content="<%= triggered_by(entry.user) %>"
>
<span class="col-md-1">
<%= image_tag gravatar_url_for(entry.hacker.email, 24) %>
</span>
......
<div class="list-group-item list-group-item-danger row">
<div class="list-group-item list-group-item-danger row"
data-popup-top="true" data-content="<%= triggered_by(entry.user) %>"
>
<span class="col-md-1">
</span>
<span class="col-md-2">
......@@ -7,7 +9,8 @@
<span class="col-md-3">
<%= l(entry.created_at, :format => :short) %>
</span>
<span class="col-md-6">
<span class="col-md-6"
>
<%= entry.chronicle_text %>
</span>
</div>
<div class="list-group-item list-group-item-danger row">
<div class="list-group-item list-group-item-danger row"
data-popup-top="true" data-content="<%= triggered_by(entry.user) %>"
>
<span class="col-md-1">
</span>
<span class="col-md-1 col-md-offset-1">
......
......@@ -18,6 +18,6 @@ module SpacePunkte
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.default_locale = :de
end
end
de:
activerecord:
attributes:
redemption:
hacker_remaining_points: Verbleibende Punkte
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
devise:
confirmations:
confirmed: "Your account was successfully confirmed."
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account is not activated yet."
invalid: "Invalid email or password."
locked: "Your account is locked."
last_attempt: "You have one more attempt before your account will be locked."
not_found_in_database: "Invalid email or password."
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your account before continuing."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock Instructions"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
passwords:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password was changed successfully. You are now signed in."
updated_not_active: "Your password was changed successfully."
registrations:
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have signed up successfully."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
updated: "You updated your account successfully."
sessions:
signed_in: "Signed in successfully."
signed_out: "Signed out successfully."
unlocks:
send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
errors:
messages:
already_confirmed: "was already confirmed, please try signing in"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
expired: "has expired, please request a new one"
not_found: "not found"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
......@@ -16,6 +16,7 @@ describe RewardsController do
before do
request.env['HTTP_REFERER'] = 'test.de'
Redemption.any_instance.stub(:hacker_remaining_points).and_return(700)
end
context 'not logged in' do
......
......@@ -12,5 +12,11 @@ FactoryGirl.define do
trait :cool_kim do
nickname 'KimCM'
end
trait :with_earning do
earnings {[FactoryGirl.build(:earning, :hacker => nil)]}
end
factory :hacker_with_earning, :traits => [:with_earning]
end
end
FactoryGirl.define do
factory :redemption do
points { [1,10,50,150].shuffle.first}
association :hacker, :factory => :hacker
association :hacker, :factory => :hacker_with_earning
association :user, :factory => :hacker
association :reward, :factory => :reward
end
......
......@@ -7,6 +7,7 @@ describe Hacker do
FactoryGirl.create(:hacker)
end
let(:redemptions) do
[FactoryGirl.create(:redemption, {
:hacker => hacker, :points => 10
......@@ -24,6 +25,7 @@ describe Hacker do
describe '#all_redeemed_points' do
before do
Redemption.any_instance.stub(:hacker_remaining_points).and_return(700)
redemptions
end
......
......@@ -14,9 +14,10 @@ describe Quest do
describe '#solve' do
it 'should produce a reward' do
hacker.reload.should have(0).earnings
hacker.should have(0).earnings
subject.solve(hacker)
hacker.reload.should have(1).earnings
hacker.earnings.first.quest.should be_eql(subject)
end
it 'should produce text into reward'
......
......@@ -19,6 +19,11 @@ describe Redemption do
let(:hacker) do
FactoryGirl.create(:hacker)
end
before do
Redemption.any_instance.stub(:hacker_remaining_points).and_return(700)
end
context 'associations' do
it 'should have a user which is instance of hacker' do
redemption.build_user.should be_kind_of(Hacker)
......
......@@ -9,13 +9,31 @@ describe Reward do
FactoryGirl.create(:user)
end
let(:earning) do
FactoryGirl.create(:earning, {
:hacker => hacker
})
end
subject do
FactoryGirl.create(:reward)
end
it 'should earn a reward' do
it 'should not earn a reward' do
hacker.should have(0).redemptions
subject.earn(hacker)
hacker.reload.should have(1).redemptions
end
hacker.reload.should have(0).redemptions
end
context 'with earning' do
before do
earning
end
it 'should earn a reward' do
hacker.should have(0).redemptions
subject.earn(hacker)
hacker.reload.should have(1).redemptions
end
end # with earning
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