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 12 # GET /kalibro_configurations
13 13 # GET /kalibro_configurations.json
14 14 def index
15   - @kalibro_configurations = KalibroConfigurationAttributes.where(hidden: false).map { |cfg_attr|
  15 + @kalibro_configurations = KalibroConfigurationAttributes.where(public: true).map { |cfg_attr|
16 16 KalibroConfiguration.find(cfg_attr.kalibro_configuration_id)
17 17 }.compact
18 18 end
... ...
app/controllers/reading_groups_controller.rb
... ... @@ -13,7 +13,7 @@ class ReadingGroupsController &lt; ApplicationController
13 13 # GET /reading_groups
14 14 # GET /reading_groups.json
15 15 def index
16   - @reading_groups = ReadingGroup.visible
  16 + @reading_groups = ReadingGroup.public
17 17 end
18 18  
19 19 # POST /reading_groups
... ...
db/schema.rb
... ... @@ -39,19 +39,19 @@ ActiveRecord::Schema.define(version: 20150511181035) do
39 39 end
40 40  
41 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 44 t.datetime "created_at"
45 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 48 t.datetime "reset_password_sent_at"
49 49 t.datetime "remember_created_at"
50   - t.integer "sign_in_count", default: 0
  50 + t.integer "sign_in_count", default: 0
51 51 t.datetime "current_sign_in_at"
52 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 55 end
56 56  
57 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 99 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s
100 100 end
101 101  
102   - xit { is_expected.to render_template(:edit) }
  102 + it { is_expected.to render_template(:edit) }
103 103 end
104 104  
105 105 context 'when the user does not own the compound metric configuration' do
... ... @@ -107,7 +107,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
107 107 get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s
108 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 111 it { is_expected.to respond_with(:redirect) }
112 112 it { is_expected.to set_flash[:notice].to("You're not allowed to do this operation") }
113 113 end
... ... @@ -157,7 +157,7 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
157 157 post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params
158 158 end
159 159  
160   - xit { should render_template(:edit) }
  160 + it { should render_template(:edit) }
161 161 end
162 162 end
163 163  
... ...
spec/controllers/kalibro_configurations_controller_spec.rb
... ... @@ -132,13 +132,15 @@ describe KalibroConfigurationsController, :type =&gt; :controller do
132 132 end
133 133  
134 134 describe 'index' do
  135 + let!(:kalibro_configuration_attribute) { FactoryGirl.build(:kalibro_configuration_attributes) }
135 136 before :each do
136 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 140 get :index
139 141 end
140 142  
141   - xit { is_expected.to render_template(:index) }
  143 + it { is_expected.to render_template(:index) }
142 144 end
143 145  
144 146 describe 'edit' do
... ...
spec/controllers/kalibro_ranges_controller_spec.rb
... ... @@ -54,8 +54,8 @@ describe KalibroRangesController, :type =&gt; :controller do
54 54 post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: kalibro_range.metric_configuration_id, kalibro_range: kalibro_range_params
55 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 59 end
60 60  
61 61 context 'with valid fields and a compound metric configuration' do
... ... @@ -69,8 +69,8 @@ describe KalibroRangesController, :type =&gt; :controller do
69 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 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 74 end
75 75  
76 76 context 'with invalid fields' do
... ...
spec/controllers/reading_groups_controller_spec.rb
... ... @@ -126,13 +126,15 @@ describe ReadingGroupsController, :type =&gt; :controller do
126 126 end
127 127  
128 128 describe 'index' do
  129 + let!(:reading_group_attribute) { FactoryGirl.build(:reading_group_attributes) }
129 130 before :each do
130 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 134 get :index
133 135 end
134 136  
135   - xit { is_expected.to render_template(:index) }
  137 + it { is_expected.to render_template(:index) }
136 138 end
137 139  
138 140 describe 'edit' do
... ...
spec/factories/kalibro_configurations.rb
... ... @@ -4,7 +4,7 @@ FactoryGirl.define do
4 4 description "Code metrics for Java."
5 5  
6 6 trait :with_id do
7   - sequence(:id, 1)
  7 + id 1
8 8 end
9 9  
10 10 factory :another_kalibro_configuration do
... ...
spec/factories/reading_groups.rb
... ... @@ -12,4 +12,4 @@ FactoryGirl.define do
12 12 description "The best one"
13 13 end
14 14 end
15   -end
16 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 18 helper.expects(:user_signed_in?).returns(true)
19 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 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 28 end
29 29  
30 30 context 'returns true if user is the kalibro_configuration owner' do
... ... @@ -32,13 +32,13 @@ describe KalibroConfigurationsHelper, :type =&gt; :helper do
32 32 helper.expects(:user_signed_in?).returns(true)
33 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 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 42 end
43 43 end
44 44  
... ...