Last active
February 16, 2016 12:44
-
-
Save durexlw/4984b0adc8e45c61cb1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :contract do | |
sequence(:persnr) { |n| "#{n}" } | |
sequence(:naam) { |n| "naam #{n}" } | |
sequence(:voornaam) { |n| "voornaam #{n}" } | |
sequence(:maand) { |n| n } | |
sequence(:maand_teller) { |n| n } | |
jaar 2015 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class ContractSerializerKoppenPerMaand < ActiveSupport::TestCase | |
include FactoryGirl::Syntax::Methods | |
attr_reader :contract | |
setup do | |
12.times do | |
create(:contract) | |
end | |
@stats = ContractSerializer.contracts_per_month | |
end | |
it "should retreive the data in the form of an array" do | |
assert false | |
assert_includes @stats.keys, :aantal_koppen | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contract < ActiveRecord::Base | |
scope :contracts_per_month, -> { select("jaar, maand, count(persnr) as aantal_koppen").group("maand_teller") } | |
def self.serialize_for_graph | |
ContractSerializer.contracts_per_month.to_json | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContractSerializer | |
def self.contracts_per_month | |
contracts = Contract.contracts_per_month | |
debug = contracts.map { |c| ["#{c.jaar}/#{c.maand}", c.aantal_koppen] } | |
byebug | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/workspace (master) $ rake test test/units/contract_serializer/koppen_per_maand.rb | |
Run options: --seed 32154 | |
# Running: | |
[3, 12] in /home/ubuntu/workspace/app/lib/contract_serializer.rb | |
3: contracts = Contract.contracts_per_month | |
4: | |
5: debug = contracts.map { |c| ["#{c.jaar}/#{c.maand}", c.aantal_koppen] } | |
6: | |
7: byebug | |
=> 8: end | |
9: | |
10: def self.koppen_per_maand_with_annotation | |
11: contracts = Contract.koppen_per_maand | |
12: | |
(byebug) contracts.last.inspect | |
#<Contract id: nil, jaar: 2015, maand: 12> | |
(byebug) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment