diff --git a/Gemfile.lock b/Gemfile.lock index 3f90168..568e59c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,14 @@ PATH remote: . specs: - helena (0.2.2) + helena (0.3.0) bootstrap-sass breadcrumbs_on_rails haml haml-rails jquery-rails liquid - mongoid (~> 4.0.0.beta1) + mongoid (~> 4.0.0.rc2) mongoid-simple-tags mongoid_orderable rails (~> 4.1.1) @@ -107,7 +107,7 @@ GEM highline (1.6.21) hike (1.2.3) i18n (0.6.9) - i18n-tasks (0.4.5) + i18n-tasks (0.5.1) activesupport easy_translate (>= 0.5.0) erubis @@ -115,7 +115,7 @@ GEM slop (>= 3.5.0) term-ansicolor terminal-table - jquery-rails (3.1.0) + jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) @@ -129,9 +129,9 @@ GEM mime-types (1.25.1) mini_portile (0.6.0) minitest (5.3.5) - mongoid (4.0.0.rc2) + mongoid (4.0.0) activemodel (~> 4.0) - moped (~> 2.0.0.rc2) + moped (~> 2.0.0) origin (~> 2.1) tzinfo (>= 0.3.37) mongoid-rspec (1.10.0) @@ -143,7 +143,7 @@ GEM mongoid (>= 3.0.3) mongoid_orderable (4.1.0) mongoid - moped (2.0.0.rc2) + moped (2.0.0) bson (~> 2.2) connection_pool (~> 2.0) optionable (~> 0.2.0) @@ -207,7 +207,7 @@ GEM rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) - rspec-support (3.0.1) + rspec-support (3.0.2) ruby-progressbar (1.5.1) rubyzip (1.1.4) sass (3.2.19) diff --git a/app/assets/images/helena/icons/export.svg b/app/assets/images/helena/icons/export.svg new file mode 100644 index 0000000..52688c3 --- /dev/null +++ b/app/assets/images/helena/icons/export.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/app/assets/stylesheets/helena/admin/layout.css.sass b/app/assets/stylesheets/helena/admin/layout.css.sass new file mode 100644 index 0000000..9ce35c5 --- /dev/null +++ b/app/assets/stylesheets/helena/admin/layout.css.sass @@ -0,0 +1,6 @@ +.helena-admin + .actions + font-size: 18pt + + .icon + width: 70px diff --git a/app/assets/stylesheets/helena/layouts.css.sass b/app/assets/stylesheets/helena/layout.css.sass similarity index 100% rename from app/assets/stylesheets/helena/layouts.css.sass rename to app/assets/stylesheets/helena/layout.css.sass diff --git a/app/controllers/helena/admin/question_groups_controller.rb b/app/controllers/helena/admin/question_groups_controller.rb index b723caa..9dc59f4 100644 --- a/app/controllers/helena/admin/question_groups_controller.rb +++ b/app/controllers/helena/admin/question_groups_controller.rb @@ -22,8 +22,6 @@ def create if @question_group.save notify_successful_create_for(@question_group.title) - else - notify_error end respond_with @question_group, location: admin_survey_question_groups_path(@survey) end @@ -37,9 +35,6 @@ def update if @question_group.update_attributes question_group_params notify_successful_update_for(@question_group.title) - else - notify_error - add_breadcrumb @question_group.title_was end respond_with @question_group, location: admin_survey_question_groups_path(@survey) end diff --git a/app/controllers/helena/admin/sessions_controller.rb b/app/controllers/helena/admin/sessions_controller.rb index 671edbc..66fe09b 100644 --- a/app/controllers/helena/admin/sessions_controller.rb +++ b/app/controllers/helena/admin/sessions_controller.rb @@ -6,7 +6,12 @@ class SessionsController < Admin::ApplicationController before_filter :load_survey, :add_breadcrumbs def index - @sessions = @survey.sessions.desc(:created_at) + respond_to do |format| + @sessions = @survey.sessions.desc(:created_at) + format.html + format.json { render json: @sessions } + format.csv { render text: @sessions.to_csv } + end end def destroy diff --git a/app/controllers/helena/admin/versions_controller.rb b/app/controllers/helena/admin/versions_controller.rb index 83aa271..eb09295 100644 --- a/app/controllers/helena/admin/versions_controller.rb +++ b/app/controllers/helena/admin/versions_controller.rb @@ -34,7 +34,7 @@ def update def destroy @version = @survey.versions.find_by id: params[:id] - notify_successful_delete_for(@version.version) if @version.destroy + notify_successful_delete_for(@version.version) if @version.destroy && Helena::Session.where(version: @version).destroy respond_with @version, location: admin_survey_versions_path(@survey) end diff --git a/app/models/helena/session.rb b/app/models/helena/session.rb index 7f22a19..e1218a8 100644 --- a/app/models/helena/session.rb +++ b/app/models/helena/session.rb @@ -22,8 +22,39 @@ def reset_tokens self.view_token = generate_token(25) until unique_token_for?(:view_token) end + def self.to_csv + CSV.generate do |csv| + csv << fields.keys + uniq_answer_codes + all.each do |session| + csv << session.attributes.values_at(*fields.keys) + answer_values_in(session) + end + end + end + private + def self.answer_values_in(session) + answers = [] + answer_codes.each do |code| + answers << session.answers.where(code: code).first.try(&:value) + end + answers + end + + def self.answer_codes + answer_codes = [] + all.each do |session| + answer_codes += session.answers.map(&:code) - answer_codes + end + answer_codes + end + + def self.uniq_answer_codes + answer_codes.map do |code| + fields.keys.include?(code) ? "answer_#{code}" : code + end + end + def generate_token(size) SecureRandom.base64(size).delete('/+=')[0, size] end diff --git a/app/views/helena/admin/question_groups/index.html.haml b/app/views/helena/admin/question_groups/index.html.haml index ef17093..8035ed8 100644 --- a/app/views/helena/admin/question_groups/index.html.haml +++ b/app/views/helena/admin/question_groups/index.html.haml @@ -16,9 +16,9 @@ %tbody - @question_groups.each do |question_group| %tr[question_group] - %td.position{ data: { title: Helena::QuestionGroup.human_attribute_name(:position) } } + %td.position = question_group.position - %td.title{ data: { title: Helena::QuestionGroup.human_attribute_name(:title) } } + %td.title = question_group.title %td .btn-group.btn-group-sm diff --git a/app/views/helena/admin/questions/_labels.html.haml b/app/views/helena/admin/questions/_labels.html.haml index 5be6ec3..ccc1f2a 100644 --- a/app/views/helena/admin/questions/_labels.html.haml +++ b/app/views/helena/admin/questions/_labels.html.haml @@ -11,13 +11,13 @@ %tbody = form.simple_fields_for :labels do |label| %tr[label.object] - %td.position{ data: { title: Helena::Label.human_attribute_name(:position) } } + %td.position = label.input :position, as: :integer, label: false - %td.preselected{ data: { title: Helena::Label.human_attribute_name(:preselected) } } + %td.preselected = label.input :preselected, as: :boolean, wrapper: :checkbox, label: Helena::Label.human_attribute_name(:preselected) - %td.text{ data: { title: Helena::Label.human_attribute_name(:text) } } + %td.text = label.input :text, label: false - %td.value{ data: { title: Helena::Label.human_attribute_name(:value) } } + %td.value = label.input :value, label: false %td.delete - unless label.object.new_record? diff --git a/app/views/helena/admin/questions/_sub_questions.html.haml b/app/views/helena/admin/questions/_sub_questions.html.haml index a80157b..65f091e 100644 --- a/app/views/helena/admin/questions/_sub_questions.html.haml +++ b/app/views/helena/admin/questions/_sub_questions.html.haml @@ -14,17 +14,17 @@ %tbody = form.simple_fields_for :sub_questions do |sub_question| %tr[sub_question.object] - %td.position{ data: { title: Helena::SubQuestion.human_attribute_name(:position) } } + %td.position = sub_question.input :position, as: :integer, label: false - %td.code{ data: { title: Helena::SubQuestion.human_attribute_name(:code) } } + %td.code = sub_question.input :code, label: false, hint: t('shared.code_hint') - if @question.is_a?(Helena::Questions::CheckboxGroup) - %td.preselected{ data: { title: Helena::SubQuestion.human_attribute_name(:preselected) } } + %td.preselected = sub_question.input :preselected, as: :boolean, wrapper: :checkbox - %td.text{ data: { title: Helena::SubQuestion.human_attribute_name(:text) } } + %td.text = sub_question.input :text, label: false - if @question.is_a?(Helena::Questions::CheckboxGroup) - %td.value{ data: { title: Helena::SubQuestion.human_attribute_name(:value) } } + %td.value = sub_question.input :value, label: false, as: :hidden, value: 1 %td.delete - unless sub_question.object.new_record? diff --git a/app/views/helena/admin/questions/index.html.haml b/app/views/helena/admin/questions/index.html.haml index 13ffdea..41a80ad 100644 --- a/app/views/helena/admin/questions/index.html.haml +++ b/app/views/helena/admin/questions/index.html.haml @@ -18,15 +18,15 @@ %tbody - @questions.each_with_index do |question, index| %tr[question] - %td.position{ data: { title: Helena::Question.human_attribute_name(:position) } } + %td.position = question.position - %td.code{ data: { title: Helena::Question.human_attribute_name(:code) } } + %td.code = question.code - %td.type{ data: { title: Helena::Question.human_attribute_name(:type) } } + %td.type = question.class.model_name.human - if question.try :required %span.glyphicon.glyphicon-flag{ title: Helena::Question.human_attribute_name(:require) } - %td.question_text{ data: { title: Helena::Question.human_attribute_name(:question_text) } } + %td.question_text = question.question_text %td .btn-group.btn-group-sm diff --git a/app/views/helena/admin/sessions/index.html.haml b/app/views/helena/admin/sessions/index.html.haml index baf9345..98368d3 100644 --- a/app/views/helena/admin/sessions/index.html.haml +++ b/app/views/helena/admin/sessions/index.html.haml @@ -1,11 +1,17 @@ .helena-admin - %h2 - = Helena::Session.model_name.human(count: 2) - = "(#{@sessions.count})" - if @sessions.empty? .alert.alert-warning = t '.empty' - else + .actions + = link_to admin_survey_sessions_path(@survey, format: :csv) do + = image_tag('helena/icons/export.svg', class: :icon) + = t('.export_sessions_csv') + = link_to admin_survey_sessions_path(@survey, format: :json) do + = t('.export_sessions_json') + %h2 + = Helena::Session.model_name.human(count: 2) + = "(#{@sessions.count})" .table-responsive %table.table.sessions %thead @@ -13,19 +19,22 @@ %th.updated_at= Helena::Session.human_attribute_name(:updated_at) %th.token= Helena::Session.human_attribute_name(:token) %th.completed= Helena::Session.human_attribute_name(:completed) + %th.version= Helena::Session.human_attribute_name(:version) %th.answers= Helena::Session.human_attribute_name(:answers) %th %tbody - @sessions.each do |session| %tr[session] - %td.updated_at{ data: { title: Helena::Session.human_attribute_name(:updated_at) } } + %td.updated_at = time_ago_in_words(session.updated_at) - %td.token{ data: { title: Helena::Session.human_attribute_name(:token) } } + %td.token = session.token - %td.completed{ data: { title: Helena::Session.human_attribute_name(:completed) } } + %td.completed .label{class: "label-#{session.completed? ? 'success' : 'danger'}"} = t ".#{session.completed}" - %td.answers{ data: { title: Helena::Session.human_attribute_name(:answers) } } + %td.version + = @survey.versions.find(session.version_id).version if session.version_id + %td.answers = session.answers.count %td diff --git a/app/views/helena/admin/versions/index.html.haml b/app/views/helena/admin/versions/index.html.haml index 27608ca..d75e9a4 100644 --- a/app/views/helena/admin/versions/index.html.haml +++ b/app/views/helena/admin/versions/index.html.haml @@ -12,16 +12,19 @@ %tr %th.version= Helena::Version.human_attribute_name(:version) %th.notes= Helena::Version.human_attribute_name(:notes) + %th.sessions= Helena::Session.model_name.human(count: 2) %th.created_at= Helena::Version.human_attribute_name(:created_at) %th %tbody - @versions.each do |version| %tr[version] - %td.version{ data: { title: Helena::Version.human_attribute_name(:version) } } + %td.version = version.version - %td.notes{ data: { title: Helena::Version.human_attribute_name(:notes) } } + %td.notes = version.notes - %td.created_at{ data: { title: Helena::Version.human_attribute_name(:created_at) } } + %td.sessions + = Helena::Session.where(version: version).count + %td.created_at = time_ago_in_words(version.created_at) %td .btn-group diff --git a/config/locales/views/admin/sessions/en.yml b/config/locales/views/admin/sessions/en.yml index 5538591..7445917 100644 --- a/config/locales/views/admin/sessions/en.yml +++ b/config/locales/views/admin/sessions/en.yml @@ -7,3 +7,5 @@ en: 'false': "No" 'true': "Yes" edit: Edit + export_sessions_csv: I want to export all session from this survey to my local computer as CSV + export_sessions_json: ... or as JSON diff --git a/helena.gemspec b/helena.gemspec index 8749399..c84de8e 100644 --- a/helena.gemspec +++ b/helena.gemspec @@ -19,7 +19,7 @@ survey/test development, longitudinal studies and instant feedback.' s.test_files = `git ls-files -- {spec}/*`.split("\n") s.add_dependency 'rails', '~> 4.1.1' - s.add_dependency 'mongoid', '~> 4.0.0.beta1' + s.add_dependency 'mongoid', '~> 4.0.0.rc2' s.add_dependency 'mongoid_orderable' s.add_dependency 'mongoid-simple-tags' s.add_dependency 'haml' @@ -33,7 +33,7 @@ survey/test development, longitudinal studies and instant feedback.' s.add_dependency 'liquid' s.add_development_dependency 'rspec-rails' - s.add_development_dependency 'rspec-collection_matchers' + s.add_development_dependency 'rspec-collection_matchers' s.add_development_dependency 'mongoid-rspec' s.add_development_dependency 'factory_girl_rails' s.add_development_dependency 'database_cleaner' diff --git a/lib/helena.rb b/lib/helena.rb index 9f14452..1d6fbf1 100644 --- a/lib/helena.rb +++ b/lib/helena.rb @@ -5,6 +5,7 @@ require 'mongoid_orderable' require 'mongoid-simple-tags' require 'liquid' +require 'csv' module Helena end diff --git a/lib/helena/version.rb b/lib/helena/version.rb index 6a83698..e42338d 100644 --- a/lib/helena/version.rb +++ b/lib/helena/version.rb @@ -1,3 +1,3 @@ module Helena - VERSION = '0.2.2' + VERSION = '0.3.0' end diff --git a/lib/helena/version_publisher.rb b/lib/helena/version_publisher.rb index 7b245a6..3b05545 100644 --- a/lib/helena/version_publisher.rb +++ b/lib/helena/version_publisher.rb @@ -4,6 +4,8 @@ def self.publish(version) copied_version = version.dup copied_version.survey = version.survey copied_version.version = newest_version_of(version.survey) + 1 + copied_version.created_at = DateTime.now + copied_version.updated_at = DateTime.now copied_version end diff --git a/spec/controllers/helena/admin/sessions_controller_spec.rb b/spec/controllers/helena/admin/sessions_controller_spec.rb new file mode 100644 index 0000000..dedfe29 --- /dev/null +++ b/spec/controllers/helena/admin/sessions_controller_spec.rb @@ -0,0 +1,84 @@ +require 'spec_helper' + +describe Helena::Admin::SessionsController do + routes { Helena::Engine.routes } + + let(:survey) { create :survey } + + context 'without authorization' do + before { allow_any_instance_of(ApplicationController).to receive(:can_administer?).and_return false } + + specify 'trying to list surveys throws an error' do + expect { get :index, survey_id: survey }.to raise_error(ActionController::RoutingError, 'Access Denied') + end + + specify 'trying to export surveys as json throws an error' do + expect { get :index, survey_id: survey, format: :json }.to raise_error(ActionController::RoutingError, 'Access Denied') + end + + specify 'trying to export surveys as csv throws an error' do + expect { get :index, survey_id: survey, format: :csv }.to raise_error(ActionController::RoutingError, 'Access Denied') + end + end + + context 'with authorization' do + before do + create :session, survey: survey, answers: [ + build(:string_answer, code: 'string_answer_1', value: 'abc'), + build(:integer_answer, code: 'integer_answer_1', value: '123') + ] + create :session, survey: survey, answers: [ + build(:string_answer, code: 'string_answer_2', value: 'def, xyz'), + build(:integer_answer, code: 'integer_answer_2', value: '456') + ] + end + + it 'return json result of all sessions' do + get :index, survey_id: survey, format: :json + + first_result = ActiveSupport::JSON.decode(response.body).first + + expect(first_result['answers'].first['code']).to eq 'string_answer_2' + expect(first_result['answers'].first['value']).to eq 'def, xyz' + expect(first_result['answers'].last['code']).to eq 'integer_answer_2' + expect(first_result['answers'].last['value']).to eq 456 + + last_result = ActiveSupport::JSON.decode(response.body).last + + expect(last_result['answers'].first['code']).to eq 'string_answer_1' + expect(last_result['answers'].first['value']).to eq 'abc' + expect(last_result['answers'].last['code']).to eq 'integer_answer_1' + expect(last_result['answers'].last['value']).to eq 123 + end + + it 'return csv result of all sessions' do + get :index, survey_id: survey, format: :csv + + csv = CSV.parse(response.body) + %w(string_answer_2 integer_answer_2 string_answer_1 integer_answer_1).each do |code| + expect(csv.first).to include code + end + + ['456', 'def, xyz'].each do |value| + expect(csv[1]).to include value + end + + %w(123 abc).each do |value| + expect(csv[2]).to include value + end + end + + specify 'csv header for all sessions does not allow same column names for answers and session fields' do + create :session, survey: survey, answers: [ + build(:boolean_answer, code: 'completed', value: true), + build(:string_answer, code: 'token', value: 'abcdefghijklmnopqrstuvwxyz') + ] + get :index, survey_id: survey, format: :csv + + csv = CSV.parse(response.body) + %w(answer_token answer_completed).each do |code| + expect(csv.first).to include code + end + end + end +end diff --git a/spec/controllers/helena/admin/versions_controller_spec.rb b/spec/controllers/helena/admin/versions_controller_spec.rb new file mode 100644 index 0000000..0c71e13 --- /dev/null +++ b/spec/controllers/helena/admin/versions_controller_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Helena::Admin::VersionsController do + routes { Helena::Engine.routes } + + let(:survey) { create :survey } + let(:baseversion) { survey.versions.create version: 0 } + + context 'with authorization' do + it 'deleting a version deletes also the associated sessions' do + published_version = Helena::VersionPublisher.publish baseversion + published_version.save + + create :session, survey: survey, version: published_version + + expect { delete :destroy, survey_id: survey, id: published_version }.to change { Helena::Session.count }.by(-1) + end + end +end diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cd..0000000 --- a/spec/dummy/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb deleted file mode 100644 index ac033bf..0000000 --- a/spec/dummy/config/initializers/inflections.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format. Inflections -# are locale specific, and you may define rules for as many different -# locales as you wish. All of these examples are active by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end - -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e..0000000 --- a/spec/dummy/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/spec/features/helena/admin/manage_question_spec.rb b/spec/features/helena/admin/manage_question_spec.rb index eb378d0..dac115c 100644 --- a/spec/features/helena/admin/manage_question_spec.rb +++ b/spec/features/helena/admin/manage_question_spec.rb @@ -38,6 +38,14 @@ expect { click_button 'Save' }.to change { question_group.reload.questions.count }.by(1) end + scenario 'creating a new question errors when without entering a code' do + visit helena.new_admin_survey_question_group_question_path(draft_version.survey, question_group) + + fill_in 'Code', with: '' + + expect { click_button 'Save' }.to change { question_group.reload.questions.count }.by(0) + end + scenario 'edits a question' do question = create :question, question_text: 'We are here?', question_group: question_group @@ -52,6 +60,16 @@ expect(question.reload.code).to eq 'b12' end + scenario 'edits a question errors when code text is empty' do + question = create :question, question_text: 'We are here?', question_group: question_group + + visit helena.edit_admin_survey_question_group_question_path(draft_version.survey, question.question_group, question) + + fill_in 'Code', with: '' + + expect{ click_button 'Save' }.not_to change { question.reload } + end + scenario 'moving a question' do first_question = create :question, question_group: question_group, position: 1 second_question = create :question, question_group: question_group, position: 2 diff --git a/spec/features/helena/admin/manage_session_spec.rb b/spec/features/helena/admin/manage_session_spec.rb index ce18542..35c23bd 100644 --- a/spec/features/helena/admin/manage_session_spec.rb +++ b/spec/features/helena/admin/manage_session_spec.rb @@ -6,6 +6,7 @@ @survey = create :survey baseversion = @survey.versions.create version: 0 @version = Helena::VersionPublisher.publish baseversion + @version.save end scenario 'lists all sessions of a survey' do @@ -32,7 +33,6 @@ session = @survey.sessions.create visit helena.admin_survey_sessions_path @survey - within "#helena_#{dom_id(session)}" do expect { click_link 'Delete' }.to change { @survey.sessions.count }.by(-1) end diff --git a/spec/features/helena/admin/manage_survey_spec.rb b/spec/features/helena/admin/manage_survey_spec.rb index 517ed3c..e92125c 100644 --- a/spec/features/helena/admin/manage_survey_spec.rb +++ b/spec/features/helena/admin/manage_survey_spec.rb @@ -42,7 +42,14 @@ end expect { click_button 'Save' }.to change { Helena::Survey.count }.by 1 + end + + scenario 'creates a new surveys errors without a name' do + visit helena.new_admin_survey_path + + fill_in 'Name', with: '' + expect { click_button 'Save' }.to change { Helena::Survey.count }.by 0 end scenario 'edits a survey' do diff --git a/spec/features/helena/admin/manage_version_spec.rb b/spec/features/helena/admin/manage_version_spec.rb index d87d3ff..3c061d6 100644 --- a/spec/features/helena/admin/manage_version_spec.rb +++ b/spec/features/helena/admin/manage_version_spec.rb @@ -17,7 +17,7 @@ expect(page).not_to have_selector "#helena_#{dom_id @baseversion}" # Base version is always the working version within "#helena_#{dom_id published_version}" do - expect(page).to have_text '1 bla bla less than a minute' + expect(page).to have_text '1 bla bla 0 less than a minute' end within '.breadcrumb' do diff --git a/spec/lib/version_publisher_spec.rb b/spec/lib/version_publisher_spec.rb index dc7723f..93b1c84 100644 --- a/spec/lib/version_publisher_spec.rb +++ b/spec/lib/version_publisher_spec.rb @@ -10,6 +10,8 @@ let!(:sub_question) { build(:sub_question, text: 'ymca', code: 'cde', question: question) } it 'creates a new version' do + allow(DateTime).to receive(:now).and_return('Tue, 24 Jun 2014 10:24:08 +0200') + new_version = Helena::VersionPublisher.publish(base_version) expect(new_version.version).to eq 43 @@ -18,5 +20,7 @@ expect(new_version.question_groups.first).to have_exactly(1).questions expect(new_version.question_groups.first.questions.first).to have_exactly(1).labels expect(new_version.question_groups.first.questions.first).to have_exactly(1).sub_questions + expect(new_version.created_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200' + expect(new_version.updated_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200' end end