added counter
This commit is contained in:
@@ -24,3 +24,20 @@ body
|
|||||||
label.required
|
label.required
|
||||||
abbr
|
abbr
|
||||||
display: none
|
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
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ class Supporter
|
|||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include Geocoder::Model::Mongoid
|
include Geocoder::Model::Mongoid
|
||||||
|
|
||||||
|
COUNTER_START = 1331
|
||||||
|
|
||||||
geocoded_by :address
|
geocoded_by :address
|
||||||
after_validation :geocode # auto-fetch coordinates
|
after_validation :geocode # auto-fetch coordinates
|
||||||
|
|
||||||
@@ -25,6 +27,11 @@ class Supporter
|
|||||||
validates :support, presence: true
|
validates :support, presence: true
|
||||||
validates :age_category, presence: true
|
validates :age_category, presence: true
|
||||||
|
|
||||||
|
def self.counter
|
||||||
|
actual = count.to_i
|
||||||
|
actual > COUNTER_START ? actual : COUNTER_START
|
||||||
|
end
|
||||||
|
|
||||||
def address
|
def address
|
||||||
"#{street}, #{zip}, #{city}, Switzerland"
|
"#{street}, #{zip}, #{city}, Switzerland"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ html
|
|||||||
/ = console if Rails.env.development?
|
/ = console if Rails.env.development?
|
||||||
.container
|
.container
|
||||||
= render 'shared/flashes'
|
= render 'shared/flashes'
|
||||||
|
= render 'shared/counter'
|
||||||
= yield
|
= yield
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#counter.pull-right
|
||||||
|
| Unterstützer:
|
||||||
|
- Supporter.counter.to_s.split('').each do |x|
|
||||||
|
.counter_char= x
|
||||||
@@ -10,4 +10,16 @@ describe Supporter do
|
|||||||
it { is_expected.to validate_uniqueness_of(:email) }
|
it { is_expected.to validate_uniqueness_of(:email) }
|
||||||
it { is_expected.to validate_presence_of(:support) }
|
it { is_expected.to validate_presence_of(:support) }
|
||||||
it { is_expected.to validate_presence_of(:age_category) }
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user