Skip to content

Commit

Permalink
Add ActiveRecord::Enum columns to teams and players
Browse files Browse the repository at this point in the history
There are no tests for the active_record_enum type. Now the integration
tests at least test them implicitly
  • Loading branch information
tiii committed Jul 28, 2016
1 parent 9ab7b91 commit 10bff49
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions spec/dummy_app/app/active_record/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Player < ActiveRecord::Base
record.errors.add(:base, 'Player is cheating') if value.to_s =~ /on steroids/
end

if ::Rails.version >= '4.1'
enum formation: {start: 'start', substitute: 'substitute'}
end

before_destroy :destroy_hook

def destroy_hook; end
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy_app/app/active_record/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Team < ActiveRecord::Base
validates_numericality_of :revenue, allow_nil: true
belongs_to :division

if ::Rails.version >= '4.1'
enum main_sponsor: [:no_sponsor, :food_factory, :transportation_company, :bank, :energy_producer]
end

def player_names_truncated
players.collect(&:name).join(', ')[0..32]
end
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/app/locales/models.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ en:
name: Their Name
team:
manager: Team Manager
main_sponsor: Main Sponsor
fans: Some Fans
mongoid:
*en_attributes
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/app/mongoid/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Player
field :born_on, type: Date
field :notes, type: String
field :suspended, type: Boolean, default: false
field :formation, type: String

validates_presence_of(:name)
validates_numericality_of(:number, only_integer: true)
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/app/mongoid/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Team
field :revenue, type: BigDecimal
field :color, type: String
field :custom_field, type: String
field :main_sponsor, type: Integer

has_many :players, inverse_of: :team, order: :_id.asc
has_and_belongs_to_many :fans
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddMainSponsorToTeams < MigrationBase
def change
add_column :teams, :main_sponsor, :integer, default: 0, null: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFormationToPlayers < MigrationBase
def change
add_column :players, :formation, :string, default: 'substitute', null: false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
click_button 'Export to csv'
csv = CSV.parse page.driver.response.body.force_encoding('utf-8') # comes through as us-ascii on some platforms
expect(csv[0]).to match_array ['Id', 'Created at', 'Updated at', 'Deleted at', 'Name', 'Position',
'Number', 'Retired', 'Injured', 'Born on', 'Notes', 'Suspended', 'Id [Team]', 'Created at [Team]',
'Number', 'Retired', 'Injured', 'Born on', 'Notes', 'Suspended', 'Formation', 'Id [Team]', 'Created at [Team]',
'Updated at [Team]', 'Name [Team]', 'Logo url [Team]', 'Team Manager [Team]', 'Ballpark [Team]',
'Mascot [Team]', 'Founded [Team]', 'Wins [Team]', 'Losses [Team]', 'Win percentage [Team]',
'Revenue [Team]', 'Color [Team]', 'Custom field [Team]', 'Id [Draft]', 'Created at [Draft]',
'Revenue [Team]', 'Color [Team]', 'Custom field [Team]', 'Main Sponsor [Team]', 'Id [Draft]', 'Created at [Draft]',
'Updated at [Draft]', 'Date [Draft]', 'Round [Draft]', 'Pick [Draft]', 'Overall [Draft]',
'College [Draft]', 'Notes [Draft]', 'Id [Comments]', 'Content [Comments]', 'Created at [Comments]',
'Updated at [Comments]']
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_admin/config/sections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
expect(RailsAdmin.config(Team).edit.visible_groups.collect { |g| g.visible_fields.collect(&:name) }).to eq([[:name], [:founded, :wins]])
expect(RailsAdmin.config(Team).create.visible_groups.collect { |g| g.visible_fields.collect(&:name) }).to eq([[:name], [:founded, :wins]])
expect(RailsAdmin.config(Team).update.visible_groups.collect { |g| g.visible_fields.collect(&:name) }).to eq([[:name], [:founded], [:wins], [:losses]])
expect(RailsAdmin.config(Team).visible_groups.collect { |g| g.visible_fields.collect(&:name) }.flatten.count).to eq(19)
expect(RailsAdmin.config(Team).export.visible_groups.collect { |g| g.visible_fields.collect(&:name) }.flatten.count).to eq(19)
expect(RailsAdmin.config(Team).visible_groups.collect { |g| g.visible_fields.collect(&:name) }.flatten.count).to eq(20)
expect(RailsAdmin.config(Team).export.visible_groups.collect { |g| g.visible_fields.collect(&:name) }.flatten.count).to eq(20)
end
end
end

0 comments on commit 10bff49

Please sign in to comment.