merges master and fixes conflicts
This commit is contained in:
36
spec/models/ahoy/data_source_spec.rb
Normal file
36
spec/models/ahoy/data_source_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Ahoy::DataSource do
|
||||
describe '#build' do
|
||||
before :each do
|
||||
time_1 = DateTime.parse("2015-01-01")
|
||||
time_2 = DateTime.parse("2015-01-02")
|
||||
time_3 = DateTime.parse("2015-01-03")
|
||||
|
||||
create :ahoy_event, name: 'foo', time: time_1
|
||||
create :ahoy_event, name: 'foo', time: time_1
|
||||
create :ahoy_event, name: 'foo', time: time_2
|
||||
create :ahoy_event, name: 'bar', time: time_1
|
||||
create :ahoy_event, name: 'bar', time: time_3
|
||||
create :ahoy_event, name: 'bar', time: time_3
|
||||
end
|
||||
|
||||
it 'should work without data sources' do
|
||||
ds = Ahoy::DataSource.new
|
||||
expect(ds.build).to eq x: []
|
||||
end
|
||||
|
||||
it 'should work with single data sources' do
|
||||
ds = Ahoy::DataSource.new
|
||||
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count
|
||||
expect(ds.build).to eq :x=>["2015-01-01", "2015-01-02"], "foo"=>[2, 1]
|
||||
end
|
||||
|
||||
it 'should combine data sources' do
|
||||
ds = Ahoy::DataSource.new
|
||||
ds.add 'foo', Ahoy::Event.where(name: 'foo').group_by_day(:time).count
|
||||
ds.add 'bar', Ahoy::Event.where(name: 'bar').group_by_day(:time).count
|
||||
expect(ds.build).to eq :x=>["2015-01-01", "2015-01-02", "2015-01-03"], "foo"=>[2, 1, 0], "bar"=>[1, 0, 2]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -143,4 +143,80 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe "official?" do
|
||||
it "is false when the user is not an official" do
|
||||
expect(subject.official_level).to eq(0)
|
||||
expect(subject.official?).to be false
|
||||
end
|
||||
|
||||
it "is true when the user is an official" do
|
||||
subject.official_level = 3
|
||||
subject.save
|
||||
expect(subject.official?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_official_position!" do
|
||||
it "is false when level not valid" do
|
||||
expect(subject.add_official_position!("Boss", 89)).to be false
|
||||
end
|
||||
|
||||
it "updates official position fields" do
|
||||
expect(subject).not_to be_official
|
||||
subject.add_official_position!("Veterinarian", 2)
|
||||
|
||||
expect(subject).to be_official
|
||||
expect(subject.official_position).to eq("Veterinarian")
|
||||
expect(subject.official_level).to eq(2)
|
||||
|
||||
subject.add_official_position!("Brain surgeon", 3)
|
||||
expect(subject.official_position).to eq("Brain surgeon")
|
||||
expect(subject.official_level).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_official_position!" do
|
||||
it "updates official position fields" do
|
||||
subject.add_official_position!("Brain surgeon", 3)
|
||||
expect(subject).to be_official
|
||||
|
||||
subject.remove_official_position!
|
||||
|
||||
expect(subject).not_to be_official
|
||||
expect(subject.official_position).to be_nil
|
||||
expect(subject.official_level).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "officials scope" do
|
||||
it "returns only users with official positions" do
|
||||
create(:user, official_position: "Mayor", official_level: 1)
|
||||
create(:user, official_position: "Director", official_level: 3)
|
||||
create(:user, official_position: "Math Teacher", official_level: 4)
|
||||
create(:user, official_position: "Manager", official_level: 5)
|
||||
2.times { create(:user) }
|
||||
|
||||
officials = User.officials
|
||||
expect(officials.size).to eq(4)
|
||||
officials.each do |user|
|
||||
expect(user.official_level).to be > 0
|
||||
expect(user.official_position).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "self.with_email" do
|
||||
it "find users by email" do
|
||||
user1 = create(:user, email: "larry@madrid.es")
|
||||
create(:user, email: "bird@madrid.es")
|
||||
search = User.with_email("larry@madrid.es")
|
||||
expect(search.size).to eq(1)
|
||||
expect(search.first).to eq(user1)
|
||||
end
|
||||
|
||||
it "returns no results if no email provided" do
|
||||
expect(User.with_email(" ").size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user