Skip to content

Commit ca4162c

Browse files
committed
Don't automatically add id to all settings models
It doesn't really make sense for "singleton" models like Campfire global settings, it's better to declare id everywhere when we need it.
1 parent 32a8f8d commit ca4162c

File tree

5 files changed

+4
-10
lines changed

5 files changed

+4
-10
lines changed

lib/travis/model/repository/settings.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Repository::Settings < Travis::Settings
88
class SshKey < Travis::Settings::Model
9+
attribute :id, String
910
attribute :name, String
1011
attribute :content, Travis::Settings::EncryptedValue
1112

@@ -17,6 +18,7 @@ class SshKeys < Collection
1718
end
1819

1920
class EnvVar < Travis::Settings::Model
21+
attribute :id, String
2022
attribute :name, String
2123
attribute :value, Travis::Settings::EncryptedValue
2224
attribute :public, Boolean, default: false
@@ -28,12 +30,9 @@ class EnvVars < Collection
2830
model EnvVar
2931
end
3032

31-
32-
3333
attribute :ssh_keys, SshKeys.for_virtus
3434
attribute :env_vars, EnvVars.for_virtus
3535

36-
3736
attribute :builds_only_with_travis_yml, Boolean, default: false
3837
attribute :build_pushes, Boolean, default: true
3938
attribute :build_pull_requests, Boolean, default: true

lib/travis/settings/model.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class Model
99
include ActiveModel::Validations
1010
include ActiveModel::Serialization
1111

12-
attribute :id, String
13-
1412
class Errors < ActiveModel::Errors
1513
# Default behavior of Errors in Active Model is to
1614
# translate symbolized message into full text message,

spec/travis/settings/collection_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@model_class = Class.new(Travis::Settings::Model) {
88
attribute :description
99

10+
attribute :id, String
1011
attribute :secret, Travis::Settings::EncryptedValue
1112
}
1213

spec/travis/settings/model_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ def name
8787
model.name.should == 'PIOTR'
8888
end
8989

90-
it 'automatically generates id attribute' do
91-
model = model_class.new(id: 'foobar')
92-
model.id.should == 'foobar'
93-
end
94-
9590
it 'handles validations' do
9691
model_class = Class.new(described_class) do
9792
attribute :name

spec/travis/settings_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
describe 'to_hash' do
9191
it 'returns registered collections and all attributes' do
9292
model_class = Class.new(Travis::Settings::Model) {
93+
attribute :id, String
9394
attribute :name, String
9495
attribute :content, Travis::Settings::EncryptedValue
9596
}

0 commit comments

Comments
 (0)