Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/sponsor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Sponsor < ActiveRecord::Base
validates :level, inclusion: { in: Sponsor.levels.keys }
validates :name, :address, :avatar, :website, :level, presence: true
validate :website_is_url, if: :website?
validates :number_of_coaches, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true }
validates :seats, presence: true, numericality: { greater_tha_or_equal_to: 0, only_integer: true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validates :seats, presence: true, numericality: { greater_tha_or_equal_to: 0, only_integer: true }
validates :seats, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true }


default_scope -> { order('updated_at desc') }
scope :active, -> { where.not(level: 'hidden') }
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/sponsors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

expect do
post :create, sponsor: {
name: 'name', website: 'https://example.com', seats: 40,
name: 'name', website: 'https://example.com', seats: 40, number_of_coaches: 1,
address: address, avatar: avatar
}
end.to change(Sponsor, :count).by(1)
Expand All @@ -48,7 +48,7 @@

expect do
post :create, sponsor: {
name: 'name', website: 'https://example.com', seats: 40,
name: 'name', website: 'https://example.com', seats: 40, number_of_coaches: 1,
address: address, avatar: avatar, contact_ids: [member.id, member1.id]
}
end.to change(Sponsor, :count).by(1)
Expand All @@ -60,7 +60,7 @@

expect do
post :create, sponsor: {
name: 'name', website: 'https://example.com', seats: 40,
name: 'name', website: 'https://example.com', seats: 40, number_of_coaches: 1,
address: address, avatar: avatar, contact_ids: [member.id, member1.id]
}
end.to change(Sponsor, :count).by(1)
Expand All @@ -72,7 +72,7 @@

expect do
post :create, sponsor: {
name: 'name', website: 'https://example.com', seats: 40,
name: 'name', website: 'https://example.com', seats: 40, number_of_coaches: 1,
address: Fabricate(:address, latitude: '54.47474', longitude: '-0.12345'),
avatar: avatar, members: []
}
Expand Down
2 changes: 2 additions & 0 deletions spec/fabricators/sponsor_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
website { "http://#{Faker::Internet.domain_name}" }
avatar { Rack::Test::UploadedFile.new(Rails.root.join('app', 'assets', 'images', 'sponsors', sponsor_image), 'image/png') }
address
seats { Faker::Number.between(from: 1, to: 50) }
number_of_coaches { Faker::Number.between(from: 1, to: 50) }
end

Fabricator(:sponsor_full, from: :sponsor) do
Expand Down
2 changes: 1 addition & 1 deletion spec/fabricators/workshop_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
workshop: workshop,
sponsor: Fabricate(:sponsor,
seats: transients[:student_count] || 10,
number_of_coaches: transients[:coach_count || 10]),
number_of_coaches: transients[:coach_count] || 10),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaoguiIherme do we need the closing parenthesis at the end of this line? I think the next line (11) closes the parenthesis opened on line 8.

host: true)
end

Expand Down
3 changes: 3 additions & 0 deletions spec/features/admin/manage_sponsor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
fill_in 'Website', with: 'https://www.sponsorname.com/'
attach_file('Avatar', Rails.root + 'spec/support/codebar-logo.png')
fill_in 'Student spots', with: 20
fill_in 'Coach spots', with: 1
select "Bronze", from: "Level"

click_on 'Create sponsor'
Expand All @@ -34,6 +35,7 @@
fill_in 'Website', with: 'https://www.sponsorname.com/'
attach_file('Avatar', Rails.root + 'spec/support/codebar-logo.png')
fill_in 'Student spots', with: 20
fill_in 'Coach spots', with: 1

click_on 'Create sponsor'

Expand All @@ -49,6 +51,7 @@
fill_in 'Website', with: 'https://www.sponsorname.com/'
attach_file('Avatar', Rails.root + 'spec/support/codebar-logo.png')
fill_in 'Student spots', with: 20
fill_in 'Coach spots', with: 1

click_on 'Create sponsor'

Expand Down
5 changes: 4 additions & 1 deletion spec/features/coach_accepting_invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
let(:reject_invitation_route) { reject_invitation_path(invitation) }
let(:accept_invitation_route) { accept_invitation_path(invitation) }

let(:set_no_available_slots) { invitation.workshop.host.update_attribute(:seats, 0) }
let(:set_no_available_slots) do
invitation.workshop.host.update_attribute(:seats, 0)
invitation.workshop.host.update_attribute(:number_of_coaches, 0)
end

before(:each) do
login(member)
Expand Down