Skip to content

Commit

Permalink
added trait for project factory, fixed style violation
Browse files Browse the repository at this point in the history
  • Loading branch information
PraveenVignesh committed Mar 13, 2015
1 parent 1adf5fe commit 7f6857c
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 148 deletions.
6 changes: 3 additions & 3 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'
require "spec_helper"

describe UsersController do
describe "GET 'new'" do
it 'returns http success' do
get 'new'
it "returns http success" do
get "new"
response.should be_success
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
factory :project do
name { generate(:random_word) }
github_repo { generate(:random_word) }

trait :inactive do
is_active false
end

trait :approved do
is_approved true
end
end

factory :user do
Expand Down
38 changes: 19 additions & 19 deletions spec/features/pages_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
require 'spec_helper'
require "spec_helper"

describe 'The basic content site', #:js => true,
describe "The basic content site", #:js => true,
type: :feature do
context 'pages' do
it 'displays landing page' do
visit '/'
page.should have_content('Ready to change the world?')
context "pages" do
it "displays landing page" do
visit "/"
page.should have_content("Ready to change the world?")
end

it 'displays projects page' do
visit '/projects'
page.should have_content('Projects')
it "displays projects page" do
visit "/projects"
page.should have_content("Projects")
end

it 'displays jobs page' do
visit '/jobs'
it "displays jobs page" do
visit "/jobs"
page.should have_content("Jobs You've Been Looking For")
end

it 'displays coder day page' do
visit '/coder_day'
page.should have_content('Coder Day of Service')
it "displays coder day page" do
visit "/coder_day"
page.should have_content("Coder Day of Service")
end

it 'displays our story page' do
visit '/our_story'
page.should have_content('Major Contributors')
it "displays our story page" do
visit "/our_story"
page.should have_content("Major Contributors")
end

it 'displays resources page' do
visit '/resources'
it "displays resources page" do
visit "/resources"
page.should have_content("We're not the only ones")
end
end
Expand Down
32 changes: 16 additions & 16 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'spec_helper'
require "spec_helper"

describe ApplicationHelper do
describe '#display_url' do
it 'returns the domain portion of a given url' do
describe "#display_url" do
it "returns the domain portion of a given url" do
expect(helper.display_url("http://www.foo.com/bar/12")).
to eq("www.foo.com/bar/12")
end
end

context 'logo retrieval' do
context "logo retrieval" do
let(:organization) { Organization.new }
let(:logo) { double }

describe '#find_logo' do
describe "#find_logo" do
it "returns an organization's attached logo if it exists" do
organization.stub(:logo) { logo }
logo.should_receive(:url).with(:medium)
Expand All @@ -21,39 +21,39 @@

it "returns an organizations's image_url if no attached logo exists" do
organization.stub(:logo) { nil }
organization.stub(:image_url) { 'foo.png' }
expect(helper.find_logo(organization)).to eq('foo.png')
organization.stub(:image_url) { "foo.png" }
expect(helper.find_logo(organization)).to eq("foo.png")
end
end

describe '#find_logo?' do
it 'returns true if an organization has a logo attachment' do
organization.stub(:logo) { 'something' }
describe "#find_logo?" do
it "returns true if an organization has a logo attachment" do
organization.stub(:logo) { "something" }
organization.stub(:image_url) { nil }
expect(helper.find_logo?(organization)).to be_true
end

it 'returns true if an organization has an image_url defined' do
it "returns true if an organization has an image_url defined" do
organization.stub(:logo) { nil }
organization.stub(:image_url) { 'foo.png' }
organization.stub(:image_url) { "foo.png" }
expect(helper.find_logo?(organization)).to be_true
end

it 'returns false if neither logo nor image_url are present' do
it "returns false if neither logo nor image_url are present" do
organization.stub(:logo) { nil }
organization.stub(:image_url) { nil }
expect(helper.find_logo?(organization)).to be_false
end
end
end

describe '#twitter_url' do
it 'returns twitter url for given non nil handle' do
describe "#twitter_url" do
it "returns twitter url for given non nil handle" do
helper.twitter_url("CodeMontage").
should eq("http://twitter.com/CodeMontage")
end

it 'returns nil when nil is given' do
it "returns nil when nil is given" do
helper.twitter_url(nil).should eq(nil)
end
end
Expand Down
46 changes: 23 additions & 23 deletions spec/helpers/project_controller_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
require 'spec_helper'
require "spec_helper"

describe ProjectControllerHelper do
describe '#code_later_url' do
describe "#code_later_url" do
let(:url) { helper.code_later_url }

before do
Date.stub(:tomorrow) { Date.parse('1971/12/17') }
Date.stub(:tomorrow) { Date.parse("1971/12/17") }
end

it 'returns a url with a start date parameter of tomorrow at 2pm' do
it "returns a url with a start date parameter of tomorrow at 2pm" do
url = helper.code_later_url
expected = '19711217T140000Z'
expected = "19711217T140000Z"
expect(url.include?(expected)).to be_true
end

it 'returns a url with an end date parameter of tomorrow at 6pm' do
it "returns a url with an end date parameter of tomorrow at 6pm" do
url = helper.code_later_url
expected = '19711217T180000Z'
expected = "19711217T180000Z"
expect(url.include?(expected)).to be_true
end
end

describe '#project_tags_link_list' do
describe "#project_tags_link_list" do
let(:project) do
Project.new(
organization_id: 1,
name: 'CodeMontage Platform',
github_repo: 'codemontage'
name: "CodeMontage Platform",
github_repo: "codemontage"
)
end

Expand All @@ -39,27 +39,27 @@
end
end

context 'given a technologies argument' do
context "given a technologies argument" do
let(:links_list) do
helper.project_tags_link_list(project, "technologies")
end

it 'returns a list of technology links' do
expect(links_list).to include('Ruby')
expect(links_list).to include('Rails')
expect(links_list).to include(projects_path(tags: 'Ruby'))
expect(links_list).to include(projects_path(tags: 'Rails'))
it "returns a list of technology links" do
expect(links_list).to include("Ruby")
expect(links_list).to include("Rails")
expect(links_list).to include(projects_path(tags: "Ruby"))
expect(links_list).to include(projects_path(tags: "Rails"))
end
end

context 'given a causes argument' do
let(:links_list) { helper.project_tags_link_list(project, 'causes') }
context "given a causes argument" do
let(:links_list) { helper.project_tags_link_list(project, "causes") }

it 'returns a list of cause links' do
expect(links_list).to include('Cause1')
expect(links_list).to include('Cause2')
expect(links_list).to include(projects_path(tags: 'Cause1'))
expect(links_list).to include(projects_path(tags: 'Cause2'))
it "returns a list of cause links" do
expect(links_list).to include("Cause1")
expect(links_list).to include("Cause2")
expect(links_list).to include(projects_path(tags: "Cause1"))
expect(links_list).to include(projects_path(tags: "Cause2"))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/organization_metric_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require "spec_helper"

describe OrganizationMetric do
it { should belong_to(:organization) }
Expand Down
78 changes: 39 additions & 39 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require "spec_helper"

describe Organization do
it { should have_many(:organization_metrics) }
Expand All @@ -7,107 +7,107 @@
it { should have_many(:sponsorships) }
it { should validate_presence_of(:name) }

context 'validations' do
context 'if public submission' do
context "validations" do
context "if public submission" do
before { subject.stub(:is_public_submission) { true } }
it { should validate_presence_of(:github_org) }
end

context 'if not public submission' do
context "if not public submission" do
before { subject.stub(:is_public_submission) { false } }
it { should_not validate_presence_of(:github_org) }
end

context 'if not public submission, implicit' do
context "if not public submission, implicit" do
it { should_not validate_presence_of(:github_org) }
end
end

context 'scopes' do
context "scopes" do
before(:each) do
@organization1 = create(:organization, name: 'Spritle')
@organization2 = create(:organization, name: 'Foo')
@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)
@project2 = create(:project, :inactive, organization_id: @organization1.id)
@project3 = create(:project, :approved, organization_id: @organization1.id)
@job = create(:job, organization_id: @organization1.id)
end

describe 'approved scope' do
it 'should return all organization which has approved projects' do
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 organizations which has approved & active projects' do
describe "featured scope" do
it "should return organizations 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
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
context "url wrangling" do
let(:organization) do
Organization.new(url: 'http://www.amazing.org', github_org: 'amazing')
Organization.new(url: "http://www.amazing.org", github_org: "amazing")
end

describe '#display_url' do
it 'returns the hostname of its url' do
expect(organization.display_url).to eq('www.amazing.org')
describe "#display_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('')
expect(organization.display_url).to eq("")
end
end

describe '#github_url' do
it 'concatentates its github url' do
expect(organization.github_url).to eq('https://github.com/amazing')
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
expect(organization.logo_delete).to eq('0')
describe "#logo_delete" do
it "defaults its logo_delete flag" do
expect(organization.logo_delete).to eq("0")
end
end

describe '#logo_delete=' do
it 'sets its logo_delete flag' do
organization.logo_delete = 'foo'
expect(organization.logo_delete).to eq('foo')
describe "#logo_delete=" do
it "sets its logo_delete flag" do
organization.logo_delete = "foo"
expect(organization.logo_delete).to eq("foo")
end
end

describe '#delete_logo' do
it 'clears its logo if its logo_delete flag is set to 1' do
organization.stub(:logo_delete) { '1' }
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)
Expand Down
Loading

0 comments on commit 7f6857c

Please sign in to comment.