Skip to content

Commit 47db127

Browse files
committed
ExperimentsController Rudimentary Tests
1 parent 05b2526 commit 47db127

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
11
require 'rails_helper'
22

33
RSpec.describe ExperimentsController, type: :controller do
4+
include BasicAuthHelper
45
describe "GET conduct" do
56
it "Raises controlled error on wrong experiment" do
67
@experiment = create(:experiment_with_static_text)
78
get 'conduct', :params => {:id_hash => @experiment.id_hash} ## this is the wrong type of hash
89
expect(response).to have_http_status(:error)
910
end
1011
end
12+
13+
describe "GET edit" do
14+
it "opens edit page" do
15+
login_as_admin
16+
@experiment = create(:experiment_with_static_text)
17+
get 'edit', :params => {:id => @experiment.id} ## this is the wrong type of hash
18+
expect(response).to have_http_status(:ok)
19+
end
20+
end
21+
22+
23+
describe "POST update" do
24+
it "can update the title" do
25+
login_as_admin
26+
@experiment = create(:experiment_with_static_text)
27+
new_title = Faker::Name.name
28+
patch 'update', :params => {:id => @experiment.id, :experiment => {:title => new_title}} ## this is the wrong type of hash
29+
expect(response).to have_http_status(:found)
30+
@experiment.reload
31+
expect(@experiment.title).to eq(new_title)
32+
33+
end
34+
end
35+
36+
37+
describe "DELETE destroy" do
38+
it "can update the title" do
39+
login_as_admin
40+
@experiment = create(:experiment_with_static_text)
41+
experiment_id = @experiment.id
42+
expect(Experiment.where(:id => experiment_id).length).to eq(1)
43+
44+
new_title = Faker::Name.name
45+
delete 'destroy', :params => {:id => @experiment.id} ## this is the wrong type of hash
46+
expect(response).to have_http_status(:found)
47+
expect(Experiment.where(:id => experiment_id).length).to eq(0)
48+
49+
end
50+
end
51+
52+
53+
54+
55+
56+
1157
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
FactoryBot.define do
22
factory :question do
3+
factory :number_question do
4+
question_text "Welche Nummer wird gesucht?"
5+
6+
factory :number_question_with_one_answer_possibility do
7+
after(:create) do |number_question_with_one_answer_possibility, evaluator|
8+
create_list(:answer_possibility_collection, 1, question: number_question_with_one_answer_possibility)
9+
end
10+
end
11+
12+
13+
14+
end
15+
16+
factory :text_question do
17+
question_text "Welcher Text wird gesucht?"
18+
19+
end
20+
321

422
end
523
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module BasicAuthHelper
2+
def login_as_admin
3+
user = 'admin'
4+
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,ENV['ADMIN_PASSWORD'])
5+
end
6+
end

0 commit comments

Comments
 (0)