-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added factory girl, facker, added factories, added specs for scope an…
…d relationship
- Loading branch information
1 parent
296803d
commit 50b386a
Showing
14 changed files
with
256 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FactoryGirl.define do | ||
sequence :email do |n| | ||
"#{Faker::Internet.user_name}#{n}@#{Faker::Internet.domain_name}" | ||
end | ||
|
||
sequence :user_name do |n| | ||
"#{Faker::Internet.user_name}#{n}" | ||
end | ||
|
||
sequence :random_word do |n| | ||
"#{Faker::Lorem.word}#{n}" | ||
end | ||
|
||
factory :event do | ||
short_code { generate(:random_word) } | ||
name Faker::Lorem.word | ||
end | ||
|
||
factory :organization do | ||
name Faker::Company.name | ||
end | ||
|
||
factory :job do | ||
title Faker::Lorem.sentence(3) | ||
end | ||
|
||
factory :project do | ||
name { generate(:random_word) } | ||
github_repo { generate(:random_word) } | ||
end | ||
|
||
factory :user do | ||
email { generate(:email) } | ||
password Faker::Internet.password | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
describe FavoriteProject do | ||
it { should belong_to(:project) } | ||
it { should belong_to(:user) } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
describe Job do | ||
it { should belong_to(:organization) } | ||
|
||
before(:each) do | ||
@organization = create(:organization) | ||
@job1 = create(:job, :organization_id => @organization.id, :expires_at => DateTime.now+1.day) | ||
@job2 = create(:job, :organization_id => @organization.id, :expires_at => DateTime.now-1.day) | ||
@job3 = create(:job, :organization_id => @organization.id) | ||
end | ||
|
||
describe "active scope" do | ||
|
||
it "should return jobs which not expires or does not have expires_at field" do | ||
expect(Job.active).to eq([@job1, @job3]) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,130 @@ | ||
require 'spec_helper' | ||
|
||
describe Organization do | ||
|
||
it { should have_many(:organization_metrics) } | ||
it { should have_many(:projects) } | ||
it { should have_many(:jobs) } | ||
it { should have_many(:sponsorships)} | ||
it { should validate_presence_of(:name) } | ||
|
||
context 'validations' do | ||
context "validations" do | ||
|
||
context 'if public submission' do | ||
before { subject.stub(:is_public_submission) { true } } | ||
before { subject.stub(:is_public_submission){true} } | ||
it { should validate_presence_of(:github_org) } | ||
end | ||
|
||
context 'if not public submission' do | ||
before { subject.stub(:is_public_submission) { false } } | ||
before { subject.stub(:is_public_submission){false} } | ||
it { should_not validate_presence_of(:github_org) } | ||
end | ||
|
||
context 'if not public submission, implicit' do | ||
it { should_not validate_presence_of(:github_org) } | ||
end | ||
|
||
end | ||
|
||
context "scopes" do | ||
|
||
before(:each) do | ||
@organization1 = create(:organization, :name => "Spritle") | ||
@organization2 = create(:organization, :name => "Foo") | ||
@project1 = create(:project, :organization_id => @organization1.id) | ||
@project2 = create(:project, :organization_id => @organization1.id, :is_active => false) | ||
@project3 = create(:project, :organization_id => @organization1.id, :is_approved => true) | ||
@job = create(:job, :organization_id => @organization1.id) | ||
end | ||
|
||
describe "approved scope" do | ||
it "should return all organization which has approved projects" do | ||
expect(Organization.approved).to eq([@organization1]) | ||
end | ||
end | ||
|
||
describe "featured scope" do | ||
it "should return all organization which has approved & active projects" do | ||
expect(Organization.featured).to eq([@organization1]) | ||
end | ||
end | ||
|
||
describe "hiring scope" do | ||
it "should return all organization which has jobs" do | ||
expect(Organization.hiring).to eq([@organization1]) | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
context "url wrangling" do | ||
|
||
let(:organization) { Organization.new(url: 'http://www.amazing.org', github_org: 'amazing')} | ||
|
||
context 'url wrangling' do | ||
let(:organization) { Organization.new(url: 'http://www.amazing.org', github_org: 'amazing') } | ||
describe "#display_url" do | ||
|
||
describe '#display_url' do | ||
it 'returns the hostname of its url' do | ||
it "returns the hostname of its url" do | ||
expect(organization.display_url).to eq('www.amazing.org') | ||
end | ||
|
||
it 'returns an empty string if its url is missing' do | ||
it "returns an empty string if its url is missing" do | ||
organization.stub(url: nil) | ||
expect(organization.display_url).to eq('') | ||
end | ||
|
||
end | ||
|
||
describe '#github_url' do | ||
it 'concatentates its github url' do | ||
describe "#github_url" do | ||
|
||
it "concatentates its github url" do | ||
expect(organization.github_url).to eq('https://github.com/amazing') | ||
end | ||
|
||
it 'returns an empty string if it has no github org' do | ||
it "returns an empty string if it has no github org" do | ||
organization.stub(github_org: nil) | ||
expect(organization.github_url).to be_nil | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
context 'logo deletion' do | ||
context "logo deletion" do | ||
|
||
let(:organization) { Organization.new } | ||
let(:logo) { double } | ||
|
||
before do | ||
organization.stub(:logo) { logo } | ||
end | ||
|
||
describe '#logo_delete' do | ||
it 'defaults its logo_delete flag' do | ||
describe "#logo_delete" do | ||
it "defaults its logo_delete flag" do | ||
expect(organization.logo_delete).to eq('0') | ||
end | ||
end | ||
end | ||
|
||
describe '#logo_delete=' do | ||
it 'sets its logo_delete flag' do | ||
describe "#logo_delete=" do | ||
it "sets its logo_delete flag" do | ||
organization.logo_delete = 'foo' | ||
expect(organization.logo_delete).to eq('foo') | ||
end | ||
end | ||
end | ||
|
||
describe '#delete_logo' do | ||
it 'clears its logo if its logo_delete flag is set to 1' do | ||
describe "#delete_logo" do | ||
it "clears its logo if its logo_delete flag is set to 1" do | ||
organization.stub(:logo_delete) { '1' } | ||
logo.should_receive(:clear) | ||
organization.send(:delete_logo) | ||
end | ||
it 'does not clear its logo if its logo_delete flag is not set to 1' do | ||
it "does not clear its logo if its logo_delete flag is not set to 1" do | ||
organization.stub(:logo_delete) { nil } | ||
logo.should_not_receive(:clear) | ||
organization.send(:delete_logo) | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe Service do | ||
it { should belong_to(:user) } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
describe Sponsorship do | ||
it { should belong_to(:organization) } | ||
it { should belong_to(:event) } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe Tag do | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
describe UserProfile do | ||
it { should belong_to(:user) } | ||
it { should ensure_length_of(:headline).is_at_most(128) } | ||
end |
Oops, something went wrong.