From 97df081b334e96b4a23ef2827235bd003ae6d485 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 30 Jul 2015 00:03:02 +0200 Subject: [PATCH] AutoCommit Don Jul 30 00:03:02 CEST 2015 --- .../javascripts/survey/answers.js.coffee | 3 + .../javascripts/survey/choices.js.coffee | 3 + .../javascripts/survey/questions.js.coffee | 3 + .../stylesheets/survey/answers.css.scss | 3 + .../stylesheets/survey/choices.css.scss | 3 + .../stylesheets/survey/questions.css.scss | 3 + app/controllers/survey/answers_controller.rb | 83 +++++++++ app/controllers/survey/choices_controller.rb | 83 +++++++++ .../survey/questions_controller.rb | 85 ++++++++++ app/helpers/survey/answers_helper.rb | 2 + app/helpers/survey/choices_helper.rb | 2 + app/helpers/survey/questions_helper.rb | 2 + app/models/survey.rb | 5 + app/models/survey/answer.rb | 5 + app/models/survey/choice.rb | 5 + app/models/survey/question.rb | 16 ++ app/views/survey/answers/_form.html.erb | 10 ++ app/views/survey/answers/edit.html.erb | 6 + app/views/survey/answers/index.html.erb | 25 +++ app/views/survey/answers/new.html.erb | 5 + app/views/survey/answers/show.html.erb | 15 ++ app/views/survey/choices/_form.html.erb | 12 ++ app/views/survey/choices/edit.html.erb | 6 + app/views/survey/choices/index.html.erb | 29 ++++ app/views/survey/choices/new.html.erb | 5 + app/views/survey/choices/show.html.erb | 25 +++ app/views/survey/questions/_form.html.erb | 13 ++ app/views/survey/questions/_question.html.erb | 2 + app/views/survey/questions/edit.html.erb | 6 + app/views/survey/questions/index.html.erb | 27 +++ app/views/survey/questions/new.html.erb | 5 + app/views/survey/questions/show.html.erb | 21 +++ config/routes.rb | 18 ++ .../20150729210826_create_survey_questions.rb | 12 ++ .../20150729211328_create_survey_choices.rb | 13 ++ .../20150729211914_create_survey_answers.rb | 12 ++ .../survey/answers_controller_spec.rb | 159 ++++++++++++++++++ .../survey/choices_controller_spec.rb | 159 ++++++++++++++++++ .../survey/questions_controller_spec.rb | 159 ++++++++++++++++++ spec/factories/survey_answers.rb | 7 + spec/factories/survey_choices.rb | 9 + spec/factories/survey_questions.rb | 8 + spec/helpers/survey/answers_helper_spec.rb | 15 ++ spec/helpers/survey/choices_helper_spec.rb | 15 ++ spec/helpers/survey/questions_helper_spec.rb | 15 ++ spec/models/survey/answer_spec.rb | 5 + spec/models/survey/choice_spec.rb | 5 + spec/models/survey/question_spec.rb | 5 + spec/requests/survey/survey_answers_spec.rb | 10 ++ spec/requests/survey/survey_choices_spec.rb | 10 ++ spec/requests/survey/survey_questions_spec.rb | 10 ++ spec/routing/survey/answers_routing_spec.rb | 35 ++++ spec/routing/survey/choices_routing_spec.rb | 35 ++++ spec/routing/survey/questions_routing_spec.rb | 35 ++++ .../survey/answers/edit.html.erb_spec.rb | 21 +++ .../survey/answers/index.html.erb_spec.rb | 22 +++ .../views/survey/answers/new.html.erb_spec.rb | 21 +++ .../survey/answers/show.html.erb_spec.rb | 16 ++ .../survey/choices/edit.html.erb_spec.rb | 27 +++ .../survey/choices/index.html.erb_spec.rb | 28 +++ .../views/survey/choices/new.html.erb_spec.rb | 27 +++ .../survey/choices/show.html.erb_spec.rb | 20 +++ .../survey/questions/edit.html.erb_spec.rb | 24 +++ .../survey/questions/index.html.erb_spec.rb | 25 +++ .../survey/questions/new.html.erb_spec.rb | 24 +++ .../survey/questions/show.html.erb_spec.rb | 18 ++ 66 files changed, 1542 insertions(+) create mode 100644 app/assets/javascripts/survey/answers.js.coffee create mode 100644 app/assets/javascripts/survey/choices.js.coffee create mode 100644 app/assets/javascripts/survey/questions.js.coffee create mode 100644 app/assets/stylesheets/survey/answers.css.scss create mode 100644 app/assets/stylesheets/survey/choices.css.scss create mode 100644 app/assets/stylesheets/survey/questions.css.scss create mode 100644 app/controllers/survey/answers_controller.rb create mode 100644 app/controllers/survey/choices_controller.rb create mode 100644 app/controllers/survey/questions_controller.rb create mode 100644 app/helpers/survey/answers_helper.rb create mode 100644 app/helpers/survey/choices_helper.rb create mode 100644 app/helpers/survey/questions_helper.rb create mode 100644 app/models/survey.rb create mode 100644 app/models/survey/answer.rb create mode 100644 app/models/survey/choice.rb create mode 100644 app/models/survey/question.rb create mode 100644 app/views/survey/answers/_form.html.erb create mode 100644 app/views/survey/answers/edit.html.erb create mode 100644 app/views/survey/answers/index.html.erb create mode 100644 app/views/survey/answers/new.html.erb create mode 100644 app/views/survey/answers/show.html.erb create mode 100644 app/views/survey/choices/_form.html.erb create mode 100644 app/views/survey/choices/edit.html.erb create mode 100644 app/views/survey/choices/index.html.erb create mode 100644 app/views/survey/choices/new.html.erb create mode 100644 app/views/survey/choices/show.html.erb create mode 100644 app/views/survey/questions/_form.html.erb create mode 100644 app/views/survey/questions/_question.html.erb create mode 100644 app/views/survey/questions/edit.html.erb create mode 100644 app/views/survey/questions/index.html.erb create mode 100644 app/views/survey/questions/new.html.erb create mode 100644 app/views/survey/questions/show.html.erb create mode 100644 db/migrate/20150729210826_create_survey_questions.rb create mode 100644 db/migrate/20150729211328_create_survey_choices.rb create mode 100644 db/migrate/20150729211914_create_survey_answers.rb create mode 100644 spec/controllers/survey/answers_controller_spec.rb create mode 100644 spec/controllers/survey/choices_controller_spec.rb create mode 100644 spec/controllers/survey/questions_controller_spec.rb create mode 100644 spec/factories/survey_answers.rb create mode 100644 spec/factories/survey_choices.rb create mode 100644 spec/factories/survey_questions.rb create mode 100644 spec/helpers/survey/answers_helper_spec.rb create mode 100644 spec/helpers/survey/choices_helper_spec.rb create mode 100644 spec/helpers/survey/questions_helper_spec.rb create mode 100644 spec/models/survey/answer_spec.rb create mode 100644 spec/models/survey/choice_spec.rb create mode 100644 spec/models/survey/question_spec.rb create mode 100644 spec/requests/survey/survey_answers_spec.rb create mode 100644 spec/requests/survey/survey_choices_spec.rb create mode 100644 spec/requests/survey/survey_questions_spec.rb create mode 100644 spec/routing/survey/answers_routing_spec.rb create mode 100644 spec/routing/survey/choices_routing_spec.rb create mode 100644 spec/routing/survey/questions_routing_spec.rb create mode 100644 spec/views/survey/answers/edit.html.erb_spec.rb create mode 100644 spec/views/survey/answers/index.html.erb_spec.rb create mode 100644 spec/views/survey/answers/new.html.erb_spec.rb create mode 100644 spec/views/survey/answers/show.html.erb_spec.rb create mode 100644 spec/views/survey/choices/edit.html.erb_spec.rb create mode 100644 spec/views/survey/choices/index.html.erb_spec.rb create mode 100644 spec/views/survey/choices/new.html.erb_spec.rb create mode 100644 spec/views/survey/choices/show.html.erb_spec.rb create mode 100644 spec/views/survey/questions/edit.html.erb_spec.rb create mode 100644 spec/views/survey/questions/index.html.erb_spec.rb create mode 100644 spec/views/survey/questions/new.html.erb_spec.rb create mode 100644 spec/views/survey/questions/show.html.erb_spec.rb diff --git a/app/assets/javascripts/survey/answers.js.coffee b/app/assets/javascripts/survey/answers.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/survey/answers.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/survey/choices.js.coffee b/app/assets/javascripts/survey/choices.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/survey/choices.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/survey/questions.js.coffee b/app/assets/javascripts/survey/questions.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/survey/questions.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/survey/answers.css.scss b/app/assets/stylesheets/survey/answers.css.scss new file mode 100644 index 0000000..34c04ec --- /dev/null +++ b/app/assets/stylesheets/survey/answers.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Survey::answers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/survey/choices.css.scss b/app/assets/stylesheets/survey/choices.css.scss new file mode 100644 index 0000000..0bf8087 --- /dev/null +++ b/app/assets/stylesheets/survey/choices.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Survey::choices controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/survey/questions.css.scss b/app/assets/stylesheets/survey/questions.css.scss new file mode 100644 index 0000000..758801f --- /dev/null +++ b/app/assets/stylesheets/survey/questions.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Survey::questions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/survey/answers_controller.rb b/app/controllers/survey/answers_controller.rb new file mode 100644 index 0000000..3f5ff83 --- /dev/null +++ b/app/controllers/survey/answers_controller.rb @@ -0,0 +1,83 @@ +class Survey::AnswersController < ApplicationController + # GET /survey/answers + # GET /survey/answers.json + def index + @survey_answers = Survey::Answer.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @survey_answers } + end + end + + # GET /survey/answers/1 + # GET /survey/answers/1.json + def show + @survey_answer = Survey::Answer.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @survey_answer } + end + end + + # GET /survey/answers/new + # GET /survey/answers/new.json + def new + @survey_answer = Survey::Answer.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @survey_answer } + end + end + + # GET /survey/answers/1/edit + def edit + @survey_answer = Survey::Answer.find(params[:id]) + end + + # POST /survey/answers + # POST /survey/answers.json + def create + @survey_answer = Survey::Answer.new(params[:survey_answer]) + + respond_to do |format| + if @survey_answer.save + format.html { redirect_to @survey_answer, notice: 'Answer was successfully created.' } + format.json { render json: @survey_answer, status: :created, location: @survey_answer } + else + format.html { render action: "new" } + format.json { render json: @survey_answer.errors, status: :unprocessable_entity } + end + end + end + + # PUT /survey/answers/1 + # PUT /survey/answers/1.json + def update + @survey_answer = Survey::Answer.find(params[:id]) + + respond_to do |format| + if @survey_answer.update_attributes(params[:survey_answer]) + format.html { redirect_to @survey_answer, notice: 'Answer was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @survey_answer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /survey/answers/1 + # DELETE /survey/answers/1.json + def destroy + @survey_answer = Survey::Answer.find(params[:id]) + @survey_answer.destroy + + respond_to do |format| + format.html { redirect_to survey_answers_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/survey/choices_controller.rb b/app/controllers/survey/choices_controller.rb new file mode 100644 index 0000000..d43b5c5 --- /dev/null +++ b/app/controllers/survey/choices_controller.rb @@ -0,0 +1,83 @@ +class Survey::ChoicesController < ApplicationController + # GET /survey/choices + # GET /survey/choices.json + def index + @survey_choices = Survey::Choice.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @survey_choices } + end + end + + # GET /survey/choices/1 + # GET /survey/choices/1.json + def show + @survey_choice = Survey::Choice.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @survey_choice } + end + end + + # GET /survey/choices/new + # GET /survey/choices/new.json + def new + @survey_choice = Survey::Choice.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @survey_choice } + end + end + + # GET /survey/choices/1/edit + def edit + @survey_choice = Survey::Choice.find(params[:id]) + end + + # POST /survey/choices + # POST /survey/choices.json + def create + @survey_choice = Survey::Choice.new(params[:survey_choice]) + + respond_to do |format| + if @survey_choice.save + format.html { redirect_to @survey_choice, notice: 'Choice was successfully created.' } + format.json { render json: @survey_choice, status: :created, location: @survey_choice } + else + format.html { render action: "new" } + format.json { render json: @survey_choice.errors, status: :unprocessable_entity } + end + end + end + + # PUT /survey/choices/1 + # PUT /survey/choices/1.json + def update + @survey_choice = Survey::Choice.find(params[:id]) + + respond_to do |format| + if @survey_choice.update_attributes(params[:survey_choice]) + format.html { redirect_to @survey_choice, notice: 'Choice was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @survey_choice.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /survey/choices/1 + # DELETE /survey/choices/1.json + def destroy + @survey_choice = Survey::Choice.find(params[:id]) + @survey_choice.destroy + + respond_to do |format| + format.html { redirect_to survey_choices_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/survey/questions_controller.rb b/app/controllers/survey/questions_controller.rb new file mode 100644 index 0000000..e3bfc43 --- /dev/null +++ b/app/controllers/survey/questions_controller.rb @@ -0,0 +1,85 @@ +class Survey::QuestionsController < ApplicationController + # GET /survey/questions + # GET /survey/questions.json + def index + @survey_questions = Survey::Question.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @survey_questions } + end + end + def answer + render :show + end + # GET /survey/questions/1 + # GET /survey/questions/1.json + def show + @survey_question = Survey::Question.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @survey_question } + end + end + + # GET /survey/questions/new + # GET /survey/questions/new.json + def new + @survey_question = Survey::Question.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @survey_question } + end + end + + # GET /survey/questions/1/edit + def edit + @survey_question = Survey::Question.find(params[:id]) + end + + # POST /survey/questions + # POST /survey/questions.json + def create + @survey_question = Survey::Question.new(params[:survey_question]) + + respond_to do |format| + if @survey_question.save + format.html { redirect_to @survey_question, notice: 'Question was successfully created.' } + format.json { render json: @survey_question, status: :created, location: @survey_question } + else + format.html { render action: "new" } + format.json { render json: @survey_question.errors, status: :unprocessable_entity } + end + end + end + + # PUT /survey/questions/1 + # PUT /survey/questions/1.json + def update + @survey_question = Survey::Question.find(params[:id]) + + respond_to do |format| + if @survey_question.update_attributes(params[:survey_question]) + format.html { redirect_to @survey_question, notice: 'Question was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @survey_question.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /survey/questions/1 + # DELETE /survey/questions/1.json + def destroy + @survey_question = Survey::Question.find(params[:id]) + @survey_question.destroy + + respond_to do |format| + format.html { redirect_to survey_questions_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/survey/answers_helper.rb b/app/helpers/survey/answers_helper.rb new file mode 100644 index 0000000..becb796 --- /dev/null +++ b/app/helpers/survey/answers_helper.rb @@ -0,0 +1,2 @@ +module Survey::AnswersHelper +end diff --git a/app/helpers/survey/choices_helper.rb b/app/helpers/survey/choices_helper.rb new file mode 100644 index 0000000..fb9681e --- /dev/null +++ b/app/helpers/survey/choices_helper.rb @@ -0,0 +1,2 @@ +module Survey::ChoicesHelper +end diff --git a/app/helpers/survey/questions_helper.rb b/app/helpers/survey/questions_helper.rb new file mode 100644 index 0000000..b4d9998 --- /dev/null +++ b/app/helpers/survey/questions_helper.rb @@ -0,0 +1,2 @@ +module Survey::QuestionsHelper +end diff --git a/app/models/survey.rb b/app/models/survey.rb new file mode 100644 index 0000000..02da13d --- /dev/null +++ b/app/models/survey.rb @@ -0,0 +1,5 @@ +module Survey + def self.table_name_prefix + 'survey_' + end +end diff --git a/app/models/survey/answer.rb b/app/models/survey/answer.rb new file mode 100644 index 0000000..a7d2c78 --- /dev/null +++ b/app/models/survey/answer.rb @@ -0,0 +1,5 @@ +class Survey::Answer < ActiveRecord::Base + belongs_to :choice, class_name: 'Survey::Choice' + belongs_to :user + # attr_accessible :title, :body +end diff --git a/app/models/survey/choice.rb b/app/models/survey/choice.rb new file mode 100644 index 0000000..921e636 --- /dev/null +++ b/app/models/survey/choice.rb @@ -0,0 +1,5 @@ +class Survey::Choice < ActiveRecord::Base + belongs_to :question, class_name: 'Survey::Question' + attr_accessible :picture, :sort, :text + has_many :answers, class_name: 'Survey::Answer' +end diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb new file mode 100644 index 0000000..7815d40 --- /dev/null +++ b/app/models/survey/question.rb @@ -0,0 +1,16 @@ +class Survey::Question < ActiveRecord::Base + attr_accessible :text, :title, :typ, :choice_ids + belongs_to :parent, polymorphic: true + has_many :choices + has_many :answers, through: :choices + def add_yesno_choices + c=Survey::Choice.new(title: "Ja") + c.save + this.choices << c + c=Survey::Choice.new(title: "Nein") + c.save + this.choices << c + + end +end + diff --git a/app/views/survey/answers/_form.html.erb b/app/views/survey/answers/_form.html.erb new file mode 100644 index 0000000..b115e0a --- /dev/null +++ b/app/views/survey/answers/_form.html.erb @@ -0,0 +1,10 @@ +<%= semantic_form_for @answer do |f| %> + <%= f.inputs do %> + <%= f.input :choice %> + <%= f.input :user %> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/survey/answers/edit.html.erb b/app/views/survey/answers/edit.html.erb new file mode 100644 index 0000000..36e125d --- /dev/null +++ b/app/views/survey/answers/edit.html.erb @@ -0,0 +1,6 @@ +

Editing survey_answer

+ +<%= render 'form' %> + +<%= link_to 'Show', @survey_answer %> | +<%= link_to 'Back', survey_answers_path %> diff --git a/app/views/survey/answers/index.html.erb b/app/views/survey/answers/index.html.erb new file mode 100644 index 0000000..f2c5eee --- /dev/null +++ b/app/views/survey/answers/index.html.erb @@ -0,0 +1,25 @@ +

Listing survey_answers

+ + + + + + + + + + +<% @survey_answers.each do |survey_answer| %> + + + + + + + +<% end %> +
ChoiceUser
<%= survey_answer.choice %><%= survey_answer.user %><%= link_to 'Show', survey_answer %><%= link_to 'Edit', edit_survey_answer_path(survey_answer) %><%= link_to 'Destroy', survey_answer, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Answer', new_survey_answer_path %> diff --git a/app/views/survey/answers/new.html.erb b/app/views/survey/answers/new.html.erb new file mode 100644 index 0000000..9f35966 --- /dev/null +++ b/app/views/survey/answers/new.html.erb @@ -0,0 +1,5 @@ +

New survey_answer

+ +<%= render 'form' %> + +<%= link_to 'Back', survey_answers_path %> diff --git a/app/views/survey/answers/show.html.erb b/app/views/survey/answers/show.html.erb new file mode 100644 index 0000000..741d702 --- /dev/null +++ b/app/views/survey/answers/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Choice: + <%= @survey_answer.choice %> +

+ +

+ User: + <%= @survey_answer.user %> +

+ + +<%= link_to 'Edit', edit_survey_answer_path(@survey_answer) %> | +<%= link_to 'Back', survey_answers_path %> diff --git a/app/views/survey/choices/_form.html.erb b/app/views/survey/choices/_form.html.erb new file mode 100644 index 0000000..865a002 --- /dev/null +++ b/app/views/survey/choices/_form.html.erb @@ -0,0 +1,12 @@ +<%= semantic_form_for @choice do |f| %> + <%= f.inputs do %> + <%= f.input :text %> + <%= f.input :question %> + <%= f.input :sort %> + <%= f.input :picture %> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/survey/choices/edit.html.erb b/app/views/survey/choices/edit.html.erb new file mode 100644 index 0000000..e57d725 --- /dev/null +++ b/app/views/survey/choices/edit.html.erb @@ -0,0 +1,6 @@ +

Editing survey_choice

+ +<%= render 'form' %> + +<%= link_to 'Show', @survey_choice %> | +<%= link_to 'Back', survey_choices_path %> diff --git a/app/views/survey/choices/index.html.erb b/app/views/survey/choices/index.html.erb new file mode 100644 index 0000000..c2249f3 --- /dev/null +++ b/app/views/survey/choices/index.html.erb @@ -0,0 +1,29 @@ +

Listing survey_choices

+ + + + + + + + + + + + +<% @survey_choices.each do |survey_choice| %> + + + + + + + + + +<% end %> +
TextQuestionSortPicture
<%= survey_choice.text %><%= survey_choice.question %><%= survey_choice.sort %><%= survey_choice.picture %><%= link_to 'Show', survey_choice %><%= link_to 'Edit', edit_survey_choice_path(survey_choice) %><%= link_to 'Destroy', survey_choice, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Choice', new_survey_choice_path %> diff --git a/app/views/survey/choices/new.html.erb b/app/views/survey/choices/new.html.erb new file mode 100644 index 0000000..c843fc3 --- /dev/null +++ b/app/views/survey/choices/new.html.erb @@ -0,0 +1,5 @@ +

New survey_choice

+ +<%= render 'form' %> + +<%= link_to 'Back', survey_choices_path %> diff --git a/app/views/survey/choices/show.html.erb b/app/views/survey/choices/show.html.erb new file mode 100644 index 0000000..41342d4 --- /dev/null +++ b/app/views/survey/choices/show.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

+ Text: + <%= @survey_choice.text %> +

+ +

+ Question: + <%= @survey_choice.question %> +

+ +

+ Sort: + <%= @survey_choice.sort %> +

+ +

+ Picture: + <%= @survey_choice.picture %> +

+ + +<%= link_to 'Edit', edit_survey_choice_path(@survey_choice) %> | +<%= link_to 'Back', survey_choices_path %> diff --git a/app/views/survey/questions/_form.html.erb b/app/views/survey/questions/_form.html.erb new file mode 100644 index 0000000..8a95873 --- /dev/null +++ b/app/views/survey/questions/_form.html.erb @@ -0,0 +1,13 @@ +<%= semantic_form_for @survey_question do |f| %> + <%= f.inputs do %> + <%= f.input :title %> + <%= f.input :text %> + + + <%= f.input :typ %> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/survey/questions/_question.html.erb b/app/views/survey/questions/_question.html.erb new file mode 100644 index 0000000..4584665 --- /dev/null +++ b/app/views/survey/questions/_question.html.erb @@ -0,0 +1,2 @@ +<%= question.title%> +<%= form_for %> diff --git a/app/views/survey/questions/edit.html.erb b/app/views/survey/questions/edit.html.erb new file mode 100644 index 0000000..c5fe57f --- /dev/null +++ b/app/views/survey/questions/edit.html.erb @@ -0,0 +1,6 @@ +

Editing survey_question

+ +<%= render 'form' %> + +<%= link_to 'Show', @survey_question %> | +<%= link_to 'Back', survey_questions_path %> diff --git a/app/views/survey/questions/index.html.erb b/app/views/survey/questions/index.html.erb new file mode 100644 index 0000000..055f0d2 --- /dev/null +++ b/app/views/survey/questions/index.html.erb @@ -0,0 +1,27 @@ +

Listing survey_questions

+ + + + + + + + + + + +<% @survey_questions.each do |survey_question| %> + + + + + + + + +<% end %> +
TitleTextTyp
<%= survey_question.title %><%= survey_question.text %><%= survey_question.typ %><%= link_to 'Show', survey_question %><%= link_to 'Edit', edit_survey_question_path(survey_question) %><%= link_to 'Destroy', survey_question, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Question', new_survey_question_path %> diff --git a/app/views/survey/questions/new.html.erb b/app/views/survey/questions/new.html.erb new file mode 100644 index 0000000..601c133 --- /dev/null +++ b/app/views/survey/questions/new.html.erb @@ -0,0 +1,5 @@ +

New survey_question

+ +<%= render 'form' %> + +<%= link_to 'Back', survey_questions_path %> diff --git a/app/views/survey/questions/show.html.erb b/app/views/survey/questions/show.html.erb new file mode 100644 index 0000000..32ebcc3 --- /dev/null +++ b/app/views/survey/questions/show.html.erb @@ -0,0 +1,21 @@ +

<%= notice %>

+ +

+ Title: + <%= @survey_question.title %> +

+ +

+ Text: + <%= @survey_question.text %> +

+ +

+ Typ: + <%= @survey_question.typ %> +

+ +<%= render @survey_question %> + +<%= link_to 'Edit', edit_survey_question_path(@survey_question) %> | +<%= link_to 'Back', survey_questions_path %> diff --git a/config/routes.rb b/config/routes.rb index c12894e..2ea73a3 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,23 @@ Fetsite::Application.routes.draw do + namespace :survey do + resources :answers + end + + + namespace :survey do + resources :choices + end + + + namespace :survey do + resources :questions do + member do + :answer + end + end + end + themes_for_rails devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } resources :home, :only=>[:index] do diff --git a/db/migrate/20150729210826_create_survey_questions.rb b/db/migrate/20150729210826_create_survey_questions.rb new file mode 100644 index 0000000..fd6988f --- /dev/null +++ b/db/migrate/20150729210826_create_survey_questions.rb @@ -0,0 +1,12 @@ +class CreateSurveyQuestions < ActiveRecord::Migration + def change + create_table :survey_questions do |t| + t.string :title + t.text :text + t.integer :typ + t.string :parent_type + t.integer :parent_id + t.timestamps + end + end +end diff --git a/db/migrate/20150729211328_create_survey_choices.rb b/db/migrate/20150729211328_create_survey_choices.rb new file mode 100644 index 0000000..1b49f48 --- /dev/null +++ b/db/migrate/20150729211328_create_survey_choices.rb @@ -0,0 +1,13 @@ +class CreateSurveyChoices < ActiveRecord::Migration + def change + create_table :survey_choices do |t| + t.string :text + t.references :question + t.integer :sort + t.string :picture + + t.timestamps + end + add_index :survey_choices, :question_id + end +end diff --git a/db/migrate/20150729211914_create_survey_answers.rb b/db/migrate/20150729211914_create_survey_answers.rb new file mode 100644 index 0000000..fc966a0 --- /dev/null +++ b/db/migrate/20150729211914_create_survey_answers.rb @@ -0,0 +1,12 @@ +class CreateSurveyAnswers < ActiveRecord::Migration + def change + create_table :survey_answers do |t| + t.references :choice + t.references :user + + t.timestamps + end + add_index :survey_answers, :choice_id + add_index :survey_answers, :user_id + end +end diff --git a/spec/controllers/survey/answers_controller_spec.rb b/spec/controllers/survey/answers_controller_spec.rb new file mode 100644 index 0000000..37d74ed --- /dev/null +++ b/spec/controllers/survey/answers_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe Survey::AnswersController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Survey::Answer. As you add validations to Survey::Answer, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # Survey::AnswersController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all survey_answers as @survey_answers" do + answer = Survey::Answer.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:survey_answers)).to eq([answer]) + end + end + + describe "GET #show" do + it "assigns the requested survey_answer as @survey_answer" do + answer = Survey::Answer.create! valid_attributes + get :show, {:id => answer.to_param}, valid_session + expect(assigns(:survey_answer)).to eq(answer) + end + end + + describe "GET #new" do + it "assigns a new survey_answer as @survey_answer" do + get :new, {}, valid_session + expect(assigns(:survey_answer)).to be_a_new(Survey::Answer) + end + end + + describe "GET #edit" do + it "assigns the requested survey_answer as @survey_answer" do + answer = Survey::Answer.create! valid_attributes + get :edit, {:id => answer.to_param}, valid_session + expect(assigns(:survey_answer)).to eq(answer) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Survey::Answer" do + expect { + post :create, {:survey_answer => valid_attributes}, valid_session + }.to change(Survey::Answer, :count).by(1) + end + + it "assigns a newly created survey_answer as @survey_answer" do + post :create, {:survey_answer => valid_attributes}, valid_session + expect(assigns(:survey_answer)).to be_a(Survey::Answer) + expect(assigns(:survey_answer)).to be_persisted + end + + it "redirects to the created survey_answer" do + post :create, {:survey_answer => valid_attributes}, valid_session + expect(response).to redirect_to(Survey::Answer.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved survey_answer as @survey_answer" do + post :create, {:survey_answer => invalid_attributes}, valid_session + expect(assigns(:survey_answer)).to be_a_new(Survey::Answer) + end + + it "re-renders the 'new' template" do + post :create, {:survey_answer => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested survey_answer" do + answer = Survey::Answer.create! valid_attributes + put :update, {:id => answer.to_param, :survey_answer => new_attributes}, valid_session + answer.reload + skip("Add assertions for updated state") + end + + it "assigns the requested survey_answer as @survey_answer" do + answer = Survey::Answer.create! valid_attributes + put :update, {:id => answer.to_param, :survey_answer => valid_attributes}, valid_session + expect(assigns(:survey_answer)).to eq(answer) + end + + it "redirects to the survey_answer" do + answer = Survey::Answer.create! valid_attributes + put :update, {:id => answer.to_param, :survey_answer => valid_attributes}, valid_session + expect(response).to redirect_to(answer) + end + end + + context "with invalid params" do + it "assigns the survey_answer as @survey_answer" do + answer = Survey::Answer.create! valid_attributes + put :update, {:id => answer.to_param, :survey_answer => invalid_attributes}, valid_session + expect(assigns(:survey_answer)).to eq(answer) + end + + it "re-renders the 'edit' template" do + answer = Survey::Answer.create! valid_attributes + put :update, {:id => answer.to_param, :survey_answer => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested survey_answer" do + answer = Survey::Answer.create! valid_attributes + expect { + delete :destroy, {:id => answer.to_param}, valid_session + }.to change(Survey::Answer, :count).by(-1) + end + + it "redirects to the survey_answers list" do + answer = Survey::Answer.create! valid_attributes + delete :destroy, {:id => answer.to_param}, valid_session + expect(response).to redirect_to(survey_answers_url) + end + end + +end diff --git a/spec/controllers/survey/choices_controller_spec.rb b/spec/controllers/survey/choices_controller_spec.rb new file mode 100644 index 0000000..a84bf4e --- /dev/null +++ b/spec/controllers/survey/choices_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe Survey::ChoicesController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Survey::Choice. As you add validations to Survey::Choice, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # Survey::ChoicesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all survey_choices as @survey_choices" do + choice = Survey::Choice.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:survey_choices)).to eq([choice]) + end + end + + describe "GET #show" do + it "assigns the requested survey_choice as @survey_choice" do + choice = Survey::Choice.create! valid_attributes + get :show, {:id => choice.to_param}, valid_session + expect(assigns(:survey_choice)).to eq(choice) + end + end + + describe "GET #new" do + it "assigns a new survey_choice as @survey_choice" do + get :new, {}, valid_session + expect(assigns(:survey_choice)).to be_a_new(Survey::Choice) + end + end + + describe "GET #edit" do + it "assigns the requested survey_choice as @survey_choice" do + choice = Survey::Choice.create! valid_attributes + get :edit, {:id => choice.to_param}, valid_session + expect(assigns(:survey_choice)).to eq(choice) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Survey::Choice" do + expect { + post :create, {:survey_choice => valid_attributes}, valid_session + }.to change(Survey::Choice, :count).by(1) + end + + it "assigns a newly created survey_choice as @survey_choice" do + post :create, {:survey_choice => valid_attributes}, valid_session + expect(assigns(:survey_choice)).to be_a(Survey::Choice) + expect(assigns(:survey_choice)).to be_persisted + end + + it "redirects to the created survey_choice" do + post :create, {:survey_choice => valid_attributes}, valid_session + expect(response).to redirect_to(Survey::Choice.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved survey_choice as @survey_choice" do + post :create, {:survey_choice => invalid_attributes}, valid_session + expect(assigns(:survey_choice)).to be_a_new(Survey::Choice) + end + + it "re-renders the 'new' template" do + post :create, {:survey_choice => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested survey_choice" do + choice = Survey::Choice.create! valid_attributes + put :update, {:id => choice.to_param, :survey_choice => new_attributes}, valid_session + choice.reload + skip("Add assertions for updated state") + end + + it "assigns the requested survey_choice as @survey_choice" do + choice = Survey::Choice.create! valid_attributes + put :update, {:id => choice.to_param, :survey_choice => valid_attributes}, valid_session + expect(assigns(:survey_choice)).to eq(choice) + end + + it "redirects to the survey_choice" do + choice = Survey::Choice.create! valid_attributes + put :update, {:id => choice.to_param, :survey_choice => valid_attributes}, valid_session + expect(response).to redirect_to(choice) + end + end + + context "with invalid params" do + it "assigns the survey_choice as @survey_choice" do + choice = Survey::Choice.create! valid_attributes + put :update, {:id => choice.to_param, :survey_choice => invalid_attributes}, valid_session + expect(assigns(:survey_choice)).to eq(choice) + end + + it "re-renders the 'edit' template" do + choice = Survey::Choice.create! valid_attributes + put :update, {:id => choice.to_param, :survey_choice => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested survey_choice" do + choice = Survey::Choice.create! valid_attributes + expect { + delete :destroy, {:id => choice.to_param}, valid_session + }.to change(Survey::Choice, :count).by(-1) + end + + it "redirects to the survey_choices list" do + choice = Survey::Choice.create! valid_attributes + delete :destroy, {:id => choice.to_param}, valid_session + expect(response).to redirect_to(survey_choices_url) + end + end + +end diff --git a/spec/controllers/survey/questions_controller_spec.rb b/spec/controllers/survey/questions_controller_spec.rb new file mode 100644 index 0000000..707d369 --- /dev/null +++ b/spec/controllers/survey/questions_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe Survey::QuestionsController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Survey::Question. As you add validations to Survey::Question, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # Survey::QuestionsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all survey_questions as @survey_questions" do + question = Survey::Question.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:survey_questions)).to eq([question]) + end + end + + describe "GET #show" do + it "assigns the requested survey_question as @survey_question" do + question = Survey::Question.create! valid_attributes + get :show, {:id => question.to_param}, valid_session + expect(assigns(:survey_question)).to eq(question) + end + end + + describe "GET #new" do + it "assigns a new survey_question as @survey_question" do + get :new, {}, valid_session + expect(assigns(:survey_question)).to be_a_new(Survey::Question) + end + end + + describe "GET #edit" do + it "assigns the requested survey_question as @survey_question" do + question = Survey::Question.create! valid_attributes + get :edit, {:id => question.to_param}, valid_session + expect(assigns(:survey_question)).to eq(question) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Survey::Question" do + expect { + post :create, {:survey_question => valid_attributes}, valid_session + }.to change(Survey::Question, :count).by(1) + end + + it "assigns a newly created survey_question as @survey_question" do + post :create, {:survey_question => valid_attributes}, valid_session + expect(assigns(:survey_question)).to be_a(Survey::Question) + expect(assigns(:survey_question)).to be_persisted + end + + it "redirects to the created survey_question" do + post :create, {:survey_question => valid_attributes}, valid_session + expect(response).to redirect_to(Survey::Question.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved survey_question as @survey_question" do + post :create, {:survey_question => invalid_attributes}, valid_session + expect(assigns(:survey_question)).to be_a_new(Survey::Question) + end + + it "re-renders the 'new' template" do + post :create, {:survey_question => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested survey_question" do + question = Survey::Question.create! valid_attributes + put :update, {:id => question.to_param, :survey_question => new_attributes}, valid_session + question.reload + skip("Add assertions for updated state") + end + + it "assigns the requested survey_question as @survey_question" do + question = Survey::Question.create! valid_attributes + put :update, {:id => question.to_param, :survey_question => valid_attributes}, valid_session + expect(assigns(:survey_question)).to eq(question) + end + + it "redirects to the survey_question" do + question = Survey::Question.create! valid_attributes + put :update, {:id => question.to_param, :survey_question => valid_attributes}, valid_session + expect(response).to redirect_to(question) + end + end + + context "with invalid params" do + it "assigns the survey_question as @survey_question" do + question = Survey::Question.create! valid_attributes + put :update, {:id => question.to_param, :survey_question => invalid_attributes}, valid_session + expect(assigns(:survey_question)).to eq(question) + end + + it "re-renders the 'edit' template" do + question = Survey::Question.create! valid_attributes + put :update, {:id => question.to_param, :survey_question => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested survey_question" do + question = Survey::Question.create! valid_attributes + expect { + delete :destroy, {:id => question.to_param}, valid_session + }.to change(Survey::Question, :count).by(-1) + end + + it "redirects to the survey_questions list" do + question = Survey::Question.create! valid_attributes + delete :destroy, {:id => question.to_param}, valid_session + expect(response).to redirect_to(survey_questions_url) + end + end + +end diff --git a/spec/factories/survey_answers.rb b/spec/factories/survey_answers.rb new file mode 100644 index 0000000..830266e --- /dev/null +++ b/spec/factories/survey_answers.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :survey_answer, :class => 'Survey::Answer' do + choice nil +user nil + end + +end diff --git a/spec/factories/survey_choices.rb b/spec/factories/survey_choices.rb new file mode 100644 index 0000000..0b5d6a6 --- /dev/null +++ b/spec/factories/survey_choices.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :survey_choice, :class => 'Survey::Choice' do + text "MyString" +question nil +sort 1 +picture "MyString" + end + +end diff --git a/spec/factories/survey_questions.rb b/spec/factories/survey_questions.rb new file mode 100644 index 0000000..df8268e --- /dev/null +++ b/spec/factories/survey_questions.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :survey_question, :class => 'Survey::Question' do + title "MyString" +text "MyText" +typ 1 + end + +end diff --git a/spec/helpers/survey/answers_helper_spec.rb b/spec/helpers/survey/answers_helper_spec.rb new file mode 100644 index 0000000..cdf297c --- /dev/null +++ b/spec/helpers/survey/answers_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Survey::AnswersHelper. For example: +# +# describe Survey::AnswersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Survey::AnswersHelper, :type => :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/survey/choices_helper_spec.rb b/spec/helpers/survey/choices_helper_spec.rb new file mode 100644 index 0000000..8a2f708 --- /dev/null +++ b/spec/helpers/survey/choices_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Survey::ChoicesHelper. For example: +# +# describe Survey::ChoicesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Survey::ChoicesHelper, :type => :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/survey/questions_helper_spec.rb b/spec/helpers/survey/questions_helper_spec.rb new file mode 100644 index 0000000..c54cf52 --- /dev/null +++ b/spec/helpers/survey/questions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Survey::QuestionsHelper. For example: +# +# describe Survey::QuestionsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Survey::QuestionsHelper, :type => :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/survey/answer_spec.rb b/spec/models/survey/answer_spec.rb new file mode 100644 index 0000000..518fae0 --- /dev/null +++ b/spec/models/survey/answer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Survey::Answer, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/survey/choice_spec.rb b/spec/models/survey/choice_spec.rb new file mode 100644 index 0000000..31558cb --- /dev/null +++ b/spec/models/survey/choice_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Survey::Choice, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/survey/question_spec.rb b/spec/models/survey/question_spec.rb new file mode 100644 index 0000000..556c094 --- /dev/null +++ b/spec/models/survey/question_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Survey::Question, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/survey/survey_answers_spec.rb b/spec/requests/survey/survey_answers_spec.rb new file mode 100644 index 0000000..34ab404 --- /dev/null +++ b/spec/requests/survey/survey_answers_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Survey::Answers", :type => :request do + describe "GET /survey_answers" do + it "works! (now write some real specs)" do + get survey_answers_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/survey/survey_choices_spec.rb b/spec/requests/survey/survey_choices_spec.rb new file mode 100644 index 0000000..2627c04 --- /dev/null +++ b/spec/requests/survey/survey_choices_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Survey::Choices", :type => :request do + describe "GET /survey_choices" do + it "works! (now write some real specs)" do + get survey_choices_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/survey/survey_questions_spec.rb b/spec/requests/survey/survey_questions_spec.rb new file mode 100644 index 0000000..89d048e --- /dev/null +++ b/spec/requests/survey/survey_questions_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Survey::Questions", :type => :request do + describe "GET /survey_questions" do + it "works! (now write some real specs)" do + get survey_questions_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/survey/answers_routing_spec.rb b/spec/routing/survey/answers_routing_spec.rb new file mode 100644 index 0000000..886637e --- /dev/null +++ b/spec/routing/survey/answers_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Survey::AnswersController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/survey/answers").to route_to("survey/answers#index") + end + + it "routes to #new" do + expect(:get => "/survey/answers/new").to route_to("survey/answers#new") + end + + it "routes to #show" do + expect(:get => "/survey/answers/1").to route_to("survey/answers#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/survey/answers/1/edit").to route_to("survey/answers#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/survey/answers").to route_to("survey/answers#create") + end + + it "routes to #update" do + expect(:put => "/survey/answers/1").to route_to("survey/answers#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/survey/answers/1").to route_to("survey/answers#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/survey/choices_routing_spec.rb b/spec/routing/survey/choices_routing_spec.rb new file mode 100644 index 0000000..b181088 --- /dev/null +++ b/spec/routing/survey/choices_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Survey::ChoicesController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/survey/choices").to route_to("survey/choices#index") + end + + it "routes to #new" do + expect(:get => "/survey/choices/new").to route_to("survey/choices#new") + end + + it "routes to #show" do + expect(:get => "/survey/choices/1").to route_to("survey/choices#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/survey/choices/1/edit").to route_to("survey/choices#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/survey/choices").to route_to("survey/choices#create") + end + + it "routes to #update" do + expect(:put => "/survey/choices/1").to route_to("survey/choices#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/survey/choices/1").to route_to("survey/choices#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/survey/questions_routing_spec.rb b/spec/routing/survey/questions_routing_spec.rb new file mode 100644 index 0000000..ce1a8e2 --- /dev/null +++ b/spec/routing/survey/questions_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Survey::QuestionsController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/survey/questions").to route_to("survey/questions#index") + end + + it "routes to #new" do + expect(:get => "/survey/questions/new").to route_to("survey/questions#new") + end + + it "routes to #show" do + expect(:get => "/survey/questions/1").to route_to("survey/questions#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/survey/questions/1/edit").to route_to("survey/questions#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/survey/questions").to route_to("survey/questions#create") + end + + it "routes to #update" do + expect(:put => "/survey/questions/1").to route_to("survey/questions#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/survey/questions/1").to route_to("survey/questions#destroy", :id => "1") + end + + end +end diff --git a/spec/views/survey/answers/edit.html.erb_spec.rb b/spec/views/survey/answers/edit.html.erb_spec.rb new file mode 100644 index 0000000..fb32ce8 --- /dev/null +++ b/spec/views/survey/answers/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "survey/answers/edit", :type => :view do + before(:each) do + @survey_answer = assign(:survey_answer, Survey::Answer.create!( + :choice => nil, + :user => nil + )) + end + + it "renders the edit survey_answer form" do + render + + assert_select "form[action=?][method=?]", survey_answer_path(@survey_answer), "post" do + + assert_select "input#survey_answer_choice[name=?]", "survey_answer[choice]" + + assert_select "input#survey_answer_user[name=?]", "survey_answer[user]" + end + end +end diff --git a/spec/views/survey/answers/index.html.erb_spec.rb b/spec/views/survey/answers/index.html.erb_spec.rb new file mode 100644 index 0000000..2ed2992 --- /dev/null +++ b/spec/views/survey/answers/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "survey/answers/index", :type => :view do + before(:each) do + assign(:survey_answers, [ + Survey::Answer.create!( + :choice => nil, + :user => nil + ), + Survey::Answer.create!( + :choice => nil, + :user => nil + ) + ]) + end + + it "renders a list of survey/answers" do + render + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + end +end diff --git a/spec/views/survey/answers/new.html.erb_spec.rb b/spec/views/survey/answers/new.html.erb_spec.rb new file mode 100644 index 0000000..72f554f --- /dev/null +++ b/spec/views/survey/answers/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "survey/answers/new", :type => :view do + before(:each) do + assign(:survey_answer, Survey::Answer.new( + :choice => nil, + :user => nil + )) + end + + it "renders new survey_answer form" do + render + + assert_select "form[action=?][method=?]", survey_answers_path, "post" do + + assert_select "input#survey_answer_choice[name=?]", "survey_answer[choice]" + + assert_select "input#survey_answer_user[name=?]", "survey_answer[user]" + end + end +end diff --git a/spec/views/survey/answers/show.html.erb_spec.rb b/spec/views/survey/answers/show.html.erb_spec.rb new file mode 100644 index 0000000..012c887 --- /dev/null +++ b/spec/views/survey/answers/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "survey/answers/show", :type => :view do + before(:each) do + @survey_answer = assign(:survey_answer, Survey::Answer.create!( + :choice => nil, + :user => nil + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(//) + expect(rendered).to match(//) + end +end diff --git a/spec/views/survey/choices/edit.html.erb_spec.rb b/spec/views/survey/choices/edit.html.erb_spec.rb new file mode 100644 index 0000000..3871864 --- /dev/null +++ b/spec/views/survey/choices/edit.html.erb_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe "survey/choices/edit", :type => :view do + before(:each) do + @survey_choice = assign(:survey_choice, Survey::Choice.create!( + :text => "MyString", + :question => nil, + :sort => 1, + :picture => "MyString" + )) + end + + it "renders the edit survey_choice form" do + render + + assert_select "form[action=?][method=?]", survey_choice_path(@survey_choice), "post" do + + assert_select "input#survey_choice_text[name=?]", "survey_choice[text]" + + assert_select "input#survey_choice_question[name=?]", "survey_choice[question]" + + assert_select "input#survey_choice_sort[name=?]", "survey_choice[sort]" + + assert_select "input#survey_choice_picture[name=?]", "survey_choice[picture]" + end + end +end diff --git a/spec/views/survey/choices/index.html.erb_spec.rb b/spec/views/survey/choices/index.html.erb_spec.rb new file mode 100644 index 0000000..49b96b6 --- /dev/null +++ b/spec/views/survey/choices/index.html.erb_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +RSpec.describe "survey/choices/index", :type => :view do + before(:each) do + assign(:survey_choices, [ + Survey::Choice.create!( + :text => "Text", + :question => nil, + :sort => 1, + :picture => "Picture" + ), + Survey::Choice.create!( + :text => "Text", + :question => nil, + :sort => 1, + :picture => "Picture" + ) + ]) + end + + it "renders a list of survey/choices" do + render + assert_select "tr>td", :text => "Text".to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => 1.to_s, :count => 2 + assert_select "tr>td", :text => "Picture".to_s, :count => 2 + end +end diff --git a/spec/views/survey/choices/new.html.erb_spec.rb b/spec/views/survey/choices/new.html.erb_spec.rb new file mode 100644 index 0000000..ec80eb4 --- /dev/null +++ b/spec/views/survey/choices/new.html.erb_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe "survey/choices/new", :type => :view do + before(:each) do + assign(:survey_choice, Survey::Choice.new( + :text => "MyString", + :question => nil, + :sort => 1, + :picture => "MyString" + )) + end + + it "renders new survey_choice form" do + render + + assert_select "form[action=?][method=?]", survey_choices_path, "post" do + + assert_select "input#survey_choice_text[name=?]", "survey_choice[text]" + + assert_select "input#survey_choice_question[name=?]", "survey_choice[question]" + + assert_select "input#survey_choice_sort[name=?]", "survey_choice[sort]" + + assert_select "input#survey_choice_picture[name=?]", "survey_choice[picture]" + end + end +end diff --git a/spec/views/survey/choices/show.html.erb_spec.rb b/spec/views/survey/choices/show.html.erb_spec.rb new file mode 100644 index 0000000..6dd5663 --- /dev/null +++ b/spec/views/survey/choices/show.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe "survey/choices/show", :type => :view do + before(:each) do + @survey_choice = assign(:survey_choice, Survey::Choice.create!( + :text => "Text", + :question => nil, + :sort => 1, + :picture => "Picture" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Text/) + expect(rendered).to match(//) + expect(rendered).to match(/1/) + expect(rendered).to match(/Picture/) + end +end diff --git a/spec/views/survey/questions/edit.html.erb_spec.rb b/spec/views/survey/questions/edit.html.erb_spec.rb new file mode 100644 index 0000000..7875849 --- /dev/null +++ b/spec/views/survey/questions/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "survey/questions/edit", :type => :view do + before(:each) do + @survey_question = assign(:survey_question, Survey::Question.create!( + :title => "MyString", + :text => "MyText", + :typ => 1 + )) + end + + it "renders the edit survey_question form" do + render + + assert_select "form[action=?][method=?]", survey_question_path(@survey_question), "post" do + + assert_select "input#survey_question_title[name=?]", "survey_question[title]" + + assert_select "textarea#survey_question_text[name=?]", "survey_question[text]" + + assert_select "input#survey_question_typ[name=?]", "survey_question[typ]" + end + end +end diff --git a/spec/views/survey/questions/index.html.erb_spec.rb b/spec/views/survey/questions/index.html.erb_spec.rb new file mode 100644 index 0000000..f7b7806 --- /dev/null +++ b/spec/views/survey/questions/index.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe "survey/questions/index", :type => :view do + before(:each) do + assign(:survey_questions, [ + Survey::Question.create!( + :title => "Title", + :text => "MyText", + :typ => 1 + ), + Survey::Question.create!( + :title => "Title", + :text => "MyText", + :typ => 1 + ) + ]) + end + + it "renders a list of survey/questions" do + render + assert_select "tr>td", :text => "Title".to_s, :count => 2 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + assert_select "tr>td", :text => 1.to_s, :count => 2 + end +end diff --git a/spec/views/survey/questions/new.html.erb_spec.rb b/spec/views/survey/questions/new.html.erb_spec.rb new file mode 100644 index 0000000..940a2cb --- /dev/null +++ b/spec/views/survey/questions/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "survey/questions/new", :type => :view do + before(:each) do + assign(:survey_question, Survey::Question.new( + :title => "MyString", + :text => "MyText", + :typ => 1 + )) + end + + it "renders new survey_question form" do + render + + assert_select "form[action=?][method=?]", survey_questions_path, "post" do + + assert_select "input#survey_question_title[name=?]", "survey_question[title]" + + assert_select "textarea#survey_question_text[name=?]", "survey_question[text]" + + assert_select "input#survey_question_typ[name=?]", "survey_question[typ]" + end + end +end diff --git a/spec/views/survey/questions/show.html.erb_spec.rb b/spec/views/survey/questions/show.html.erb_spec.rb new file mode 100644 index 0000000..9c85d5a --- /dev/null +++ b/spec/views/survey/questions/show.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "survey/questions/show", :type => :view do + before(:each) do + @survey_question = assign(:survey_question, Survey::Question.create!( + :title => "Title", + :text => "MyText", + :typ => 1 + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Title/) + expect(rendered).to match(/MyText/) + expect(rendered).to match(/1/) + end +end