Sha256: 5616be1fcd890c9ded8891f5e83b494a4a1b2b0a752970fa12ede40e7e49b708
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
shared_examples "an extractor" do AGGREGATES = [:sum, :minimum, :maximum, :average] let(:expected_data_size) { 14 } ["sql", "normal"].each do |type| AGGREGATES.each do |agg| context "a #{type} metric with aggregate #{agg}" do let(:metric) do Class.new(Prosperity::Metric) do if type == 'sql' sql "SELECT * FROM users" else scope { User } end aggregate { send(agg, :value) } end.new end describe "#to_a" do let(:data) { subject.to_a } it "returns the one entry per period" do expect(data.size).to eq(expected_data_size) end end end end context "a sql metric with default aggregate" do let(:metric) do Class.new(Prosperity::Metric) do if type == 'sql' sql "SELECT * FROM users" else scope { User } end end.new end describe "#to_a" do let(:data) { subject.to_a } it "returns the one entry per period" do expect(data.size).to eq(expected_data_size) end end end end context "a full SQL metric" do let(:metric) do Class.new(Prosperity::Metric) do sql "SELECT * FROM users" group_by "created_at" aggregate { "SUM(value)" } end.new end describe "#to_a" do let(:data) { subject.to_a } it "returns the one entry per period" do expect(data.size).to eq(expected_data_size) end end end context "a normal metric with a sql aggregate" do let(:metric) do Class.new(Prosperity::Metric) do scope { User } group_by "created_at" aggregate { "SUM(value)" } end.new end describe "#to_a" do it "returns the correct data" do data.size.should == expected_data_size end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prosperity-0.0.11 | spec/support/shared/extractors.rb |