Commit 34f9be8ae029dba9a9092ed6148770b3af641378

Authored by Diego Camarinha
1 parent 6810ee7c

Fixed some unit tests

Still need to complete the refactoring of ReadingGroupOwnership and
KalibroConfigurationOwnership

Signed off by: Pedro Scocco <pedroscocco@gmail.com>
app/controllers/kalibro_configurations_controller.rb
@@ -12,7 +12,7 @@ class KalibroConfigurationsController &lt; ApplicationController @@ -12,7 +12,7 @@ class KalibroConfigurationsController &lt; ApplicationController
12 # GET /kalibro_configurations 12 # GET /kalibro_configurations
13 # GET /kalibro_configurations.json 13 # GET /kalibro_configurations.json
14 def index 14 def index
15 - @kalibro_configurations = KalibroConfigurationAttributes.where(hidden: false).map { |cfg_attr| 15 + @kalibro_configurations = KalibroConfigurationAttributes.where(public: true).map { |cfg_attr|
16 KalibroConfiguration.find(cfg_attr.kalibro_configuration_id) 16 KalibroConfiguration.find(cfg_attr.kalibro_configuration_id)
17 }.compact 17 }.compact
18 end 18 end
app/controllers/reading_groups_controller.rb
@@ -13,7 +13,7 @@ class ReadingGroupsController &lt; ApplicationController @@ -13,7 +13,7 @@ class ReadingGroupsController &lt; ApplicationController
13 # GET /reading_groups 13 # GET /reading_groups
14 # GET /reading_groups.json 14 # GET /reading_groups.json
15 def index 15 def index
16 - @reading_groups = ReadingGroup.visible 16 + @reading_groups = ReadingGroup.public
17 end 17 end
18 18
19 # POST /reading_groups 19 # POST /reading_groups
@@ -39,19 +39,19 @@ ActiveRecord::Schema.define(version: 20150511181035) do @@ -39,19 +39,19 @@ ActiveRecord::Schema.define(version: 20150511181035) do
39 end 39 end
40 40
41 create_table "users", force: :cascade do |t| 41 create_table "users", force: :cascade do |t|
42 - t.string "name", default: "", null: false  
43 - t.string "email", default: "", null: false 42 + t.string "name", limit: 255, default: "", null: false
  43 + t.string "email", limit: 255, default: "", null: false
44 t.datetime "created_at" 44 t.datetime "created_at"
45 t.datetime "updated_at" 45 t.datetime "updated_at"
46 - t.string "encrypted_password", default: "", null: false  
47 - t.string "reset_password_token" 46 + t.string "encrypted_password", limit: 255, default: "", null: false
  47 + t.string "reset_password_token", limit: 255
48 t.datetime "reset_password_sent_at" 48 t.datetime "reset_password_sent_at"
49 t.datetime "remember_created_at" 49 t.datetime "remember_created_at"
50 - t.integer "sign_in_count", default: 0 50 + t.integer "sign_in_count", default: 0
51 t.datetime "current_sign_in_at" 51 t.datetime "current_sign_in_at"
52 t.datetime "last_sign_in_at" 52 t.datetime "last_sign_in_at"
53 - t.string "current_sign_in_ip"  
54 - t.string "last_sign_in_ip" 53 + t.string "current_sign_in_ip", limit: 255
  54 + t.string "last_sign_in_ip", limit: 255
55 end 55 end
56 56
57 add_index "users", ["email"], name: "index_users_on_email", unique: true 57 add_index "users", ["email"], name: "index_users_on_email", unique: true
spec/controllers/compound_metric_configurations_controller_spec.rb
@@ -99,7 +99,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do @@ -99,7 +99,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
99 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s 99 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s
100 end 100 end
101 101
102 - xit { is_expected.to render_template(:edit) } 102 + it { is_expected.to render_template(:edit) }
103 end 103 end
104 104
105 context 'when the user does not own the compound metric configuration' do 105 context 'when the user does not own the compound metric configuration' do
@@ -107,7 +107,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do @@ -107,7 +107,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
107 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s 107 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s
108 end 108 end
109 109
110 - xit { is_expected.to redirect_to(kalibro_configurations_path(id: kalibro_configuration.id)) } 110 + it { is_expected.to redirect_to(kalibro_configurations_path(id: kalibro_configuration.id)) }
111 it { is_expected.to respond_with(:redirect) } 111 it { is_expected.to respond_with(:redirect) }
112 it { is_expected.to set_flash[:notice].to("You're not allowed to do this operation") } 112 it { is_expected.to set_flash[:notice].to("You're not allowed to do this operation") }
113 end 113 end
@@ -157,7 +157,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do @@ -157,7 +157,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
157 post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params 157 post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params
158 end 158 end
159 159
160 - xit { should render_template(:edit) } 160 + it { should render_template(:edit) }
161 end 161 end
162 end 162 end
163 163
spec/controllers/kalibro_configurations_controller_spec.rb
@@ -132,13 +132,15 @@ describe KalibroConfigurationsController, :type =&gt; :controller do @@ -132,13 +132,15 @@ describe KalibroConfigurationsController, :type =&gt; :controller do
132 end 132 end
133 133
134 describe 'index' do 134 describe 'index' do
  135 + let!(:kalibro_configuration_attribute) { FactoryGirl.build(:kalibro_configuration_attributes) }
135 before :each do 136 before :each do
136 @subject = FactoryGirl.build(:kalibro_configuration, :with_id) 137 @subject = FactoryGirl.build(:kalibro_configuration, :with_id)
137 - KalibroConfiguration.expects(:all).returns([@subject]) 138 + KalibroConfigurationAttributes.expects(:where).with(public: true).returns([kalibro_configuration_attribute])
  139 + KalibroConfiguration.expects(:find).with(kalibro_configuration_attribute.kalibro_configuration_id).returns(@subject)
138 get :index 140 get :index
139 end 141 end
140 142
141 - xit { is_expected.to render_template(:index) } 143 + it { is_expected.to render_template(:index) }
142 end 144 end
143 145
144 describe 'edit' do 146 describe 'edit' do
spec/controllers/kalibro_ranges_controller_spec.rb
@@ -54,8 +54,8 @@ describe KalibroRangesController, :type =&gt; :controller do @@ -54,8 +54,8 @@ describe KalibroRangesController, :type =&gt; :controller do
54 post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: kalibro_range.metric_configuration_id, kalibro_range: kalibro_range_params 54 post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: kalibro_range.metric_configuration_id, kalibro_range: kalibro_range_params
55 end 55 end
56 56
57 - xit { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: metric_configuration.id)) }  
58 - xit { is_expected.to respond_with(:redirect) } 57 + it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: metric_configuration.id)) }
  58 + it { is_expected.to respond_with(:redirect) }
59 end 59 end
60 60
61 context 'with valid fields and a compound metric configuration' do 61 context 'with valid fields and a compound metric configuration' do
@@ -69,8 +69,8 @@ describe KalibroRangesController, :type =&gt; :controller do @@ -69,8 +69,8 @@ describe KalibroRangesController, :type =&gt; :controller do
69 post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: new_kalibro_range.metric_configuration_id, kalibro_range: new_kalibro_range.to_hash 69 post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: new_kalibro_range.metric_configuration_id, kalibro_range: new_kalibro_range.to_hash
70 end 70 end
71 71
72 - xit { is_expected.to redirect_to(kalibro_configuration_compound_metric_configuration_path(kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id)) }  
73 - xit { is_expected.to respond_with(:redirect) } 72 + it { is_expected.to redirect_to(kalibro_configuration_compound_metric_configuration_path(kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id)) }
  73 + it { is_expected.to respond_with(:redirect) }
74 end 74 end
75 75
76 context 'with invalid fields' do 76 context 'with invalid fields' do
spec/controllers/reading_groups_controller_spec.rb
@@ -126,13 +126,15 @@ describe ReadingGroupsController, :type =&gt; :controller do @@ -126,13 +126,15 @@ describe ReadingGroupsController, :type =&gt; :controller do
126 end 126 end
127 127
128 describe 'index' do 128 describe 'index' do
  129 + let!(:reading_group_attribute) { FactoryGirl.build(:reading_group_attributes) }
129 before :each do 130 before :each do
130 @subject = FactoryGirl.build(:reading_group, :with_id) 131 @subject = FactoryGirl.build(:reading_group, :with_id)
131 - ReadingGroup.expects(:all).returns([@subject]) 132 + ReadingGroupAttributes.expects(:where).with(public: true).returns([reading_group_attribute])
  133 + ReadingGroup.expects(:find).with(reading_group_attribute.reading_group_id).returns([@subject])
132 get :index 134 get :index
133 end 135 end
134 136
135 - xit { is_expected.to render_template(:index) } 137 + it { is_expected.to render_template(:index) }
136 end 138 end
137 139
138 describe 'edit' do 140 describe 'edit' do
spec/factories/kalibro_configurations.rb
@@ -4,7 +4,7 @@ FactoryGirl.define do @@ -4,7 +4,7 @@ FactoryGirl.define do
4 description "Code metrics for Java." 4 description "Code metrics for Java."
5 5
6 trait :with_id do 6 trait :with_id do
7 - sequence(:id, 1) 7 + id 1
8 end 8 end
9 9
10 factory :another_kalibro_configuration do 10 factory :another_kalibro_configuration do
spec/factories/reading_groups.rb
@@ -12,4 +12,4 @@ FactoryGirl.define do @@ -12,4 +12,4 @@ FactoryGirl.define do
12 description "The best one" 12 description "The best one"
13 end 13 end
14 end 14 end
15 -end  
16 \ No newline at end of file 15 \ No newline at end of file
  16 +end
spec/helpers/kalibro_configurations_helper_spec.rb
@@ -18,13 +18,13 @@ describe KalibroConfigurationsHelper, :type =&gt; :helper do @@ -18,13 +18,13 @@ describe KalibroConfigurationsHelper, :type =&gt; :helper do
18 helper.expects(:user_signed_in?).returns(true) 18 helper.expects(:user_signed_in?).returns(true)
19 helper.expects(:current_user).returns(FactoryGirl.build(:user)) 19 helper.expects(:current_user).returns(FactoryGirl.build(:user))
20 20
21 - @ownerships = []  
22 - @ownerships.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(nil) 21 + @attributes = []
  22 + @attributes.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(nil)
23 23
24 - User.any_instance.expects(:kalibro_configuration_ownerships).returns(@ownerships) 24 + User.any_instance.expects(:kalibro_configuration_attributes).returns(@attributes)
25 end 25 end
26 26
27 - xit { expect(helper.kalibro_configuration_owner?(@subject.id)).to be_falsey } 27 + it { expect(helper.kalibro_configuration_owner?(@subject.id)).to be_falsey }
28 end 28 end
29 29
30 context 'returns true if user is the kalibro_configuration owner' do 30 context 'returns true if user is the kalibro_configuration owner' do
@@ -32,13 +32,13 @@ describe KalibroConfigurationsHelper, :type =&gt; :helper do @@ -32,13 +32,13 @@ describe KalibroConfigurationsHelper, :type =&gt; :helper do
32 helper.expects(:user_signed_in?).returns(true) 32 helper.expects(:user_signed_in?).returns(true)
33 helper.expects(:current_user).returns(FactoryGirl.build(:user)) 33 helper.expects(:current_user).returns(FactoryGirl.build(:user))
34 34
35 - @ownership = FactoryGirl.build(:kalibro_configuration_ownership)  
36 - @ownerships = []  
37 - @ownerships.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(@ownership)  
38 - User.any_instance.expects(:kalibro_configuration_ownerships).returns(@ownerships) 35 + @ownership = FactoryGirl.build(:kalibro_configuration_attributes)
  36 + @attributes = []
  37 + @attributes.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(@ownership)
  38 + User.any_instance.expects(:kalibro_configuration_attributes).returns(@attributes)
39 end 39 end
40 40
41 - xit { expect(helper.kalibro_configuration_owner?(@subject.id)).to be_truthy } 41 + it { expect(helper.kalibro_configuration_owner?(@subject.id)).to be_truthy }
42 end 42 end
43 end 43 end
44 44