From b62606e7f11a92b7c7e74ef0241f2e5746e86b84 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Thu, 17 Apr 2014 05:36:29 +0530 Subject: [PATCH] Remove color_hexcode column from badge_types. --- app/models/badge_type.rb | 2 -- app/serializers/badge_type_serializer.rb | 2 +- config/locales/server.en.yml | 6 ------ db/fixtures/700_badge_types.rb | 9 +++------ ...140416235757_remove_color_hexcode_from_badge_types.rb | 5 +++++ spec/fabricators/badge_fabricator.rb | 1 - spec/models/badge_type.rb | 1 - test/javascripts/models/badge_test.js | 6 +++--- test/javascripts/models/user_badge_test.js | 4 ++-- 9 files changed, 14 insertions(+), 22 deletions(-) create mode 100644 db/migrate/20140416235757_remove_color_hexcode_from_badge_types.rb diff --git a/app/models/badge_type.rb b/app/models/badge_type.rb index ede440185..abebf9495 100644 --- a/app/models/badge_type.rb +++ b/app/models/badge_type.rb @@ -2,7 +2,6 @@ class BadgeType < ActiveRecord::Base has_many :badges validates :name, presence: true, uniqueness: true - validates :color_hexcode, presence: true end # == Schema Information @@ -11,7 +10,6 @@ end # # id :integer not null, primary key # name :string(255) not null -# color_hexcode :string(255) not null # created_at :datetime # updated_at :datetime # diff --git a/app/serializers/badge_type_serializer.rb b/app/serializers/badge_type_serializer.rb index bd6ed272d..199c99a37 100644 --- a/app/serializers/badge_type_serializer.rb +++ b/app/serializers/badge_type_serializer.rb @@ -1,3 +1,3 @@ class BadgeTypeSerializer < ApplicationSerializer - attributes :id, :name, :color_hexcode + attributes :id, :name end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 972386d71..ac2c6bd56 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1475,9 +1475,3 @@ en: message_to_blank: "message.to is blank" text_part_body_blank: "text_part.body is blank" body_blank: "body is blank" - - badges: - types: - gold: Gold - silver: Silver - bronze: Bronze diff --git a/db/fixtures/700_badge_types.rb b/db/fixtures/700_badge_types.rb index 475817e85..2cdec2b41 100644 --- a/db/fixtures/700_badge_types.rb +++ b/db/fixtures/700_badge_types.rb @@ -1,17 +1,14 @@ BadgeType.seed do |b| b.id = 1 - b.name = I18n.t('badges.types.gold') - b.color_hexcode = "ffd700" + b.name = "Gold" end BadgeType.seed do |b| b.id = 2 - b.name = I18n.t('badges.types.silver') - b.color_hexcode = "c0c0c0" + b.name = "Silver" end BadgeType.seed do |b| b.id = 3 - b.name = I18n.t('badges.types.bronze') - b.color_hexcode = "cd7f32" + b.name = "Bronze" end diff --git a/db/migrate/20140416235757_remove_color_hexcode_from_badge_types.rb b/db/migrate/20140416235757_remove_color_hexcode_from_badge_types.rb new file mode 100644 index 000000000..9a19c17a8 --- /dev/null +++ b/db/migrate/20140416235757_remove_color_hexcode_from_badge_types.rb @@ -0,0 +1,5 @@ +class RemoveColorHexcodeFromBadgeTypes < ActiveRecord::Migration + def change + remove_column :badge_types, :color_hexcode, :string + end +end diff --git a/spec/fabricators/badge_fabricator.rb b/spec/fabricators/badge_fabricator.rb index 7ba52d8b4..d3a5f78d7 100644 --- a/spec/fabricators/badge_fabricator.rb +++ b/spec/fabricators/badge_fabricator.rb @@ -1,6 +1,5 @@ Fabricator(:badge_type) do name { sequence(:name) {|i| "Silver #{i}" } } - color_hexcode "c0c0c0" end Fabricator(:badge) do diff --git a/spec/models/badge_type.rb b/spec/models/badge_type.rb index 9f152f0d8..552518e7c 100644 --- a/spec/models/badge_type.rb +++ b/spec/models/badge_type.rb @@ -5,6 +5,5 @@ describe BadgeType do it { should validate_presence_of :name } it { should validate_uniqueness_of :name } - it { should validate_presence_of :color_hexcode } end diff --git a/test/javascripts/models/badge_test.js b/test/javascripts/models/badge_test.js index dbd1c7549..a4365e352 100644 --- a/test/javascripts/models/badge_test.js +++ b/test/javascripts/models/badge_test.js @@ -26,7 +26,7 @@ test('translatedDescription', function() { }); test('createFromJson array', function() { - var badgesJson = {"badge_types":[{"id":6,"name":"Silver 1","color_hexcode":"#c0c0c0"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]}; + var badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]}; var badges = Discourse.Badge.createFromJson(badgesJson); @@ -36,7 +36,7 @@ test('createFromJson array', function() { }); test('createFromJson single', function() { - var badgeJson = {"badge_types":[{"id":6,"name":"Silver 1","color_hexcode":"#c0c0c0"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; + var badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; var badge = Discourse.Badge.createFromJson(badgeJson); @@ -44,7 +44,7 @@ test('createFromJson single', function() { }); test('updateFromJson', function() { - var badgeJson = {"badge_types":[{"id":6,"name":"Silver 1","color_hexcode":"#c0c0c0"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; + var badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; var badge = Discourse.Badge.create({name: "Badge 1"}); badge.updateFromJson(badgeJson); equal(badge.get('id'), 1126, "id is set"); diff --git a/test/javascripts/models/user_badge_test.js b/test/javascripts/models/user_badge_test.js index 9c7c94de6..589d34752 100644 --- a/test/javascripts/models/user_badge_test.js +++ b/test/javascripts/models/user_badge_test.js @@ -1,7 +1,7 @@ module("Discourse.UserBadge"); -var singleBadgeJson = {"badges":[{"id":874,"name":"Badge 2","description":null,"badge_type_id":7}],"badge_types":[{"id":7,"name":"Silver 2","color_hexcode":"#c0c0c0"}],"users":[{"id":13470,"username":"anne3","avatar_template":"//www.gravatar.com/avatar/a4151b1fd72089c54e2374565a87da7f.png?s={size}\u0026r=pg\u0026d=identicon"}],"user_badge":{"id":665,"granted_at":"2014-03-09T20:30:01.190-04:00","badge_id":874,"granted_by_id":13470}}, - multipleBadgesJson = {"badges":[{"id":880,"name":"Badge 8","description":null,"badge_type_id":13}],"badge_types":[{"id":13,"name":"Silver 8","color_hexcode":"#c0c0c0"}],"users":[],"user_badges":[{"id":668,"granted_at":"2014-03-09T20:30:01.420-04:00","badge_id":880,"granted_by_id":null}]}; +var singleBadgeJson = {"badges":[{"id":874,"name":"Badge 2","description":null,"badge_type_id":7}],"badge_types":[{"id":7,"name":"Silver 2"}],"users":[{"id":13470,"username":"anne3","avatar_template":"//www.gravatar.com/avatar/a4151b1fd72089c54e2374565a87da7f.png?s={size}\u0026r=pg\u0026d=identicon"}],"user_badge":{"id":665,"granted_at":"2014-03-09T20:30:01.190-04:00","badge_id":874,"granted_by_id":13470}}, + multipleBadgesJson = {"badges":[{"id":880,"name":"Badge 8","description":null,"badge_type_id":13}],"badge_types":[{"id":13,"name":"Silver 8"}],"users":[],"user_badges":[{"id":668,"granted_at":"2014-03-09T20:30:01.420-04:00","badge_id":880,"granted_by_id":null}]}; test('createFromJson single', function() { var userBadge = Discourse.UserBadge.createFromJson(singleBadgeJson);