added counter

This commit is contained in:
2015-10-19 08:25:26 +02:00
parent bffa85f28e
commit 2f45cbd558
5 changed files with 41 additions and 0 deletions
+17
View File
@@ -24,3 +24,20 @@ body
label.required
abbr
display: none
#counter
background-color: #3c763d
padding: 3px 6px
border: 1px solid #3c763d
border-radius: 5px
color: white
.counter_char
background-color: white
width: 20px
padding: 5px auto
border: 1px solid #3c763d
border-radius: 5px
display: inline-block
text-align: center
color: #3c763d
+7
View File
@@ -3,6 +3,8 @@ class Supporter
include Mongoid::Timestamps
include Geocoder::Model::Mongoid
COUNTER_START = 1331
geocoded_by :address
after_validation :geocode # auto-fetch coordinates
@@ -25,6 +27,11 @@ class Supporter
validates :support, presence: true
validates :age_category, presence: true
def self.counter
actual = count.to_i
actual > COUNTER_START ? actual : COUNTER_START
end
def address
"#{street}, #{zip}, #{city}, Switzerland"
end
+1
View File
@@ -8,4 +8,5 @@ html
/ = console if Rails.env.development?
.container
= render 'shared/flashes'
= render 'shared/counter'
= yield
+4
View File
@@ -0,0 +1,4 @@
#counter.pull-right
| Unterstützer:
- Supporter.counter.to_s.split('').each do |x|
.counter_char= x
+12
View File
@@ -10,4 +10,16 @@ describe Supporter do
it { is_expected.to validate_uniqueness_of(:email) }
it { is_expected.to validate_presence_of(:support) }
it { is_expected.to validate_presence_of(:age_category) }
describe '.counter' do
it 'counts only from a certain number on' do
allow(Supporter).to receive(:count) { 12 }
expect(Supporter.counter).to eq Supporter::COUNTER_START
allow(Supporter).to receive(:count) { Supporter::COUNTER_START + 12 }
expect(Supporter.counter).to eq Supporter::COUNTER_START + 12
end
end
end