Skip to content

Commit 6ae303d

Browse files
Eduardo Silva Araújorafamanzo
Eduardo Silva Araújo
authored andcommitted
Rename KalibroModule granlrty to granularity
We were using granlrty to avoid conflicts with Java implementation of Kalibro. After renaming, we have found out that overriding ActiveRecord attributes may lead to errors on the database persistance. For more information, see: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord%3a%3aBase-label-Overwriting+default+accessors As well, unit tests were missing for the getter and setter. They were created. Signed off by: Rafael Reggiani Manzo <[email protected]>
1 parent 78cb73c commit 6ae303d

6 files changed

+45
-6
lines changed

app/models/kalibro_module.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def parent
2727
end
2828

2929
def granularity=(value)
30-
self.granlrty = value.to_s
30+
super(value.to_s)
3131
end
3232

3333
def granularity
34-
KalibroClient::Entities::Miscellaneous::Granularity.new(self.granlrty.to_sym)
34+
KalibroClient::Entities::Miscellaneous::Granularity.new(super.to_sym)
3535
end
3636

3737
def to_s

app/models/module_result.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.find_by_module_and_processing(kalibro_module, processing)
1313
ModuleResult.joins(:kalibro_module).
1414
where(processing: processing).
1515
where("kalibro_modules.long_name" => kalibro_module.long_name).
16-
where("kalibro_modules.granlrty" => kalibro_module.granularity.to_s).first
16+
where("kalibro_modules.granularity" => kalibro_module.granularity.to_s).first
1717
end
1818

1919
def metric_result_for(metric)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RenameKalibroModuleGranlrtyToGranularity < ActiveRecord::Migration
2+
def change
3+
rename_column :kalibro_modules, :granlrty, :granularity
4+
end
5+
end

db/schema.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20150909210112) do
14+
ActiveRecord::Schema.define(version: 20151002172231) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -34,7 +34,7 @@
3434

3535
create_table "kalibro_modules", force: :cascade do |t|
3636
t.string "long_name", limit: 255
37-
t.string "granlrty", limit: 255
37+
t.string "granularity", limit: 255
3838
t.datetime "created_at"
3939
t.datetime "updated_at"
4040
t.integer "module_result_id"

spec/models/kalibro_module_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
describe KalibroModule, :type => :model do
44

5+
=begin
6+
describe 'initialize' do
7+
let(:long_name) { 'app.model.kalibro_module' }
8+
let(:granularity) { 'CLASS' }
9+
10+
it 'is expected to set long_name and granularity' do
11+
subject = KalibroModule.new(long_name: long_name, granularity: granularity)
12+
13+
expect(subject.long_name).to eq(long_name)
14+
expect(subject.granularity).to eq(KalibroClient::Entities::Miscellaneous::Granularity.new(granularity.to_sym))
15+
end
16+
end
17+
=end
518
describe 'associations' do
619
it { is_expected.to belong_to(:module_result) }
720
end
@@ -72,5 +85,26 @@
7285
end
7386
end
7487
end
88+
89+
describe 'granularity=' do
90+
91+
subject { FactoryGirl.build( :kalibro_module ) }
92+
93+
it "is expected to convert the value to string" do
94+
granularity = mock("granularity")
95+
granularity.expects(:to_s).returns("CLASS")
96+
97+
subject.granularity = granularity
98+
end
99+
end
100+
101+
describe 'granularity' do
102+
103+
subject { FactoryGirl.build( :kalibro_module ) }
104+
105+
it 'is expected to return a KalibroClient::Entities::Miscellaneous::Granularity instance' do
106+
expect(subject.granularity).to be_a(KalibroClient::Entities::Miscellaneous::Granularity)
107+
end
108+
end
75109
end
76110
end

spec/models/module_result_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
before :each do
7676
name_filtered_results = Object.new
7777
name_filtered_results.expects(:where).
78-
with("kalibro_modules.granlrty" => kalibro_module.granularity.to_s).
78+
with("kalibro_modules.granularity" => kalibro_module.granularity.to_s).
7979
returns([module_result])
8080

8181
processing_filtered_results = Object.new

0 commit comments

Comments
 (0)