From 94cad06e316b31a1c26a0741e5f7f10cd802dc30 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 26 Aug 2015 11:03:04 +0200 Subject: [PATCH 01/73] AutoCommit Mit Aug 26 11:03:04 CEST 2015 --- app/mailers/news_mailer.rb | 13 +++++++++++++ app/views/news_mailer/daily_reminder.html.erb | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 app/views/news_mailer/daily_reminder.html.erb diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb index 311708e..9d8e30d 100644 --- a/app/mailers/news_mailer.rb +++ b/app/mailers/news_mailer.rb @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + class NewsMailer < ActionMailer::Base default from: "salzamt@fet.at" helper :plugins @@ -17,7 +19,18 @@ render locals: {current_user: User.first} end def daily_newsletter(user_id) user=User.find(user_id) + self.message.perform_deliveries = false unless user.flag_getemails ability= Ability.new(user) + @neuigkeiten=Neuigkeit.accessible_by(ability).published_scope.where("cache_order<2") end + + def daily_reminder(user_id) + user=User.find(user_id) + self.message.perform_deliveries = false unless user.flag_getemails + ability = Ability.new(user) + @calentries = Calentry.limit(10) +# @neuigkeiten=Neuigkeit.accessiblße_by(ability).published_scope.where("cache_order<2") + end + end diff --git a/app/views/news_mailer/daily_reminder.html.erb b/app/views/news_mailer/daily_reminder.html.erb new file mode 100644 index 0000000..98ccbcd --- /dev/null +++ b/app/views/news_mailer/daily_reminder.html.erb @@ -0,0 +1,3 @@ +<%= @calentries.each do |ce| %> +<%= render @calentry%> +<% end %> From 1047851b4759e4bf9ef9a267bad2d5ccf3b75bc5 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 26 Aug 2015 12:03:05 +0200 Subject: [PATCH 02/73] AutoCommit Mit Aug 26 12:03:05 CEST 2015 --- app/mailers/news_mailer.rb | 20 +++++++++++++------ app/views/calentries/_mail.html.erb | 1 + app/views/neuigkeiten/_mail.html.erb | 10 ++++++++++ app/views/news_mailer/daily_reminder.html.erb | 12 +++++++++-- config/environments/development.rb | 2 +- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 app/views/calentries/_mail.html.erb create mode 100644 app/views/neuigkeiten/_mail.html.erb diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb index 9d8e30d..9a283f6 100644 --- a/app/mailers/news_mailer.rb +++ b/app/mailers/news_mailer.rb @@ -3,9 +3,7 @@ class NewsMailer < ActionMailer::Base default from: "salzamt@fet.at" helper :plugins - def current_user - @user - end + def neuigkeit_mail(email, neuigkeit_id) @neuigkeit= Neuigkeit.find(neuigkeit_id) @user=User.first @@ -27,10 +25,20 @@ render locals: {current_user: User.first} def daily_reminder(user_id) user=User.find(user_id) + @user=user self.message.perform_deliveries = false unless user.flag_getemails - ability = Ability.new(user) - @calentries = Calentry.limit(10) + @ability = Ability.new(user) + @calentries = Calentry.limit(100) # @neuigkeiten=Neuigkeit.accessiblße_by(ability).published_scope.where("cache_order<2") + mail(to: user.email, content_type: "text/html", subject: "sdf") + render locals: {c_user: user} + end +private +include CanCan::ControllerAdditions + def current_user + @user end - + def current_ability + @ability + end end diff --git a/app/views/calentries/_mail.html.erb b/app/views/calentries/_mail.html.erb new file mode 100644 index 0000000..9c75a7e --- /dev/null +++ b/app/views/calentries/_mail.html.erb @@ -0,0 +1 @@ +<%= mail.icon_text %> diff --git a/app/views/neuigkeiten/_mail.html.erb b/app/views/neuigkeiten/_mail.html.erb new file mode 100644 index 0000000..543eea2 --- /dev/null +++ b/app/views/neuigkeiten/_mail.html.erb @@ -0,0 +1,10 @@ +

+ <%= mail.title%> +

+<%= content_tag(:img,"",src: "http://" + ActionMailer::Base.default_url_options[:host].to_s + mail.picture.big_thumb.url.to_s) %> +<%=url_for controller: "neuigkeiten",action: :show, :id=>mail.id, only_path: false %> +<%= raw(mail.text) %> +<% mail.questions.each do |q| %> +<%= render partial:"survey/questions/mail", object: q %> +<% end %> +<%= link_to "Auf Fet.at weiterlesen", rubrik_neuigkeit_url(mail.rubrik, mail,:locale=>:de, :theme=>nil) %> diff --git a/app/views/news_mailer/daily_reminder.html.erb b/app/views/news_mailer/daily_reminder.html.erb index 98ccbcd..5b18aeb 100644 --- a/app/views/news_mailer/daily_reminder.html.erb +++ b/app/views/news_mailer/daily_reminder.html.erb @@ -1,3 +1,11 @@ -<%= @calentries.each do |ce| %> -<%= render @calentry%> + <%= stylesheet_link_tag "http://"+ActionMailer::Base.default_url_options[:host].to_s + "/assets/themes/blue2/application.css", :media=>"all" %> + +<% @calentries.each do |ce| %> +
+<% if can?(:show , ce.object) %> + <%= render partial: "calentries/mail", object: ce %> + <%= render partial: "neuigkeiten/mail", object: ce.object if ce.object.kind_of?(Neuigkeit)%> +<% end %> +
<% end %> + diff --git a/config/environments/development.rb b/config/environments/development.rb index e82fc64..c4acee2 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,7 +16,7 @@ Fetsite::Application.configure do # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method =:sendmail - config.action_mailer.default_url_options = {}#{:host=> "localhost", :port=>3000} # :host => 'glonass.htu.tuwien.ac.at' } + config.action_mailer.default_url_options = {:host=> "localhost", :port=>3000} # :host => 'glonass.htu.tuwien.ac.at' } # Print deprecation notices to the Rails logger config.active_support.deprecation = :log From 370c439c2944dc3b46f6f599768d483461ed89ac Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 27 Aug 2015 14:03:04 +0200 Subject: [PATCH 03/73] AutoCommit Don Aug 27 14:03:04 CEST 2015 --- app/models/calentry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/calentry.rb b/app/models/calentry.rb index b0908df..e25032e 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -21,7 +21,7 @@ class Calentry < ActiveRecord::Base validates :typ, :presence => true before_save :get_public belongs_to :object, polymorphic: true, touch: true # Objekt zu dem der Calentry gehört (derzeit ein Newsartikel) - + scope :of_month,(d) -> {where("start >= ? AND start <= ?", d.beginning_of_month, d.end_of_month)} scope :upcoming, ->{ where("start >= ?", Time.now).order(:start)} scope :recent,-> { where("start <= ?", Time.now).order(:start).reverse_order} validate do |entry| From 7c2f1f9753bb190aee5646444bb5600bc9500e6a Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 27 Aug 2015 15:03:02 +0200 Subject: [PATCH 04/73] AutoCommit Don Aug 27 15:03:02 CEST 2015 --- app/controllers/emails_controller.rb | 7 +++++++ app/controllers/rubriken_controller.rb | 2 +- app/mailers/news_mailer.rb | 2 +- app/models/ability.rb | 3 ++- app/models/calentry.rb | 9 ++++++--- app/models/survey/answer.rb | 2 +- app/models/survey/choice.rb | 2 +- app/models/survey/question.rb | 2 +- app/views/news_mailer/daily_reminder.html.erb | 3 ++- config/routes.rb | 5 ++++- 10 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 app/controllers/emails_controller.rb diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb new file mode 100644 index 0000000..7a96c05 --- /dev/null +++ b/app/controllers/emails_controller.rb @@ -0,0 +1,7 @@ +class EmailsController < ApplicationController + load_and_authorize_resource + + def index + + end +end diff --git a/app/controllers/rubriken_controller.rb b/app/controllers/rubriken_controller.rb index b6c5e0e..966edf1 100755 --- a/app/controllers/rubriken_controller.rb +++ b/app/controllers/rubriken_controller.rb @@ -16,7 +16,7 @@ class RubrikenController < ApplicationController @rubriken= Rubrik.accessible_by(current_ability, :show) @neuigkeiten = Neuigkeit.accessible_by(current_ability, :list).page(params[:page]).per(3) - @calentries= (@rubriken.map {|r| r.calendar}).collect(&:calentries).flatten.select {|c| c.object !=nil} + @calentries= (@rubriken.map {|r| r.calendar.calentries.of_month(Date.new(params[:year],params[:month],1))}).flatten.select {|c| c.object !=nil} respond_to do |format| format.html format.js {render action: :show} diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb index 9a283f6..bfb3b1a 100644 --- a/app/mailers/news_mailer.rb +++ b/app/mailers/news_mailer.rb @@ -28,7 +28,7 @@ render locals: {current_user: User.first} @user=user self.message.perform_deliveries = false unless user.flag_getemails @ability = Ability.new(user) - @calentries = Calentry.limit(100) + @calentries = Calentry.of_month(Date.today).limit(100) # @neuigkeiten=Neuigkeit.accessiblße_by(ability).published_scope.where("cache_order<2") mail(to: user.email, content_type: "text/html", subject: "sdf") render locals: {c_user: user} diff --git a/app/models/ability.rb b/app/models/ability.rb index 6dfe69d..d59a3bf 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -227,7 +227,8 @@ end can :doadmin, User end - unless user.has_role?("fetadmin") + if user.has_role?("fetadmin") + end end diff --git a/app/models/calentry.rb b/app/models/calentry.rb index e25032e..6421632 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -14,14 +14,14 @@ class Calentry < ActiveRecord::Base attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar, :dauer, :object_id, :object_type - belongs_to :calendar + belongs_to :calendar, touch: true #belongs_to :neuigkeit validates :start, :presence => true validates :object, :presence => true validates :typ, :presence => true before_save :get_public belongs_to :object, polymorphic: true, touch: true # Objekt zu dem der Calentry gehört (derzeit ein Newsartikel) - scope :of_month,(d) -> {where("start >= ? AND start <= ?", d.beginning_of_month, d.end_of_month)} + scope :of_month, ->(d) {where("start >= ? AND start <= ?", d.beginning_of_month, d.end_of_month)} scope :upcoming, ->{ where("start >= ?", Time.now).order(:start)} scope :recent,-> { where("start <= ?", Time.now).order(:start).reverse_order} validate do |entry| @@ -31,7 +31,10 @@ class Calentry < ActiveRecord::Base end resourcify - + def self.updated_at + #Calentry.select("MAX(updated_at) as m_updated_at").first.m_updated_at + Calentry.all.max_by(&:updated_at).updated_at + end def is_upcomming? self.start > Time.now end diff --git a/app/models/survey/answer.rb b/app/models/survey/answer.rb index a7d2c78..244bafe 100644 --- a/app/models/survey/answer.rb +++ b/app/models/survey/answer.rb @@ -1,5 +1,5 @@ class Survey::Answer < ActiveRecord::Base - belongs_to :choice, class_name: 'Survey::Choice' + belongs_to :choice, class_name: 'Survey::Choice', touch: true belongs_to :user # attr_accessible :title, :body end diff --git a/app/models/survey/choice.rb b/app/models/survey/choice.rb index 22f8dbf..7fca518 100644 --- a/app/models/survey/choice.rb +++ b/app/models/survey/choice.rb @@ -1,5 +1,5 @@ class Survey::Choice < ActiveRecord::Base - belongs_to :question, class_name: 'Survey::Question' + belongs_to :question, class_name: 'Survey::Question', touch: true attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture, :question_id has_many :answers, class_name: 'Survey::Answer', dependent: :destroy include ActionView::Helpers::TagHelper diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index 9500d05..b10c199 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- class Survey::Question < ActiveRecord::Base attr_accessible :text, :title, :typ, :choice_ids, :parent_type, :parent_id - belongs_to :parent, polymorphic: true + belongs_to :parent, polymorphic: true, touch: true has_many :choices, dependent: :destroy, class_name: "Survey::Choice" has_many :answers, through: :choices include IsCommentable diff --git a/app/views/news_mailer/daily_reminder.html.erb b/app/views/news_mailer/daily_reminder.html.erb index 5b18aeb..b8a3a5a 100644 --- a/app/views/news_mailer/daily_reminder.html.erb +++ b/app/views/news_mailer/daily_reminder.html.erb @@ -1,8 +1,9 @@ <%= stylesheet_link_tag "http://"+ActionMailer::Base.default_url_options[:host].to_s + "/assets/themes/blue2/application.css", :media=>"all" %> <% @calentries.each do |ce| %> -
+ <% if can?(:show , ce.object) %> +
<%= render partial: "calentries/mail", object: ce %> <%= render partial: "neuigkeiten/mail", object: ce.object if ce.object.kind_of?(Neuigkeit)%> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8416b83..91b844a 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,7 +26,10 @@ themes_for_rails devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } resources :home, :only=>[:index] do - end +end +resources :emails, :only=>[:index] do + +end get ':locale', constraints: {locale: /en|de/}, action: :language,controller: :home, as: "language" scope '(:locale)/admin' do resources :users, :only=>[] do From 8e1e19d3ab1cb8e4e4b227355182d46c426f9141 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 27 Aug 2015 16:03:04 +0200 Subject: [PATCH 05/73] AutoCommit Don Aug 27 16:03:04 CEST 2015 --- app/controllers/emails_controller.rb | 13 ++++++++++++- app/models/ability.rb | 2 +- app/views/emails/daily_reminder.html.erb | 3 +++ app/views/emails/index.html.erb | 1 + app/views/news_mailer/daily_reminder.html.erb | 9 +++++---- config/routes.rb | 4 +++- 6 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 app/views/emails/daily_reminder.html.erb create mode 100644 app/views/emails/index.html.erb diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb index 7a96c05..6065b96 100644 --- a/app/controllers/emails_controller.rb +++ b/app/controllers/emails_controller.rb @@ -1,7 +1,18 @@ class EmailsController < ApplicationController - load_and_authorize_resource +before_filter :authorize def index end + def daily_reminder + @mail =NewsMailer.daily_reminder(current_user.id) + if params[:send] + @mail.deliver + end + render layout: false +end +protected + def authorize + authorize! :emails,User + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index d59a3bf..4a43e08 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -228,7 +228,7 @@ end end if user.has_role?("fetadmin") - + can :emails,User end end diff --git a/app/views/emails/daily_reminder.html.erb b/app/views/emails/daily_reminder.html.erb new file mode 100644 index 0000000..ac3bb6b --- /dev/null +++ b/app/views/emails/daily_reminder.html.erb @@ -0,0 +1,3 @@ +<%=link_to "reminder", daily_reminder_emails_path(params: {send: true}) %> +
Subject: <%= @mail.subject %>
+<%= raw(@mail.body) %> diff --git a/app/views/emails/index.html.erb b/app/views/emails/index.html.erb new file mode 100644 index 0000000..80b1dea --- /dev/null +++ b/app/views/emails/index.html.erb @@ -0,0 +1 @@ +<%=link_to "reminder", daily_reminder_emails_path() %> diff --git a/app/views/news_mailer/daily_reminder.html.erb b/app/views/news_mailer/daily_reminder.html.erb index b8a3a5a..468e1e9 100644 --- a/app/views/news_mailer/daily_reminder.html.erb +++ b/app/views/news_mailer/daily_reminder.html.erb @@ -1,12 +1,13 @@ - <%= stylesheet_link_tag "http://"+ActionMailer::Base.default_url_options[:host].to_s + "/assets/themes/blue2/application.css", :media=>"all" %> +<%= stylesheet_link_tag "http://"+ActionMailer::Base.default_url_options[:host].to_s + "/assets/themes/blue2/application.css", :media=>"all" %> <% @calentries.each do |ce| %> <% if can?(:show , ce.object) %>
- <%= render partial: "calentries/mail", object: ce %> +

<%= render partial: "calentries/mail", object: ce %> +

<%= render partial: "neuigkeiten/mail", object: ce.object if ce.object.kind_of?(Neuigkeit)%> <% end %> -
-<% end %> +<% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 91b844a..6dc5c56 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,7 +28,9 @@ resources :home, :only=>[:index] do end resources :emails, :only=>[:index] do - + collection do + get :daily_reminder + end end get ':locale', constraints: {locale: /en|de/}, action: :language,controller: :home, as: "language" scope '(:locale)/admin' do From bffb978fc75088ff024bf12ede910a28e3c243af Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 27 Aug 2015 17:03:04 +0200 Subject: [PATCH 06/73] AutoCommit Don Aug 27 17:03:04 CEST 2015 --- app/views/home/admin.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/home/admin.html.erb b/app/views/home/admin.html.erb index 351dd50..ed68bce 100644 --- a/app/views/home/admin.html.erb +++ b/app/views/home/admin.html.erb @@ -2,6 +2,8 @@

<%= link_to "user", users_path %>

+ +

<%= link_to "emails", emails_path %>

<% if Fetsite::Application.config.facebookconfig_enabled %>

Facebook Konfiguration

<%= link_to "Grant extra FB privileges", user_omniauth_authorize_path(:facebook,:params=>{scope:"manage_pages,publish_actions,email"}), :confirm=>"Wirklich?" %> From e098c0cd36cb3e137fda110eaf3a33c4fc4414a0 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 10:03:05 +0200 Subject: [PATCH 07/73] AutoCommit Son Aug 30 10:03:05 CEST 2015 --- app/controllers/emails_controller.rb | 12 ++++++++---- app/controllers/neuigkeiten_controller.rb | 7 +++++-- app/views/neuigkeiten/mail_preview.html.erb | 5 +++++ app/views/themes/blue2/neuigkeiten/_menu.html.erb | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/views/neuigkeiten/mail_preview.html.erb diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb index 6065b96..a10e2b6 100644 --- a/app/controllers/emails_controller.rb +++ b/app/controllers/emails_controller.rb @@ -5,14 +5,18 @@ before_filter :authorize end def daily_reminder + ActionMailer::Base.default_url_options[:host] = request.host_with_port @mail =NewsMailer.daily_reminder(current_user.id) if params[:send] - @mail.deliver + usr=User.where(:flag_getemails => true) + usr.each do |u| + NewsMailer.daily_reminder(current_user.id).deliver + end end - render layout: false + render layout: false end -protected + protected def authorize - authorize! :emails,User + authorize! :emails, User end end diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 4c117d3..6410924 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -119,12 +119,15 @@ end end end def mail_preview + ActionMailer::Base.default_url_options[:host] = request.host_with_port + @neuigkeit = Neuigkeit.find(params[:id]) - @user=current_user + @user=current_user @ability=Ability.new(@user) + @mail = NewsMailer.neuigkeit_mail("all@fet.at", params[:id]) authorize! :publish, @neuigkeit - render template: "news_mailer/neuigkeit_mail", layout: false + render layout: false end def newsletter_preview authorize! :publish, Neuigkeit diff --git a/app/views/neuigkeiten/mail_preview.html.erb b/app/views/neuigkeiten/mail_preview.html.erb new file mode 100644 index 0000000..31ad38f --- /dev/null +++ b/app/views/neuigkeiten/mail_preview.html.erb @@ -0,0 +1,5 @@ +<%= link_to "send", mail_preview_rubrik_neuigkeit_path(@neuigkeit) %> +<%= raw(@mail.subject) %> + +


+<%= raw(@mail.body) %> diff --git a/app/views/themes/blue2/neuigkeiten/_menu.html.erb b/app/views/themes/blue2/neuigkeiten/_menu.html.erb index eb81f26..a0b1f9d 100644 --- a/app/views/themes/blue2/neuigkeiten/_menu.html.erb +++ b/app/views/themes/blue2/neuigkeiten/_menu.html.erb @@ -27,7 +27,7 @@ <%= li_tag(link_to(fa_icon("facebook-square") + " post on facebook", publish_to_facebook_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit))) if can?(:publish, @neuigkeit) && @neuigkeit.published? %> - <%= li_tag(link_to(fa_icon("envelope-o") + " send mail", mail_to_fet_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit))) if can?(:publish, @neuigkeit) && @neuigkeit.published? + <%= li_tag(link_to(fa_icon("envelope-o") + " send mail", mail_preview_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit))) if can?(:publish, @neuigkeit) && @neuigkeit.published? %> From 5bf63421a63e3dbccf63d5042ed21f9a8fa35ea9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 14:03:01 +0200 Subject: [PATCH 08/73] AutoCommit Son Aug 30 14:03:01 CEST 2015 --- Gemfile | 7 ++++++- app/models/studium.rb | 2 +- spec/factories/beispiele.rb | 3 +++ spec/factories/lvas.rb | 8 ++++++++ spec/factories/moduls.rb | 1 + spec/models/beispiel_spec.rb | 17 ++++++++++++++++- spec/models/lva_spec.rb | 22 ++++++++++++++++++++++ spec/models/studium_spec.rb | 9 ++++++--- spec/spec_helper.rb | 1 + 9 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 486db40..9166ff8 100755 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,9 @@ gem 'carrierwave', "~>0.9.0" group :development, :test do gem 'factory_girl_rails' gem 'rspec-rails' +gem 'minitest' +gem 'rspec-collection_matchers' +gem 'rspec-expectations' end gem "simple_calendar", "~> 0.1.9" @@ -124,4 +127,6 @@ gem 'opengraph_parser' gem 'blueimp-gallery' gem 'blueimp-gallery-rails' -gem 'shareable' \ No newline at end of file +gem 'shareable' + +gem 'sunspot_test' \ No newline at end of file diff --git a/app/models/studium.rb b/app/models/studium.rb index 2355ae6..1fd5866 100755 --- a/app/models/studium.rb +++ b/app/models/studium.rb @@ -34,7 +34,7 @@ class Studium < ActiveRecord::Base has_many :lvas, :through=>:moduls has_many :semester, :dependent => :destroy has_many :attachments, :as=>:parent -validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} + validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} validates :typ, :inclusion => {:in => ["Bachelor","Master"] } validates :name, :uniqueness => true, :presence=>true validates :zahl, :presence=>true, :format=>{:with=>/^[0-9A-Z]{4,10}$/}, :uniqueness => true diff --git a/spec/factories/beispiele.rb b/spec/factories/beispiele.rb index f9cfcdf..c6f6dd6 100644 --- a/spec/factories/beispiele.rb +++ b/spec/factories/beispiele.rb @@ -2,5 +2,8 @@ FactoryGirl.define do factory :beispiel do + name "BSP1" + desc "sdf" + datum Date.today end end diff --git a/spec/factories/lvas.rb b/spec/factories/lvas.rb index 7a0091b..5e9442f 100644 --- a/spec/factories/lvas.rb +++ b/spec/factories/lvas.rb @@ -2,5 +2,13 @@ FactoryGirl.define do factory :lva do + name "Vorlesung 1" + desc "Das ist eine Vorlesung" + lvanr "001.002" + ects 3 + stunden 2 + pruefungsinformation "sdf" + lernaufwand "sdf" + typ 'VO' end end diff --git a/spec/factories/moduls.rb b/spec/factories/moduls.rb index 4bfd34f..20497fd 100644 --- a/spec/factories/moduls.rb +++ b/spec/factories/moduls.rb @@ -1,6 +1,7 @@ # Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do + factory :modul do name "" factory :other_modul do diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index cfaeb19..a848229 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -1,5 +1,20 @@ require 'spec_helper' describe Beispiel do - pending "add some examples to (or delete) #{__FILE__}" + + it "should be created" do + b=FactoryGirl.build(:beispiel) + l=FactoryGirl.create(:lva) + b.lva=l + expect{b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) + end + it "should not be valid without lva" do + b=FactoryGirl.build(:beispiel) + expect(b.valid?).to be false + end + it "shout respond to comments" do + b=FactoryGirl.create(:beispiel) + expect(b.responds_to?(:comments)).to be true + end + pending "should be flagable" end diff --git a/spec/models/lva_spec.rb b/spec/models/lva_spec.rb index 4209553..dde366c 100644 --- a/spec/models/lva_spec.rb +++ b/spec/models/lva_spec.rb @@ -2,4 +2,26 @@ require 'spec_helper' describe Lva do pending "add some examples to (or delete) #{__FILE__}" + it "should be created" do + l=FactoryGirl.build(:lva) + mg=FactoryGirl.build(:modulgruppe) + s=FactoryGirl.create(:studium) + mg.studium= s + mg.save! + + m=FactoryGirl.build(:other_modul) + m.modulgruppe=mg + m.save! + + l.modul= m + expect{l.save!; Sunspot.commit}.to change{Lva.count}.by(1) + end + it "should not be valid without module" do + l=FactoryGirl.build(:lva) + expect(l.valid?).to be false + expect(l.errors[:modul].size).to be(1) + end + pending "should not be valid without modul" + pending "should have beispiele" + pending "should be flagable" end diff --git a/spec/models/studium_spec.rb b/spec/models/studium_spec.rb index 0297604..ab9a349 100644 --- a/spec/models/studium_spec.rb +++ b/spec/models/studium_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Studium do + # test if it is invalid if certain attributes are missing [:name, :zahl].each do |attr| it "should not be valid without #{attr}" do s = FactoryGirl.build(:studium, attr=>nil) @@ -10,18 +11,20 @@ describe Studium do it "should create studium with valid data" do s=FactoryGirl.build(:studium) lambda { - s.save!}.should change {Studium.count()}.by(1) + s.save!; Sunspot.commit}.should change {Studium.count()}.by(1) end it "should not accept double entrys" do FactoryGirl.create(:studium) + Sunspot.commit s=FactoryGirl.build(:studium) s.should_not be_valid s.should have_at_least(1).error_on(:name) s.should have_at_least(1).error_on(:zahl) end it "should expect zahl to be 000.000" do - s=FactoryGirl.build(:studium, :zahl=>"000000") + s=FactoryGirl.build(:studium, :zahl=>"000.000") + Sunspot.commit s.should_not be_valid - s.should have_at_least(1).error_on(:zahl) + expect(s.errors.size).to be > 0 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d2cbea7..871dc71 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' +require 'sunspot_test/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. From 4a671f5cff38adfcb0261602c54c4597acc98759 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 15:03:01 +0200 Subject: [PATCH 09/73] AutoCommit Son Aug 30 15:03:01 CEST 2015 --- Gemfile | 4 +-- spec/factories/beispiele.rb | 1 + spec/models/beispiel_spec.rb | 51 ++++++++++++++++++++++++++++++------ spec/models/lva_spec.rb | 25 +++++++++++------- 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 9166ff8..a2310d2 100755 --- a/Gemfile +++ b/Gemfile @@ -84,9 +84,9 @@ gem 'awesome_nested_set' gem 'annotate', ">=2.5.0" gem 'carrierwave', "~>0.9.0" group :development, :test do -gem 'factory_girl_rails' +gem 'factory_girl_rails',"~>4.5.0" gem 'rspec-rails' -gem 'minitest' +gem 'minitest', "~>4.7.5" gem 'rspec-collection_matchers' gem 'rspec-expectations' end diff --git a/spec/factories/beispiele.rb b/spec/factories/beispiele.rb index c6f6dd6..861645f 100644 --- a/spec/factories/beispiele.rb +++ b/spec/factories/beispiele.rb @@ -5,5 +5,6 @@ FactoryGirl.define do name "BSP1" desc "sdf" datum Date.today + beispieldatei { Rack::Test::UploadedFile.new(File.join(Rails.root,'public','fetlogo.png'))} end end diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index a848229..f70e744 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -1,20 +1,55 @@ require 'spec_helper' describe Beispiel do - + before(:each) do + s=FactoryGirl.create(:studium) + mg=FactoryGirl.build(:modulgruppe) + mg.studium= s + mg.save! + m=FactoryGirl.build(:other_modul) + m.modulgruppen << mg + m.save! + @l=FactoryGirl.build(:lva) + @l.modul << m + @l.save! + end + before(:each) do + @b=FactoryGirl.build(:beispiel) + @b.lva=@l + end + it "should be created" do - b=FactoryGirl.build(:beispiel) - l=FactoryGirl.create(:lva) - b.lva=l - expect{b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) + @b.lva=@l + expect{@b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) end it "should not be valid without lva" do b=FactoryGirl.build(:beispiel) expect(b.valid?).to be false end - it "shout respond to comments" do - b=FactoryGirl.create(:beispiel) - expect(b.responds_to?(:comments)).to be true + it "should respond to comments" do + expect(@b.respond_to?(:comments)).to be true end + it "should respond to get_flag" do + expect(@b.respond_to?(:get_flag)).to be true + end + [:delete, :goodquality, :badquality].each do |flg| + it "should have default false for flag #{flg}" do + b=FactoryGirl.create(:beispiel, lva_id: @l.id) + expect(b.respond_to?(:get_flag)).to be true + expect(b.get_flag(flg)).to be false + end + + it "should respond to flag setter #{flg}" do + expect(@b.respond_to?("flag_#{flg.to_s}=".to_sym)).to be true + end +end + + it "should be in beispiele " do + @b.save! + bsp= Beispiel.not_flag_delete + expect(bsp).to include @b + end + + pending "should be flagable" end diff --git a/spec/models/lva_spec.rb b/spec/models/lva_spec.rb index dde366c..435b2ed 100644 --- a/spec/models/lva_spec.rb +++ b/spec/models/lva_spec.rb @@ -2,18 +2,22 @@ require 'spec_helper' describe Lva do pending "add some examples to (or delete) #{__FILE__}" - it "should be created" do - l=FactoryGirl.build(:lva) - mg=FactoryGirl.build(:modulgruppe) + before(:all) do s=FactoryGirl.create(:studium) + mg=FactoryGirl.build(:modulgruppe) mg.studium= s mg.save! - - m=FactoryGirl.build(:other_modul) - m.modulgruppe=mg - m.save! - - l.modul= m + @m=FactoryGirl.build(:other_modul) + @m.modulgruppen << mg + @m.save! + puts "Beispiele before filter" + end + before(:each) do + @l = FactoryGirl.build(:lva) + end + it "should be created" do + l=FactoryGirl.build(:lva) + l.modul << @m expect{l.save!; Sunspot.commit}.to change{Lva.count}.by(1) end it "should not be valid without module" do @@ -21,6 +25,9 @@ describe Lva do expect(l.valid?).to be false expect(l.errors[:modul].size).to be(1) end + it "should respond to semesters" do +@l +end pending "should not be valid without modul" pending "should have beispiele" pending "should be flagable" From 8bfd96d0aff7c71b3cdb5e3ab1c1e49c3711da39 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 16:03:01 +0200 Subject: [PATCH 10/73] AutoCommit Son Aug 30 16:03:01 CEST 2015 --- spec/models/beispiel_spec.rb | 15 +++++++++++---- spec/models/fetprofile_spec.rb | 22 +++++++++++++++++++++- spec/models/survey/question_spec.rb | 6 ++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index f70e744..c32600e 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -40,16 +40,23 @@ describe Beispiel do end it "should respond to flag setter #{flg}" do - expect(@b.respond_to?("flag_#{flg.to_s}=".to_sym)).to be true + puts "flag_#{flg.to_s}" + expect(@b.respond_to?("flag_#{flg.to_s}".to_sym)).to be true end end - it "should be in beispiele " do + it "should be in not_flag beispiele" do @b.save! bsp= Beispiel.not_flag_delete expect(bsp).to include @b end - + it "should not be in not_flag" do + @b.save! + bsp= Beispiel.not_flag_delete + expect{@b.flag_delete=true; @b.save!}.to change{ Beispiel.not_flag_delete.count }.by(-1) + expect{@b.flag_delete=nil; @b.save!}.to change{ Beispiel.not_flag_delete.count }.by(1) + + +end - pending "should be flagable" end diff --git a/spec/models/fetprofile_spec.rb b/spec/models/fetprofile_spec.rb index 5714406..958d3e3 100644 --- a/spec/models/fetprofile_spec.rb +++ b/spec/models/fetprofile_spec.rb @@ -1,5 +1,25 @@ require 'spec_helper' describe Fetprofile do - pending "add some examples to (or delete) #{__FILE__}" + [:vorname,:nachname].each do |attr| + it "should not be valid without #{attr}" do + fp = FactoryGirl.build(:fetprofile) + fp.send("#{attr}=".to_sym,nil) + fp.should_not be_valid + end + end + it "should be valid" do + fp = FactoryGirl.build(:fetprofile) + fp.should be_valid + end + it "should not be valid with short name" do + fp = FactoryGirl.build(:fetprofile) + fp.nachname ="S" + fp.should_not be_valid + fp.vorname ="d" + fp.should_not be_valid + end + pending "have memberships" + pending "be associated to gremien" + end diff --git a/spec/models/survey/question_spec.rb b/spec/models/survey/question_spec.rb index 556c094..bb98bdc 100644 --- a/spec/models/survey/question_spec.rb +++ b/spec/models/survey/question_spec.rb @@ -1,5 +1,11 @@ require 'rails_helper' RSpec.describe Survey::Question, :type => :model do + pending "have choices" + pending "be lockable" + pending "be flagable" + pending "copy from template" + pending "attributes for copy" + pending "have do answer" pending "add some examples to (or delete) #{__FILE__}" end From 9dd9c3cc488ca181ac6c7a6b16995d835daf5bec Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 17:03:01 +0200 Subject: [PATCH 11/73] AutoCommit Son Aug 30 17:03:01 CEST 2015 --- .../fetprofiles_controller_spec.rb | 41 +++++++++++-------- spec/models/survey/choice_spec.rb | 3 ++ spec/models/user_spec.rb | 7 ++++ 3 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 spec/models/user_spec.rb diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index be40005..388b1f3 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -18,21 +18,26 @@ require 'spec_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -describe FetprofilesController do - +describe FetprofilesController, :type=> :controller do + include Devise::TestHelpers # This should return the minimal set of attributes required to create a valid # Fetprofile. As you add validations to Fetprofile, be sure to # adjust the attributes here as well. - let(:valid_attributes) { { "vorname" => "MyString" } } + let(:valid_attributes) { {} } # 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 # FetprofilesController. Be sure to keep this updated too. - let(:valid_session) { {} } + let(:valid_session) { {locale: :de} } describe "GET index" do + it "has a 200 status code" do + get :index, {locale: "de"} + expect(response.status).to eq(200) + end + it "assigns all fetprofiles as @fetprofiles" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) get :index, {}, valid_session assigns(:fetprofiles).should eq([fetprofile]) end @@ -40,7 +45,7 @@ describe FetprofilesController do describe "GET show" do it "assigns the requested fetprofile as @fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) get :show, {:id => fetprofile.to_param}, valid_session assigns(:fetprofile).should eq(fetprofile) end @@ -55,7 +60,7 @@ describe FetprofilesController do describe "GET edit" do it "assigns the requested fetprofile as @fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) get :edit, {:id => fetprofile.to_param}, valid_session assigns(:fetprofile).should eq(fetprofile) end @@ -65,18 +70,18 @@ describe FetprofilesController do describe "with valid params" do it "creates a new Fetprofile" do expect { - post :create, {:fetprofile => valid_attributes}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session }.to change(Fetprofile, :count).by(1) end it "assigns a newly created fetprofile as @fetprofile" do - post :create, {:fetprofile => valid_attributes}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session assigns(:fetprofile).should be_a(Fetprofile) assigns(:fetprofile).should be_persisted end it "redirects to the created fetprofile" do - post :create, {:fetprofile => valid_attributes}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session response.should redirect_to(Fetprofile.last) end end @@ -85,7 +90,7 @@ describe FetprofilesController do it "assigns a newly created but unsaved fetprofile as @fetprofile" do # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) - post :create, {:fetprofile => { "vorname" => "invalid value" }}, valid_session + post :create, {:fetprofile => { "vorname" => "in", "nachname"=> "ssdf", "desc"=> "dffff" }}, valid_session assigns(:fetprofile).should be_a_new(Fetprofile) end @@ -101,7 +106,7 @@ describe FetprofilesController do describe "PUT update" do describe "with valid params" do it "updates the requested fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) # Assuming there are no other fetprofiles in the database, this # specifies that the Fetprofile created on the previous line # receives the :update_attributes message with whatever params are @@ -111,13 +116,13 @@ describe FetprofilesController do end it "assigns the requested fetprofile as @fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) put :update, {:id => fetprofile.to_param, :fetprofile => valid_attributes}, valid_session assigns(:fetprofile).should eq(fetprofile) end it "redirects to the fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) put :update, {:id => fetprofile.to_param, :fetprofile => valid_attributes}, valid_session response.should redirect_to(fetprofile) end @@ -125,7 +130,7 @@ describe FetprofilesController do describe "with invalid params" do it "assigns the fetprofile as @fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}, valid_session @@ -133,7 +138,7 @@ describe FetprofilesController do end it "re-renders the 'edit' template" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}, valid_session @@ -144,14 +149,14 @@ describe FetprofilesController do describe "DELETE destroy" do it "destroys the requested fetprofile" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) expect { delete :destroy, {:id => fetprofile.to_param}, valid_session }.to change(Fetprofile, :count).by(-1) end it "redirects to the fetprofiles list" do - fetprofile = Fetprofile.create! valid_attributes + fetprofile = FactoryGirl.create(:fetprofile) delete :destroy, {:id => fetprofile.to_param}, valid_session response.should redirect_to(fetprofiles_url) end diff --git a/spec/models/survey/choice_spec.rb b/spec/models/survey/choice_spec.rb index 31558cb..2923d52 100644 --- a/spec/models/survey/choice_spec.rb +++ b/spec/models/survey/choice_spec.rb @@ -1,5 +1,8 @@ require 'rails_helper' RSpec.describe Survey::Choice, :type => :model do + pending "picture" + pending "icon" + pending "depended answer" pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..29129ab --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe User do + email "testuser@test.at" + password "password" + password_confirmation "password" +end From 2d9944dfc32d901e0745a64a78902ed62a2ea19a Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 18:03:01 +0200 Subject: [PATCH 12/73] AutoCommit Son Aug 30 18:03:01 CEST 2015 --- app/controllers/application_controller.rb | 8 +++- .../fetprofiles_controller_spec.rb | 40 +++++++++++-------- spec/factories/users.rb | 8 ++++ spec/models/user_spec.rb | 3 -- 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 spec/factories/users.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b88554a..47e3272 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,7 +16,13 @@ end end - I18n.locale = session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^de|en/).first || I18n.default_locale + http_header=request.env['HTTP_ACCEPT_LANGUAGE'] + unless http_header.nil? + ht= http_header.scan(/^de|en/).first + else + ht=nil + end + I18n.locale = session[:locale] || ht || I18n.default_locale session[:locale] = I18n.locale diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 388b1f3..554b65d 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -23,7 +23,7 @@ describe FetprofilesController, :type=> :controller do # This should return the minimal set of attributes required to create a valid # Fetprofile. As you add validations to Fetprofile, be sure to # adjust the attributes here as well. - let(:valid_attributes) { {} } + let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} } # 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 @@ -70,18 +70,19 @@ describe FetprofilesController, :type=> :controller do describe "with valid params" do it "creates a new Fetprofile" do expect { - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session }.to change(Fetprofile, :count).by(1) end + it "assigns a newly created fetprofile as @fetprofile" do - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session assigns(:fetprofile).should be_a(Fetprofile) assigns(:fetprofile).should be_persisted end it "redirects to the created fetprofile" do - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).to_hash}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session response.should redirect_to(Fetprofile.last) end end @@ -104,26 +105,31 @@ describe FetprofilesController, :type=> :controller do end describe "PUT update" do + before(:each) do + u= FactoryGirl.create(:user) + u.add_role(:fetuser) + sign_in u + end describe "with valid params" do it "updates the requested fetprofile" do fetprofile = FactoryGirl.create(:fetprofile) - # Assuming there are no other fetprofiles in the database, this - # specifies that the Fetprofile created on the previous line - # receives the :update_attributes message with whatever params are - # submitted in the request. - Fetprofile.any_instance.should_receive(:update_attributes).with({ "vorname" => "MyString" }) - put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "MyString" }}, valid_session + + # Fetprofile.any_instance.should_receive(:update_attributes).with({"vorname"=>"neuerName"}) + expect { + put :update, {:id => fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}}, valid_session + puts Fetprofile.find(fetprofile.id).vorname + }.to change{Fetprofile.find(fetprofile.id).vorname}#.to("neuerName") end it "assigns the requested fetprofile as @fetprofile" do fetprofile = FactoryGirl.create(:fetprofile) - put :update, {:id => fetprofile.to_param, :fetprofile => valid_attributes}, valid_session - assigns(:fetprofile).should eq(fetprofile) + put :update, {:id => fetprofile.to_param, :fetprofile=> {}}#, valid_session + expect(assigns(:fetprofile)).to eq(fetprofile) end it "redirects to the fetprofile" do fetprofile = FactoryGirl.create(:fetprofile) - put :update, {:id => fetprofile.to_param, :fetprofile => valid_attributes}, valid_session + put :update, {:id => fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}}#, valid_session response.should redirect_to(fetprofile) end end @@ -133,15 +139,17 @@ describe FetprofilesController, :type=> :controller do fetprofile = FactoryGirl.create(:fetprofile) # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) - put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}, valid_session - assigns(:fetprofile).should eq(fetprofile) + put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}#, valid_session + expect(assigns(:fetprofile)).to eq(fetprofile) + end it "re-renders the 'edit' template" do fetprofile = FactoryGirl.create(:fetprofile) + attributes= Fetprofile.attributes # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) - put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}, valid_session + put :update, {:id => fetprofile.to_param, :fetprofile => attributes}, valid_session response.should render_template("edit") end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..9cb2401 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :user do + email "testuser@test.at" + password "password" + password_confirmation "password" + + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 29129ab..0f54532 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,7 +1,4 @@ require 'spec_helper' describe User do - email "testuser@test.at" - password "password" - password_confirmation "password" end From 18a68210290ce48e039cb51db587626e0371822a Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 19:03:01 +0200 Subject: [PATCH 13/73] AutoCommit Son Aug 30 19:03:01 CEST 2015 --- .../fetprofiles_controller_spec.rb | 90 ++++++++----------- spec/spec_helper.rb | 3 +- 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 554b65d..49e8ce3 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -1,33 +1,8 @@ require 'spec_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. - describe FetprofilesController, :type=> :controller do include Devise::TestHelpers - # This should return the minimal set of attributes required to create a valid - # Fetprofile. As you add validations to Fetprofile, be sure to - # adjust the attributes here as well. let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} } - - # 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 - # FetprofilesController. Be sure to keep this updated too. let(:valid_session) { {locale: :de} } describe "GET index" do @@ -37,7 +12,7 @@ describe FetprofilesController, :type=> :controller do end it "assigns all fetprofiles as @fetprofiles" do - fetprofile = FactoryGirl.create(:fetprofile) + fetprofile = FactoryGirl.create(:fetprofile, :active=>true) get :index, {}, valid_session assigns(:fetprofiles).should eq([fetprofile]) end @@ -67,16 +42,22 @@ describe FetprofilesController, :type=> :controller do end describe "POST create" do + before(:each) do + u= FactoryGirl.create(:user) + u.add_role(:fetuser) + sign_in u + end + describe "with valid params" do it "creates a new Fetprofile" do expect { - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}, valid_session }.to change(Fetprofile, :count).by(1) end it "assigns a newly created fetprofile as @fetprofile" do - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session + post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}, valid_session assigns(:fetprofile).should be_a(Fetprofile) assigns(:fetprofile).should be_persisted end @@ -105,57 +86,64 @@ describe FetprofilesController, :type=> :controller do end describe "PUT update" do + before(:all) do + @fetprofile = FactoryGirl.create(:fetprofile) + end + before(:each) do u= FactoryGirl.create(:user) u.add_role(:fetuser) sign_in u end - describe "with valid params" do - it "updates the requested fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - # Fetprofile.any_instance.should_receive(:update_attributes).with({"vorname"=>"neuerName"}) - expect { - put :update, {:id => fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}}, valid_session - puts Fetprofile.find(fetprofile.id).vorname - }.to change{Fetprofile.find(fetprofile.id).vorname}#.to("neuerName") + describe "with valid params" do + let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} } + + it "updates the requested fetprofile" do + expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") end it "assigns the requested fetprofile as @fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - put :update, {:id => fetprofile.to_param, :fetprofile=> {}}#, valid_session - expect(assigns(:fetprofile)).to eq(fetprofile) + action + expect(assigns(:fetprofile)).to eq(Fetprofile.find(@fetprofile.to_param)) end it "redirects to the fetprofile" do fetprofile = FactoryGirl.create(:fetprofile) - put :update, {:id => fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}}#, valid_session + action response.should redirect_to(fetprofile) end end describe "with invalid params" do - it "assigns the fetprofile as @fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - # Trigger the behavior that occurs when invalid params are submitted - Fetprofile.any_instance.stub(:save).and_return(false) - put :update, {:id => fetprofile.to_param, :fetprofile => { "vorname" => "invalid value" }}#, valid_session - expect(assigns(:fetprofile)).to eq(fetprofile) + let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"n"}} } + it "assigns the fetprofile as @fetprofile" do + Fetprofile.any_instance.stub(:save).and_return(false) + action + expect(assigns(:fetprofile)).to eq(@fetprofile) end it "re-renders the 'edit' template" do - fetprofile = FactoryGirl.create(:fetprofile) - attributes= Fetprofile.attributes - # Trigger the behavior that occurs when invalid params are submitted Fetprofile.any_instance.stub(:save).and_return(false) - put :update, {:id => fetprofile.to_param, :fetprofile => attributes}, valid_session - response.should render_template("edit") + action + expect(response).to render_template("edit") end + it "redirect to 'edit'" do + Fetprofile.any_instance.stub(:save).and_return(false) + expect(action).to redirect_to action: "edit" + end + end end describe "DELETE destroy" do + before(:each) do + u= FactoryGirl.create(:user) + u.add_role(:fetuser) + sign_in u + end + it "destroys the requested fetprofile" do fetprofile = FactoryGirl.create(:fetprofile) expect { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 871dc71..45ca0a3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,8 @@ require 'sunspot_test/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } - +Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].each {|f| require f} +Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| require f} RSpec.configure do |config| # ## Mock Framework # From 6b324ded443d19f43561c83ae1384cdb91be5c1c Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 20:03:01 +0200 Subject: [PATCH 14/73] AutoCommit Son Aug 30 20:03:01 CEST 2015 --- .../fetprofiles_controller_spec.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 49e8ce3..bef4193 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -1,20 +1,21 @@ require 'spec_helper' describe FetprofilesController, :type=> :controller do - include Devise::TestHelpers + include Devise::TestHelpers, type: :contoller let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} } let(:valid_session) { {locale: :de} } describe "GET index" do + let(:action) { get :index, {}, valid_session} it "has a 200 status code" do - get :index, {locale: "de"} + action expect(response.status).to eq(200) end it "assigns all fetprofiles as @fetprofiles" do fetprofile = FactoryGirl.create(:fetprofile, :active=>true) - get :index, {}, valid_session - assigns(:fetprofiles).should eq([fetprofile]) + action + expect(assigns(:fetprofiles)).to eq([fetprofile]) end end @@ -42,29 +43,28 @@ describe FetprofilesController, :type=> :controller do end describe "POST create" do - before(:each) do - u= FactoryGirl.create(:user) + let(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} + before(:all) do + u= FactoryGirl.build(:user) + u=User.last u.add_role(:fetuser) sign_in u end describe "with valid params" do it "creates a new Fetprofile" do - expect { - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}, valid_session - }.to change(Fetprofile, :count).by(1) + + expect(action).to change(Fetprofile, :count).by(1) end - it "assigns a newly created fetprofile as @fetprofile" do - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}, valid_session - assigns(:fetprofile).should be_a(Fetprofile) + action + assigns(:fetprofile).to be_a(Fetprofile) assigns(:fetprofile).should be_persisted end it "redirects to the created fetprofile" do - post :create, {:fetprofile => FactoryGirl.create(:fetprofile).attributes}, valid_session - response.should redirect_to(Fetprofile.last) + expect(action).to redirect_to(Fetprofile.last) end end From cec9939144dea8b95b05f9a8b085a48326674ea9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 13:03:02 +0200 Subject: [PATCH 15/73] AutoCommit Mon Aug 31 13:03:02 CEST 2015 --- .../fetprofiles_controller_spec.rb | 26 +++++++------------ spec/spec_helper.rb | 12 +++++++++ spec/support/controller_macros.rb | 14 ++++++++++ spec/support/devise.rb | 0 4 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 spec/support/controller_macros.rb create mode 100644 spec/support/devise.rb diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index bef4193..0c969ad 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -1,10 +1,9 @@ require 'spec_helper' -describe FetprofilesController, :type=> :controller do - include Devise::TestHelpers, type: :contoller +describe FetprofilesController do let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} } let(:valid_session) { {locale: :de} } - + extend ControllerMacros describe "GET index" do let(:action) { get :index, {}, valid_session} it "has a 200 status code" do @@ -44,12 +43,9 @@ describe FetprofilesController, :type=> :controller do describe "POST create" do let(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} - before(:all) do - u= FactoryGirl.build(:user) - u=User.last - u.add_role(:fetuser) - sign_in u - end + +login_fet_user + describe "with valid params" do it "creates a new Fetprofile" do @@ -69,9 +65,12 @@ describe FetprofilesController, :type=> :controller do end describe "with invalid params" do + before(:each) do + Fetprofile.any_instance.stub(:save).and_return(false) + end it "assigns a newly created but unsaved fetprofile as @fetprofile" do # Trigger the behavior that occurs when invalid params are submitted - Fetprofile.any_instance.stub(:save).and_return(false) + post :create, {:fetprofile => { "vorname" => "in", "nachname"=> "ssdf", "desc"=> "dffff" }}, valid_session assigns(:fetprofile).should be_a_new(Fetprofile) end @@ -89,12 +88,7 @@ describe FetprofilesController, :type=> :controller do before(:all) do @fetprofile = FactoryGirl.create(:fetprofile) end - - before(:each) do - u= FactoryGirl.create(:user) - u.add_role(:fetuser) - sign_in u - end + login_fet_user describe "with valid params" do let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 45ca0a3..77fa791 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,14 @@ require 'sunspot_test/rspec' Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].each {|f| require f} Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| require f} + +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller + config.extend ControllerMacros, :type => :controller +end + + + RSpec.configure do |config| # ## Mock Framework # @@ -37,4 +45,8 @@ RSpec.configure do |config| # the seed, which is printed after each run. # --seed 1234 config.order = "random" + + + + end diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb new file mode 100644 index 0000000..ef976ff --- /dev/null +++ b/spec/support/controller_macros.rb @@ -0,0 +1,14 @@ +module ControllerMacros + include Devise::TestHelpers + def login_fet_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:user) + user = User.find_by_email(user.email) || user + user.add_role(:fetuser) + user.confirm! + user.save + sign_in user + end + end +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..e69de29 From f61231acccec65973e0063bb525a99d1d7586060 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 14:03:19 +0200 Subject: [PATCH 16/73] AutoCommit Mon Aug 31 14:03:19 CEST 2015 --- app/controllers/application_controller.rb | 3 +- .../fetprofiles_controller_spec.rb | 39 +++++++++++++++---- spec/spec_helper.rb | 2 +- spec/support/controller_macros.rb | 6 +-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 47e3272..881e9a1 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,7 +52,8 @@ else flash[:error] = "You must first login to view this page" session[:user_return_to] = request.url - redirect_to "/users/sign_in" + return redirect_to "/users/sign_in" + end end diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 0c969ad..cf3814b 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe FetprofilesController do - let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} } - let(:valid_session) { {locale: :de} } - extend ControllerMacros +describe FetprofilesController, :type => :controller do + let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} } +# let(:valid_session) { {locale: :de} } + describe "GET index" do let(:action) { get :index, {}, valid_session} it "has a 200 status code" do @@ -27,9 +27,34 @@ describe FetprofilesController do end describe "GET new" do - it "assigns a new fetprofile as @fetprofile" do - get :new, {}, valid_session - assigns(:fetprofile).should be_a_new(Fetprofile) + describe "with fetuser" do + login_fet_user + it "is success" do + get :new, {} + expect(response).to be_success + end + it "assigns @fetprofile" do + get :new, {} + expect(assigns(:fetprofile)).to be_a_new(Fetprofile) + end + end + describe "without fetuser" do + before(:each) do + sign_out :user + end + it "doesn't assign @fetprofile" do + + get :new, {} + expect(assigns(:fetprofile)).to be_nil #_a_new(Fetprofile) + end + it "is expected to raise error" do + bypass_rescue + expect { get :new }.to raise_error(CanCan::AccessDenied) + end + it "is not success" do + get :new, {} + expect(response).not_to be_success + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 77fa791..b9dd90f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'sunspot_test/rspec' - +require 'devise' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index ef976ff..d439641 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -1,13 +1,13 @@ module ControllerMacros - include Devise::TestHelpers +# include Devise::TestHelpers, :type=>:controller def login_fet_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] user = FactoryGirl.build(:user) user = User.find_by_email(user.email) || user - user.add_role(:fetuser) - user.confirm! user.save + user.add_role(:fetuser) + # user.confirm! sign_in user end end From 1bc9d65a44780912c13fdc1f7c8d9d1f717a2b47 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 15:03:01 +0200 Subject: [PATCH 17/73] AutoCommit Mon Aug 31 15:03:01 CEST 2015 --- .../fetprofiles_controller_spec.rb | 90 ++++++++++++------- 1 file changed, 58 insertions(+), 32 deletions(-) diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index cf3814b..cfcf514 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -2,54 +2,75 @@ require 'spec_helper' describe FetprofilesController, :type => :controller do let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} } -# let(:valid_session) { {locale: :de} } - - describe "GET index" do - let(:action) { get :index, {}, valid_session} + # let(:valid_session) { {locale: :de} } + shared_examples "it is success" do it "has a 200 status code" do action expect(response.status).to eq(200) end - - it "assigns all fetprofiles as @fetprofiles" do - fetprofile = FactoryGirl.create(:fetprofile, :active=>true) + it "is success" do action - expect(assigns(:fetprofiles)).to eq([fetprofile]) + expect(response).to be_success + end + end + shared_examples "it assigns object" do + it "assigns object variable" do + expect(assigns(object_variable)).to eq(assigned_object_variable) + end + end + shared_examples "it assigns new object" do + it "assigns new object" do + action + expect(assigns(object_variable)).to be_a_new(assigned_object_variable) + end + end + + def self.create_fetprofile + before(:each) do + @fetprofile = FactoryGirl.create(:fetprofile) + end + end + describe "GET index" do + create_fetprofile + let(:action) { get :index, {} } + before(:each) do + + end + it_behaves_like "it is success" + it "assigns all fetprofiles as @fetprofiles" do + @fetprofile = FactoryGirl.create(:fetprofile) + action + expect(assigns(:fetprofiles)).to eq(Fetprofile.active) end end describe "GET show" do - it "assigns the requested fetprofile as @fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - get :show, {:id => fetprofile.to_param}, valid_session - assigns(:fetprofile).should eq(fetprofile) + before(:each) do end + subject(:action) { get :show, {:id => fetprofile.to_param}} + let(:object_variable) {:fetprofile} + let(:assigned_object_variable) {@fetprofile} end describe "GET new" do describe "with fetuser" do login_fet_user - it "is success" do - get :new, {} - expect(response).to be_success - end - it "assigns @fetprofile" do - get :new, {} - expect(assigns(:fetprofile)).to be_a_new(Fetprofile) - end + subject(:action) { get :new, {}} + let(:object_variable) {:fetprofile} + let(:assigned_object_variable) {Fetprofile} + + it_behaves_like "it assigns new object" + it_behaves_like "it is success" + end describe "without fetuser" do before(:each) do sign_out :user end - it "doesn't assign @fetprofile" do - - get :new, {} - expect(assigns(:fetprofile)).to be_nil #_a_new(Fetprofile) - end - it "is expected to raise error" do - bypass_rescue - expect { get :new }.to raise_error(CanCan::AccessDenied) + pending "doesn't assign @fetprofile" + it "is expected to raise error" do + bypass_rescue + expect { get :new }.to raise_error(CanCan::AccessDenied) end it "is not success" do get :new, {} @@ -59,11 +80,16 @@ describe FetprofilesController, :type => :controller do end describe "GET edit" do - it "assigns the requested fetprofile as @fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - get :edit, {:id => fetprofile.to_param}, valid_session - assigns(:fetprofile).should eq(fetprofile) + login_fet_user + before(:each) do + @fetprofile = FactoryGirl.create(:fetprofile) end + subject(:action) {get :edit, :id=>@fetprofile.to_param} + it "assigns the requested fetprofile as @fetprofile" do + expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile) + # expect(assigns(:fetprofile)).to eq(@fetprofile) + end + end describe "POST create" do From 93dbdedf5348d9a2ac62929209fc465f436d723b Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 16:03:01 +0200 Subject: [PATCH 18/73] AutoCommit Mon Aug 31 16:03:01 CEST 2015 --- .../fetprofiles_controller_spec.rb | 175 ++++++++---------- spec/factories/users.rb | 11 +- spec/support/controller_macros.rb | 24 +++ 3 files changed, 109 insertions(+), 101 deletions(-) diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index cfcf514..2d3dc7c 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -15,13 +15,24 @@ describe FetprofilesController, :type => :controller do end shared_examples "it assigns object" do it "assigns object variable" do + action expect(assigns(object_variable)).to eq(assigned_object_variable) end end shared_examples "it assigns new object" do it "assigns new object" do action - expect(assigns(object_variable)).to be_a_new(assigned_object_variable) + expect(assigns(object_variable)).to be_a_new(object_class) + end + end + shared_examples "it is restricted" do + it "is expected to raise error" do + bypass_rescue + expect { action }.to raise_error(CanCan::AccessDenied) + end + it "is not success" do + action + expect(response).not_to be_success end end @@ -30,83 +41,80 @@ describe FetprofilesController, :type => :controller do @fetprofile = FactoryGirl.create(:fetprofile) end end - describe "GET index" do - create_fetprofile - let(:action) { get :index, {} } + def self.create_active_fetprofile before(:each) do + @fetprofile = FactoryGirl.create(:fetprofile, active: true) + end + end - end + let(:object_variable) {:fetprofile} + let(:assigned_object_variable) {@fetprofile} + let(:object_class) {Fetprofile} + + describe "GET index" do + create_active_fetprofile + subject(:action) { get :index, {} } + let(:object_variable) {:fetprofiles} + let(:assigned_object_variable) {[@fetprofile]} it_behaves_like "it is success" - it "assigns all fetprofiles as @fetprofiles" do - @fetprofile = FactoryGirl.create(:fetprofile) - action - expect(assigns(:fetprofiles)).to eq(Fetprofile.active) - end + it_behaves_like "it assigns object" end describe "GET show" do - before(:each) do - end - subject(:action) { get :show, {:id => fetprofile.to_param}} - let(:object_variable) {:fetprofile} - let(:assigned_object_variable) {@fetprofile} + create_fetprofile + subject(:action) { get :show, {:id => @fetprofile.to_param}} + it_behaves_like "it is success" + it_behaves_like "it assigns object" end describe "GET new" do + subject(:action) { get :new, {}} describe "with fetuser" do login_fet_user - subject(:action) { get :new, {}} - let(:object_variable) {:fetprofile} - let(:assigned_object_variable) {Fetprofile} - it_behaves_like "it assigns new object" - it_behaves_like "it is success" - - end - describe "without fetuser" do - before(:each) do - sign_out :user - end - pending "doesn't assign @fetprofile" - it "is expected to raise error" do - bypass_rescue - expect { get :new }.to raise_error(CanCan::AccessDenied) - end - it "is not success" do - get :new, {} - expect(response).not_to be_success - end + it_behaves_like "it is success" end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + # descibe "without fetuser" do + # login_user + # it_behaves_like "it is restricted" + # end end describe "GET edit" do - login_fet_user - before(:each) do - @fetprofile = FactoryGirl.create(:fetprofile) - end + subject(:action) {get :edit, :id=>@fetprofile.to_param} + login_fet_user + create_fetprofile + it_behaves_like "it is success" + it_behaves_like "it assigns object" + it "assigns the requested fetprofile as @fetprofile" do expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile) # expect(assigns(:fetprofile)).to eq(@fetprofile) end - + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end describe "POST create" do - let(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} - -login_fet_user - + subject(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} + login_fet_user describe "with valid params" do it "creates a new Fetprofile" do - - expect(action).to change(Fetprofile, :count).by(1) + expect{action}.to change(Fetprofile, :count).by(1) end it "assigns a newly created fetprofile as @fetprofile" do - action - assigns(:fetprofile).to be_a(Fetprofile) + action + expect(assigns(:fetprofile)).to be_a(Fetprofile) assigns(:fetprofile).should be_persisted end @@ -116,89 +124,62 @@ login_fet_user end describe "with invalid params" do - before(:each) do - Fetprofile.any_instance.stub(:save).and_return(false) - end + has_invalid_params + it "assigns a newly created but unsaved fetprofile as @fetprofile" do - # Trigger the behavior that occurs when invalid params are submitted - - post :create, {:fetprofile => { "vorname" => "in", "nachname"=> "ssdf", "desc"=> "dffff" }}, valid_session + action assigns(:fetprofile).should be_a_new(Fetprofile) end - it "re-renders the 'new' template" do - # Trigger the behavior that occurs when invalid params are submitted - Fetprofile.any_instance.stub(:save).and_return(false) - post :create, {:fetprofile => { "vorname" => "invalid value" }}, valid_session - response.should render_template("new") + expect(action).to render_template("new") end end end describe "PUT update" do - before(:all) do - @fetprofile = FactoryGirl.create(:fetprofile) - end + let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} } + + create_fetprofile login_fet_user describe "with valid params" do - let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} } + it_behaves_like "it assigns object" it "updates the requested fetprofile" do expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") end - - it "assigns the requested fetprofile as @fetprofile" do - action - expect(assigns(:fetprofile)).to eq(Fetprofile.find(@fetprofile.to_param)) - end - it "redirects to the fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) - action - response.should redirect_to(fetprofile) + expect(action).to redirect_to(@fetprofile) end end describe "with invalid params" do - let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"n"}} } + has_invalid_params + it_behaves_like "it assigns object" - it "assigns the fetprofile as @fetprofile" do - Fetprofile.any_instance.stub(:save).and_return(false) - action - expect(assigns(:fetprofile)).to eq(@fetprofile) - end - - it "re-renders the 'edit' template" do - Fetprofile.any_instance.stub(:save).and_return(false) - action - expect(response).to render_template("edit") - end - it "redirect to 'edit'" do - Fetprofile.any_instance.stub(:save).and_return(false) - expect(action).to redirect_to action: "edit" - end + it "re-renders the 'edit' template" do + expect(action).to render_template("edit") + end +# it "redirect to 'edit'" do + # is_expected.to redirect_to action: "edit" + # end end end describe "DELETE destroy" do - before(:each) do - u= FactoryGirl.create(:user) - u.add_role(:fetuser) - sign_in u - end + login_fet_user + create_fetprofile + subject(:action) { delete :destroy, {:id => @fetprofile.to_param}} it "destroys the requested fetprofile" do - fetprofile = FactoryGirl.create(:fetprofile) expect { - delete :destroy, {:id => fetprofile.to_param}, valid_session + action }.to change(Fetprofile, :count).by(-1) end it "redirects to the fetprofiles list" do - fetprofile = FactoryGirl.create(:fetprofile) - delete :destroy, {:id => fetprofile.to_param}, valid_session + action response.should redirect_to(fetprofiles_url) end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 9cb2401..cc1ea5e 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,8 +1,11 @@ FactoryGirl.define do factory :user do - email "testuser@test.at" - password "password" - password_confirmation "password" - + email "testuser@test.at" + password "password" + password_confirmation "password" + factory :other_user do + email "othertest@test.at" + end end end + diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index d439641..229a09a 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -11,4 +11,28 @@ module ControllerMacros sign_in user end end + def login_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:other_user) + user = User.find_by_email(user.email) || user + user.save + # user.confirm! + sign_in user + end + end + def logout_user + before(:each) do + sign_out :user + end + end + def has_invalid_params + before(:each) do + object_class.any_instance.stub(:save).and_return(false) + object_class.any_instance.stub(:update_attributes).and_return(false) + + end + + end + end From 589597509a0f9d1ecc6b14e3e23ffe28cb107b16 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 17:03:03 +0200 Subject: [PATCH 19/73] AutoCommit Mon Aug 31 17:03:03 CEST 2015 --- app/controllers/fetprofiles_controller.rb | 7 ++--- app/models/fetprofile.rb | 14 ++++----- .../fetprofiles_controller_spec.rb | 29 +++++++++++++++---- spec/factories/fetprofiles.rb | 2 ++ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/controllers/fetprofiles_controller.rb b/app/controllers/fetprofiles_controller.rb index ae58913..d7d99a7 100644 --- a/app/controllers/fetprofiles_controller.rb +++ b/app/controllers/fetprofiles_controller.rb @@ -9,18 +9,17 @@ class FetprofilesController < ApplicationController @fetprofiles = Fetprofile.order(:vorname,:nachname) if params[:filter]== "all" @fetprofiles = Fetprofile.where(:active=>false).order(:nachname,:vorname) if params[:filter]== "notactive" - @gremientabs = Gremium.tabs - @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('profile.new_profile'),:path => new_fetprofile_path(@fetprofile) } if can? :new, @fetprofile + @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('profile.new_profile'),:path => new_fetprofile_path(@fetprofile) } if can? :new, @fetprofile respond_to do |format| format.html # index.html.erb - end + end end def internlist @fetprofiles = Fetprofile.order(:vorname,:nachname) - end + end # GET /fetprofiles/1 # GET /fetprofiles/1.json diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index 804995e..19bbd0e 100644 --- a/app/models/fetprofile.rb +++ b/app/models/fetprofile.rb @@ -32,13 +32,13 @@ class Fetprofile < ActiveRecord::Base has_many :nlinks, as: :link def validate_birthday unless birth_month.nil? || birth_day.nil? - unless Date.valid_date?((birth_year.nil?) ? Date.today.year : birth_year, birth_month, birth_day) - errors.add(:birth_month, "Invalides Datum") - errors.add(:birth_day, "Invalides Datum") - v= false - else - v= true - end + unless Date.valid_date?((birth_year.nil?) ? Date.today.year : birth_year, birth_month, birth_day) + errors.add(:birth_month, "Invalides Datum") + errors.add(:birth_day, "Invalides Datum") + v= false + else + v= true + end else v= false end diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 2d3dc7c..c7bd94c 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -65,6 +65,10 @@ describe FetprofilesController, :type => :controller do subject(:action) { get :show, {:id => @fetprofile.to_param}} it_behaves_like "it is success" it_behaves_like "it assigns object" + it "renders the 'show' template" do + expect(action).to render_template("show") + end + end describe "GET new" do @@ -104,22 +108,30 @@ describe FetprofilesController, :type => :controller do end describe "POST create" do - subject(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} + subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile)},:format=>:html} login_fet_user describe "with valid params" do +# login_fet_user + it "uses valid params" do + expect(Fetprofile.new({:vorname => "sdfsdf", :nachname=>"sdfefw",:desc=>"sdfsdfe"}).save).to be true + end +# before(:each) do +# Fetprofile.any_instance.stub(:save).and_return(true) +# end + it "creates a new Fetprofile" do expect{action}.to change(Fetprofile, :count).by(1) end - + it "assigns a newly created fetprofile as @fetprofile" do action expect(assigns(:fetprofile)).to be_a(Fetprofile) - assigns(:fetprofile).should be_persisted + expect(assigns(:fetprofile)).to be_persisted end - + it "redirects to the created fetprofile" do - expect(action).to redirect_to(Fetprofile.last) + expect(action).to redirect_to action: "show" end end @@ -129,6 +141,7 @@ describe FetprofilesController, :type => :controller do it "assigns a newly created but unsaved fetprofile as @fetprofile" do action assigns(:fetprofile).should be_a_new(Fetprofile) + expect(assigns(:fetprofile)).not_to be_persisted end it "re-renders the 'new' template" do expect(action).to render_template("new") @@ -148,6 +161,12 @@ describe FetprofilesController, :type => :controller do it "updates the requested fetprofile" do expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") end + it "assigns a created fetprofile as @fetprofile" do + action + expect(assigns(:fetprofile)).to be_a(Fetprofile) + expect(assigns(:fetprofile)).to be_persisted + end + it "redirects to the fetprofile" do expect(action).to redirect_to(@fetprofile) end diff --git a/spec/factories/fetprofiles.rb b/spec/factories/fetprofiles.rb index 8576a20..c9c56a3 100644 --- a/spec/factories/fetprofiles.rb +++ b/spec/factories/fetprofiles.rb @@ -9,5 +9,7 @@ FactoryGirl.define do desc "MyText" picture "MyString" active false + birth_month 4 + birth_day 2 end end From 8c1e430bb22877321ff8d0bb5b6687aec86073a2 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 18:03:21 +0200 Subject: [PATCH 20/73] AutoCommit Mon Aug 31 18:03:21 CEST 2015 --- .../fetprofiles_controller_spec.rb | 105 +++++++----------- spec/controllers/shared_examples/basic.rb | 42 +++++++ spec/models/fetprofile_spec.rb | 5 + 3 files changed, 89 insertions(+), 63 deletions(-) create mode 100644 spec/controllers/shared_examples/basic.rb diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index c7bd94c..46607d3 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -3,38 +3,6 @@ require 'spec_helper' describe FetprofilesController, :type => :controller do let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} } # let(:valid_session) { {locale: :de} } - shared_examples "it is success" do - it "has a 200 status code" do - action - expect(response.status).to eq(200) - end - it "is success" do - action - expect(response).to be_success - end - end - shared_examples "it assigns object" do - it "assigns object variable" do - action - expect(assigns(object_variable)).to eq(assigned_object_variable) - end - end - shared_examples "it assigns new object" do - it "assigns new object" do - action - expect(assigns(object_variable)).to be_a_new(object_class) - end - end - shared_examples "it is restricted" do - it "is expected to raise error" do - bypass_rescue - expect { action }.to raise_error(CanCan::AccessDenied) - end - it "is not success" do - action - expect(response).not_to be_success - end - end def self.create_fetprofile before(:each) do @@ -68,6 +36,10 @@ describe FetprofilesController, :type => :controller do it "renders the 'show' template" do expect(action).to render_template("show") end + it "assigns memberships" do + action + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) + end end @@ -82,10 +54,7 @@ describe FetprofilesController, :type => :controller do logout_user it_behaves_like "it is restricted" end - # descibe "without fetuser" do - # login_user - # it_behaves_like "it is restricted" - # end + end describe "GET edit" do @@ -95,6 +64,10 @@ describe FetprofilesController, :type => :controller do create_fetprofile it_behaves_like "it is success" it_behaves_like "it assigns object" + it "assigns memberships" do + action + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) + end it "assigns the requested fetprofile as @fetprofile" do expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile) @@ -108,35 +81,36 @@ describe FetprofilesController, :type => :controller do end describe "POST create" do - subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile)},:format=>:html} + subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile),:format=>:html}} login_fet_user describe "with valid params" do -# login_fet_user - it "uses valid params" do - expect(Fetprofile.new({:vorname => "sdfsdf", :nachname=>"sdfefw",:desc=>"sdfsdfe"}).save).to be true - end -# before(:each) do -# Fetprofile.any_instance.stub(:save).and_return(true) -# end + it "has a 302 status code" do + expect(action.status).to eq(302) + end it "creates a new Fetprofile" do expect{action}.to change(Fetprofile, :count).by(1) end - it "assigns a newly created fetprofile as @fetprofile" do + it_behaves_like "it assigns persisted object" + + it "assigns memberships" do action - expect(assigns(:fetprofile)).to be_a(Fetprofile) - expect(assigns(:fetprofile)).to be_persisted + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) end - + it "redirects to the created fetprofile" do - expect(action).to redirect_to action: "show" + expect(action).to redirect_to assigns(:fetprofile) end end describe "with invalid params" do has_invalid_params + it "assigns memberships" do + action + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) + end it "assigns a newly created but unsaved fetprofile as @fetprofile" do action @@ -147,6 +121,11 @@ describe FetprofilesController, :type => :controller do expect(action).to render_template("new") end end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end describe "PUT update" do @@ -159,13 +138,9 @@ describe FetprofilesController, :type => :controller do it_behaves_like "it assigns object" it "updates the requested fetprofile" do - expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") - end - it "assigns a created fetprofile as @fetprofile" do - action - expect(assigns(:fetprofile)).to be_a(Fetprofile) - expect(assigns(:fetprofile)).to be_persisted + expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}.to("neuerName") end + it_behaves_like "it assigns persisted object" it "redirects to the fetprofile" do expect(action).to redirect_to(@fetprofile) @@ -175,15 +150,14 @@ describe FetprofilesController, :type => :controller do describe "with invalid params" do has_invalid_params it_behaves_like "it assigns object" - - it "re-renders the 'edit' template" do - expect(action).to render_template("edit") - end -# it "redirect to 'edit'" do - # is_expected.to redirect_to action: "edit" - # end - + it "re-renders the 'edit' template" do + expect(action).to render_template("edit") + end end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end end describe "DELETE destroy" do @@ -201,6 +175,11 @@ describe FetprofilesController, :type => :controller do action response.should redirect_to(fetprofiles_url) end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end end diff --git a/spec/controllers/shared_examples/basic.rb b/spec/controllers/shared_examples/basic.rb new file mode 100644 index 0000000..8da6780 --- /dev/null +++ b/spec/controllers/shared_examples/basic.rb @@ -0,0 +1,42 @@ + shared_examples "it is success" do + it "has a 200 status code" do + action + expect(response.status).to eq(200) + end + it "is success" do + action + expect(response).to be_success + end + end + shared_examples "it assigns object" do + it "assigns object variable" do + action + expect(assigns(object_variable)).to eq(assigned_object_variable) + end + end + shared_examples "it assigns new object" do + it "assigns new object" do + action + expect(assigns(object_variable)).to be_a_new(object_class) + expect(assigns(object_variable)).not_to be_persisted + + end + end + shared_examples "it assigns persisted object" do + it "assigns new object" do + action + expect(assigns(object_variable)).to be_a(object_class) + expect(assigns(object_variable)).to be_persisted + end + end + + shared_examples "it is restricted" do + it "is expected to raise error" do + bypass_rescue + expect { action }.to raise_error(CanCan::AccessDenied) + end + it "is not success" do + action + expect(response).not_to be_success + end + end diff --git a/spec/models/fetprofile_spec.rb b/spec/models/fetprofile_spec.rb index 958d3e3..73d44af 100644 --- a/spec/models/fetprofile_spec.rb +++ b/spec/models/fetprofile_spec.rb @@ -8,6 +8,11 @@ describe Fetprofile do fp.should_not be_valid end end + it "should be created" do + fp=Fetprofile.new(FactoryGirl.attributes_for(:fetprofile)) + expect(fp.save).to be true + end + it "should be valid" do fp = FactoryGirl.build(:fetprofile) fp.should be_valid From 221bd95cbf2253249e0e430c633dafdadd94d923 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 22:03:01 +0200 Subject: [PATCH 21/73] AutoCommit Mon Aug 31 22:03:01 CEST 2015 --- spec/views/fetprofiles/show.html.erb_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index dee3f2d..1e4294e 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -8,7 +8,7 @@ describe "fetprofiles/show" do :short => "Short", :fetmailalias => "Fetmailalias", :desc => "MyText", - :picture => "Picture", + :active => false )) end @@ -21,7 +21,7 @@ describe "fetprofiles/show" do rendered.should match(/Short/) rendered.should match(/Fetmailalias/) rendered.should match(/MyText/) - rendered.should match(/Picture/) + rendered.should match(/false/) end end From 3bcd8389d466afb2dcfdb444c3da572a3044e2bc Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 31 Aug 2015 23:03:01 +0200 Subject: [PATCH 22/73] AutoCommit Mon Aug 31 23:03:01 CEST 2015 --- Fetmailalias, | 0 Gemfile | 1 + MyText, | 0 Nachname, | 0 Short, | 0 Vorname, | 0 false | 0 spec/views/fetprofiles/show.html.erb_spec.rb | 15 +++++---------- 8 files changed, 6 insertions(+), 10 deletions(-) create mode 100644 Fetmailalias, create mode 100644 MyText, create mode 100644 Nachname, create mode 100644 Short, create mode 100644 Vorname, create mode 100644 false diff --git a/Fetmailalias, b/Fetmailalias, new file mode 100644 index 0000000..e69de29 diff --git a/Gemfile b/Gemfile index a2310d2..ac707dc 100755 --- a/Gemfile +++ b/Gemfile @@ -88,6 +88,7 @@ gem 'factory_girl_rails',"~>4.5.0" gem 'rspec-rails' gem 'minitest', "~>4.7.5" gem 'rspec-collection_matchers' +gem 'rspec-activemodel-mocks' gem 'rspec-expectations' end diff --git a/MyText, b/MyText, new file mode 100644 index 0000000..e69de29 diff --git a/Nachname, b/Nachname, new file mode 100644 index 0000000..e69de29 diff --git a/Short, b/Short, new file mode 100644 index 0000000..e69de29 diff --git a/Vorname, b/Vorname, new file mode 100644 index 0000000..e69de29 diff --git a/false b/false new file mode 100644 index 0000000..e69de29 diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 1e4294e..7c613ad 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,16 +1,11 @@ require 'spec_helper' -describe "fetprofiles/show" do +describe "fetprofiles/show", :type => :view do before(:each) do - @fetprofile = assign(:fetprofile, stub_model(Fetprofile, - :vorname => "Vorname", - :nachname => "Nachname", - :short => "Short", - :fetmailalias => "Fetmailalias", - :desc => "MyText", - - :active => false - )) +# @fetprofile = + #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) + default_url_options[:locale] = :de + assign(:fetprofile, FactoryGirl.create(:fetprofile)) end it "renders attributes in

" do From 1cea790324494a204705ab60faa6584f92bcd618 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 00:03:02 +0200 Subject: [PATCH 23/73] AutoCommit Die Sep 1 00:03:02 CEST 2015 --- spec/views/fetprofiles/show.html.erb_spec.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 7c613ad..a79e4d7 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -5,18 +5,21 @@ describe "fetprofiles/show", :type => :view do # @fetprofile = #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) default_url_options[:locale] = :de - assign(:fetprofile, FactoryGirl.create(:fetprofile)) + @fetprofile = FactoryGirl.create(:fetprofile) + assign(:fetprofile,@fetprofile) + assign(:memberships, []) end it "renders attributes in

" do - render + render_template "show" # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should match(/Vorname/) - rendered.should match(/Nachname/) - rendered.should match(/Short/) - rendered.should match(/Fetmailalias/) - rendered.should match(/MyText/) +# expect(rendered).to include_text @fetprofile.vorname + rendered.should match(@fetprofile.vorname) +# rendered.should match(/Nachname/) +# rendered.should match(/Short/) +# rendered.should match(/Fetmailalias/) +# rendered.should match(/MyText/) - rendered.should match(/false/) +# rendered.should match(/false/) end end From c02ee3001342b3cfed502624a6ef25c6b8320b18 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 01:03:02 +0200 Subject: [PATCH 24/73] AutoCommit Die Sep 1 01:03:02 CEST 2015 --- Gemfile | 1 + spec/views/fetprofiles/show.html.erb_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index ac707dc..9d1a94e 100755 --- a/Gemfile +++ b/Gemfile @@ -89,6 +89,7 @@ gem 'rspec-rails' gem 'minitest', "~>4.7.5" gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' +gem 'rspec-html-matchers' gem 'rspec-expectations' end diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index a79e4d7..c0a3d81 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe "fetprofiles/show", :type => :view do + include RSpecHtmlMatchers before(:each) do # @fetprofile = #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) @@ -11,10 +12,11 @@ describe "fetprofiles/show", :type => :view do end it "renders attributes in

" do - render_template "show" + render # Run the generator again with the --webrat flag if you want to use webrat matchers + puts rendered # expect(rendered).to include_text @fetprofile.vorname - rendered.should match(@fetprofile.vorname) + expect(rendered).to have_tag('div') # rendered.should match(/Nachname/) # rendered.should match(/Short/) # rendered.should match(/Fetmailalias/) From 576b763d8292d0e1147cf3a7a24d30c7998abd11 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 09:03:01 +0200 Subject: [PATCH 25/73] AutoCommit Die Sep 1 09:03:01 CEST 2015 --- .../fetprofiles/fetprofile.html.erb_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/views/fetprofiles/fetprofile.html.erb_spec.rb diff --git a/spec/views/fetprofiles/fetprofile.html.erb_spec.rb b/spec/views/fetprofiles/fetprofile.html.erb_spec.rb new file mode 100644 index 0000000..f69cb8a --- /dev/null +++ b/spec/views/fetprofiles/fetprofile.html.erb_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "fetprofiles/show", :type => :view do + include RSpecHtmlMatchers + before(:each) do +# @fetprofile = + #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) + default_url_options[:locale] = :de + @fetprofile = FactoryGirl.create(:fetprofile) +# assign(:fetprofile,@fetprofile) +# assign(:memberships, []) + end + it "renders a link" do + render partial: "fetprofiles/fetprofile" + expect(rendered).to have_tag("a.linkbox") + end +end From c1a7d9b7c2c848aedda0efd113567b049590323e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 10:03:01 +0200 Subject: [PATCH 26/73] AutoCommit Die Sep 1 10:03:01 CEST 2015 --- app/models/fetprofile.rb | 2 + app/views/fetprofiles/_fetprofile.html.erb | 1 + app/views/fetprofiles/show.html.erb | 1 + config/routes.rb | 22 +++++--- spec/spec_helper.rb | 3 ++ .../fetprofiles/fetprofile.html.erb_spec.rb | 20 +++++-- spec/views/fetprofiles/show.html.erb_spec.rb | 53 +++++++++++++++++-- 7 files changed, 87 insertions(+), 15 deletions(-) diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index 19bbd0e..fbabb4d 100644 --- a/app/models/fetprofile.rb +++ b/app/models/fetprofile.rb @@ -78,3 +78,5 @@ class Fetprofile < ActiveRecord::Base end end + + diff --git a/app/views/fetprofiles/_fetprofile.html.erb b/app/views/fetprofiles/_fetprofile.html.erb index b934e62..e96a277 100644 --- a/app/views/fetprofiles/_fetprofile.html.erb +++ b/app/views/fetprofiles/_fetprofile.html.erb @@ -2,3 +2,4 @@ <%= link_to fetprofile, {class: :linkbox} do %> <%= render :partial=>"fetprofiles/compact", :locals=>{:fetprofile=>fetprofile} %> <% end %> +<%= root_path() %> diff --git a/app/views/fetprofiles/show.html.erb b/app/views/fetprofiles/show.html.erb index be47657..de3d203 100644 --- a/app/views/fetprofiles/show.html.erb +++ b/app/views/fetprofiles/show.html.erb @@ -51,6 +51,7 @@ end <%= @fetprofile.desc %>

<%= render partial: "interninfo", object: @fetprofile if can?(:seeintern, @fetprofile) %> +
    <% @memberships.each do |m| %>
  • diff --git a/config/routes.rb b/config/routes.rb index 6dc5c56..8b404e4 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,15 @@ resources :comments, contstraints: {id: /[0-9]+/}, only: :show - +## Inserted for testing tests + resources :members , controller: :fetprofiles , as: :fetprofiles do + collection do + get 'verwalten' + get 'internlist' + end + end + + # #------------------------- namespace :survey do resources :questions do @@ -130,12 +138,12 @@ end get 'verwalten' end end - resources :fetprofiles, as: :fetprofiles_bak do - collection do - get 'verwalten' - get 'internlist' - end - end +# resources :fetprofiles, as: :fetprofiles_bak do +# collection do +# get 'verwalten' +# get 'internlist' +# end +# end resources :members , controller: :fetprofiles , as: :fetprofiles do collection do get 'verwalten' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9dd90f..1fcbb8b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,6 +14,9 @@ Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| requi RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller + config.include Devise::TestHelpers, :type => :view +config.include RSpecHtmlMatchers, :type => :view + end diff --git a/spec/views/fetprofiles/fetprofile.html.erb_spec.rb b/spec/views/fetprofiles/fetprofile.html.erb_spec.rb index f69cb8a..12c992f 100644 --- a/spec/views/fetprofiles/fetprofile.html.erb_spec.rb +++ b/spec/views/fetprofiles/fetprofile.html.erb_spec.rb @@ -1,8 +1,10 @@ require 'spec_helper' -describe "fetprofiles/show", :type => :view do +describe "fetprofiles/_fetprofile", :type => :view do include RSpecHtmlMatchers - before(:each) do +include Devise::TestHelpers +include Rails.application.routes.url_helpers + before(:each) do # @fetprofile = #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) default_url_options[:locale] = :de @@ -10,8 +12,20 @@ describe "fetprofiles/show", :type => :view do # assign(:fetprofile,@fetprofile) # assign(:memberships, []) end + + it "has access to url_helpers" do + expect(fetprofile_path(@fetprofile,locale: "de",theme: nil)).to match /#{@fetprofile.id}/ + end + + it "has access to url_helpers without setting nil params" do + expect(fetprofile_path(@fetprofile)).to match /#{@fetprofile.id}/ + end it "renders a link" do - render partial: "fetprofiles/fetprofile" + allow(view).to receive(:default_url_options).and_return({locale: "de"}) +# allow(view).to receive(:fetprofile_path).and_return("") + +# view.stub!(:fetprofile_path).and_return("path") + render partial: "fetprofiles/fetprofile", locals: {fetprofile: @fetprofile} expect(rendered).to have_tag("a.linkbox") end end diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index c0a3d81..7ddec66 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,22 +1,41 @@ require 'spec_helper' describe "fetprofiles/show", :type => :view do - include RSpecHtmlMatchers +# include RSpecHtmlMatchers before(:each) do # @fetprofile = #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) default_url_options[:locale] = :de - @fetprofile = FactoryGirl.create(:fetprofile) + @fetprofile = FactoryGirl.create(:fetprofile,:street => "secret adress") assign(:fetprofile,@fetprofile) assign(:memberships, []) + assign(:gremientabs, []) + end + def self.login_fet_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:user) + user = User.find_by_email(user.email) || user + user.save + user.add_role(:fetuser) + # user.confirm! + @user=user + @ability=Ability.new(@user) + sign_in user + end end - it "renders attributes in

    " do + it "renders public attributes" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - puts rendered -# expect(rendered).to include_text @fetprofile.vorname +# puts rendered + expect(rendered).to match(/#{@fetprofile.vorname}/) + expect(rendered).to match(/#{@fetprofile.nachname}/) + expect(rendered).to match(/#{@fetprofile.desc}/) + expect(rendered).to match(/#{@fetprofile.fetmail}/) + expect(rendered).to have_tag('div') + # rendered.should match(/Nachname/) # rendered.should match(/Short/) # rendered.should match(/Fetmailalias/) @@ -24,4 +43,28 @@ describe "fetprofiles/show", :type => :view do # rendered.should match(/false/) end + it "doesn't render secrets" do + render + expect(rendered).not_to match(/#{@fetprofile.street}/) + end + describe "with fet user" do + login_fet_user + it "can see intern" do + @ability = Object.new + @ability.extend(CanCan::Ability) + controller.stub(:current_ability) { @ability } + + + allow(view).to receive(:current_ability).and_return(@ability) +# view.stub!(:current_ability).and_return(@ability) + expect(current_ability.can?(:seeintern,@fetprofile)).to be true + end + it "renders secrets" do + @ability.can(:seeintern,@fetprofile) + allow(view).to receive(:current_ability).and_return(@ability) + + expect(rendered).to match(/#{@fetprofile.street}/) + + end + end end From c37040a74b698b4786249392d9ffb07c12dcbc60 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 12:03:25 +0200 Subject: [PATCH 27/73] AutoCommit Die Sep 1 12:03:25 CEST 2015 --- spec/views/fetprofiles/show.html.erb_spec.rb | 47 +++++++++++++------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 7ddec66..3f289e4 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -20,15 +20,36 @@ describe "fetprofiles/show", :type => :view do user.add_role(:fetuser) # user.confirm! @user=user - @ability=Ability.new(@user) + @ability= Ability.new(@user) + # controller.stub(:current_ability) { @ability } + allow(view).to receive(:current_ability).and_return(@ability) sign_in user end end + it "calls vorname on fetprofile" do + expect(@fetprofile).to receive(:vorname).at_least(1).times + + render +end + + it "doesn't call users" do + Fetprofile.any_instance.should_not_receive(:users) + # expect(Fetprofile.any_instance).to receive(:vorname) + render +end + + it "doesn't call memberships" do + Fetprofile.any_instance.should_not_receive(:memberships) + render + end + + it "doesn't call gremien" do + Fetprofile.any_instance.should_not_receive(:gremien) + render + end it "renders public attributes" do render - # Run the generator again with the --webrat flag if you want to use webrat matchers -# puts rendered expect(rendered).to match(/#{@fetprofile.vorname}/) expect(rendered).to match(/#{@fetprofile.nachname}/) expect(rendered).to match(/#{@fetprofile.desc}/) @@ -50,21 +71,17 @@ describe "fetprofiles/show", :type => :view do describe "with fet user" do login_fet_user it "can see intern" do - @ability = Object.new - @ability.extend(CanCan::Ability) - controller.stub(:current_ability) { @ability } - - allow(view).to receive(:current_ability).and_return(@ability) -# view.stub!(:current_ability).and_return(@ability) - expect(current_ability.can?(:seeintern,@fetprofile)).to be true + expect(@ability.can?(:seeintern,@fetprofile)).to be true end +let(:current_ability) {@ability} it "renders secrets" do - @ability.can(:seeintern,@fetprofile) - allow(view).to receive(:current_ability).and_return(@ability) - - expect(rendered).to match(/#{@fetprofile.street}/) - + render + expect(rendered).to match(/#{@fetprofile.street}/) + end + it "renders edit path" do + render + expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) end end end From 5134dc2e5fed38c92226345c78131d15ca202c46 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 13:03:03 +0200 Subject: [PATCH 28/73] AutoCommit Die Sep 1 13:03:03 CEST 2015 --- .../themes/blue2/fetprofiles/show.html.erb | 1 + spec/views/fetprofiles/show.html.erb_spec.rb | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/views/themes/blue2/fetprofiles/show.html.erb diff --git a/app/views/themes/blue2/fetprofiles/show.html.erb b/app/views/themes/blue2/fetprofiles/show.html.erb new file mode 100644 index 0000000..e81955e --- /dev/null +++ b/app/views/themes/blue2/fetprofiles/show.html.erb @@ -0,0 +1 @@ +

    please remove this from blue2 theme
    diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 3f289e4..d8e541c 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -2,7 +2,26 @@ require 'spec_helper' describe "fetprofiles/show", :type => :view do # include RSpecHtmlMatchers +include ThemesForRails::CommonMethods + include ThemesForRails::UrlHelpers +# include ThemesForRails::ActionController + + include ::ThemesForRails::ActionView + include ::ActionView::Helpers::AssetTagHelper + include ::ERB::Util + include ::ActionView::Helpers::TagHelper + include ::ActionView::Helpers::FormTagHelper + def theme_name + 'blue2' + end + before(:each) do + view.view_paths.push 'app/views/themes/blue2' + self.lookup_context.prefixes = ['app/views/themes/blue2'] + view.lookup_context.prefixes.push 'app/views/' + view= find("fetprofiles/show") +# view.view_paths.insert 0, ::ActionView::FileSystemResolver.new(theme_view_path_for(name)) + # @fetprofile = #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) default_url_options[:locale] = :de @@ -10,6 +29,7 @@ describe "fetprofiles/show", :type => :view do assign(:fetprofile,@fetprofile) assign(:memberships, []) assign(:gremientabs, []) +# view.theme "blue2" end def self.login_fet_user before(:each) do @@ -26,6 +46,9 @@ describe "fetprofiles/show", :type => :view do sign_in user end end + it "has working filters" do + expect(true).to be true + end it "calls vorname on fetprofile" do expect(@fetprofile).to receive(:vorname).at_least(1).times @@ -79,7 +102,7 @@ let(:current_ability) {@ability} render expect(rendered).to match(/#{@fetprofile.street}/) end - it "renders edit path" do + pending "renders edit path" do render expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) end From d4964f40fb93a523a50bc02ab698f7bb2800436e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 1 Sep 2015 14:03:03 +0200 Subject: [PATCH 29/73] AutoCommit Die Sep 1 14:03:03 CEST 2015 --- .../themes/blue2/fetprofiles/show.html.erb | 2 + spec/views/fetprofiles/show.html.erb_spec.rb | 39 ++++++------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/views/themes/blue2/fetprofiles/show.html.erb b/app/views/themes/blue2/fetprofiles/show.html.erb index e81955e..e600449 100644 --- a/app/views/themes/blue2/fetprofiles/show.html.erb +++ b/app/views/themes/blue2/fetprofiles/show.html.erb @@ -1 +1,3 @@
    please remove this from blue2 theme
    + <%= render partial: "interninfo", object: @fetprofile if can?(:seeintern, @fetprofile) %> + diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index d8e541c..22a6e65 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,29 +1,13 @@ require 'spec_helper' - +#ActionView.lookup_context.prefixes = ['app/views/themes/blue2'] +# ActionView.any_instance.stub!(:view_paths).and_return([ 'app/views/themes/blue2']) + describe "fetprofiles/show", :type => :view do -# include RSpecHtmlMatchers -include ThemesForRails::CommonMethods - include ThemesForRails::UrlHelpers -# include ThemesForRails::ActionController - - include ::ThemesForRails::ActionView - include ::ActionView::Helpers::AssetTagHelper - include ::ERB::Util - include ::ActionView::Helpers::TagHelper - include ::ActionView::Helpers::FormTagHelper - def theme_name - 'blue2' - end +["blue1", "blue2","2003"].each do |theme| +describe "theme #{theme}" do before(:each) do - view.view_paths.push 'app/views/themes/blue2' - self.lookup_context.prefixes = ['app/views/themes/blue2'] - view.lookup_context.prefixes.push 'app/views/' - view= find("fetprofiles/show") -# view.view_paths.insert 0, ::ActionView::FileSystemResolver.new(theme_view_path_for(name)) - -# @fetprofile = - #assign(:fetprofile, stub_model(Fetprofile, FactoryGirl.attributes_for(:fetprofile))) + view.view_paths=[ "app/views/themes/#{theme}", "app/views"] default_url_options[:locale] = :de @fetprofile = FactoryGirl.create(:fetprofile,:street => "secret adress") assign(:fetprofile,@fetprofile) @@ -70,7 +54,7 @@ end Fetprofile.any_instance.should_not_receive(:gremien) render end - + it "renders public attributes" do render expect(rendered).to match(/#{@fetprofile.vorname}/) @@ -93,14 +77,13 @@ end end describe "with fet user" do login_fet_user - it "can see intern" do - expect(@ability.can?(:seeintern,@fetprofile)).to be true - end let(:current_ability) {@ability} - it "renders secrets" do + it "renders address" do render expect(rendered).to match(/#{@fetprofile.street}/) + expect(rendered).to match(/#{@fetprofile.plz}/) + end pending "renders edit path" do render @@ -108,3 +91,5 @@ let(:current_ability) {@ability} end end end +end +end From 7b9b226e591c92c6cd97031eb31cdcbb50115df1 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 2 Sep 2015 21:03:01 +0200 Subject: [PATCH 30/73] AutoCommit Mit Sep 2 21:03:01 CEST 2015 --- .../themes/blue2/fetprofiles/show.html.erb | 78 ++++++++++++++++++- spec/factories/fetprofiles.rb | 7 ++ spec/views/fetprofiles/show.html.erb_spec.rb | 24 ++++-- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/app/views/themes/blue2/fetprofiles/show.html.erb b/app/views/themes/blue2/fetprofiles/show.html.erb index e600449..4036269 100644 --- a/app/views/themes/blue2/fetprofiles/show.html.erb +++ b/app/views/themes/blue2/fetprofiles/show.html.erb @@ -1,3 +1,77 @@ -
    please remove this from blue2 theme
    - <%= render partial: "interninfo", object: @fetprofile if can?(:seeintern, @fetprofile) %> +<%= content_for :header do %> +FET - <%= @fetprofile.name %> +<% unless @fetprofile.picture.url.nil? + picture_url=URI(root_url) + picture_url.path=@fetprofile.picture.portrait.url +end +%> +<% set_meta_tags :og => { + :image => picture_url.to_s, + :title => @fetprofile.name.to_s , + :type => "profile", + :url=>fetprofile_url(@fetprofile,:theme=>nil), +:profile=> { + :first_name=>@fetprofile.vorname, + :last_name=>@fetprofile.nachname + } +} +%> +<% set_meta_tags :og=>{:article=> {:published_time=>I18n.l(@neuigkeit.try(:datum).try(:to_date)) }} unless @neuigkeit.try(:datum).try(:to_date).nil? %> + +<%= display_meta_tags %> +<% end %> + + +<%= render 'fetprofiles/tabs' %> + +
    + +

    <%= notice %>

    +
    + + +
    + + + <%= image_tag @fetprofile.picture.portrait.url %> + + + + + +
    +

    <%= @fetprofile.vorname %> <%= @fetprofile.nachname %><% unless @fetprofile.short.empty? %> <%= @fetprofile.short %> <% end %>

    + + +

    + <%= @fetprofile.fetmail %> +

    +

    + <%= @fetprofile.desc %> +

    + <%= render partial: "interninfo", object: @fetprofile if can?(:seeintern, @fetprofile) %> + +
      + <% @memberships.each do |m| %> +
    • + <%= link_to m.gremium do %> <%= render m %><% end %> + <%= link_to I18n.t('common.edit'), edit_fetprofile_membership_path(@fetprofile,m) if params["verwalten"] && can?(:edit, m)%> + <%= link_to I18n.t('common.delete'), [@fetprofile, m], method: :delete, data: {confirm: I18n.t('common.sure_del')} if params["verwalten"] && can?(:delete, m ) %> +
    • + <% end %> +
    + +
    +
    +
    +<% if can?(:edit, @fetprofile) %> +
    + + <%= link_to ff_icon("icon-pencil")+I18n.t('common.edit'), edit_fetprofile_path(@fetprofile) if can?(:edit, @fetprofile) %> + <%= link_to fa_icon("trash")+I18n.t('common.delete'), fetprofile_path(@fetprofile),method: :delete, data: { confirm: "Are you sure?" } if can?(:delete, @fetprofile) %> + +
    +<% end %> + <%#= render 'layouts/pretty_toolbar' %> +
    diff --git a/spec/factories/fetprofiles.rb b/spec/factories/fetprofiles.rb index c9c56a3..07decc8 100644 --- a/spec/factories/fetprofiles.rb +++ b/spec/factories/fetprofiles.rb @@ -11,5 +11,12 @@ FactoryGirl.define do active false birth_month 4 birth_day 2 + factory :fetprofile_withadress do + street "some street" + plz "1231" + city "vienna" + telnr "sdf tel nummer" + hdynr "sdf hdy nummer" + end end end diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 22a6e65..fac5430 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -3,13 +3,15 @@ require 'spec_helper' # ActionView.any_instance.stub!(:view_paths).and_return([ 'app/views/themes/blue2']) describe "fetprofiles/show", :type => :view do -["blue1", "blue2","2003"].each do |theme| -describe "theme #{theme}" do + ["blue2"].each do |theme| + describe "theme #{theme}" do + before(:each) do + view.view_paths=[ "app/views/themes/#{theme}", "app/views"] + end before(:each) do - view.view_paths=[ "app/views/themes/#{theme}", "app/views"] default_url_options[:locale] = :de - @fetprofile = FactoryGirl.create(:fetprofile,:street => "secret adress") + @fetprofile = FactoryGirl.create(:fetprofile_withadress) assign(:fetprofile,@fetprofile) assign(:memberships, []) assign(:gremientabs, []) @@ -71,21 +73,29 @@ end # rendered.should match(/false/) end - it "doesn't render secrets" do + it "doesn't render address" do render expect(rendered).not_to match(/#{@fetprofile.street}/) + expect(rendered).not_to match(/#{@fetprofile.city}/) + expect(rendered).not_to match(/#{@fetprofile.hdynr}/) + expect(rendered).not_to match(/#{@fetprofile.telnr}/) + expect(rendered).not_to match(/#{@fetprofile.plz}/) + end describe "with fet user" do login_fet_user -let(:current_ability) {@ability} +# let(:current_ability) {@ability} it "renders address" do render expect(rendered).to match(/#{@fetprofile.street}/) expect(rendered).to match(/#{@fetprofile.plz}/) + expect(rendered).to match(/#{@fetprofile.city}/) + expect(rendered).to match(/#{@fetprofile.hdynr}/) + expect(rendered).to match(/#{@fetprofile.telnr}/) end - pending "renders edit path" do + it "renders edit path" do render expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) end From 194a8375ddbf5d62419c67496e9fa56515c2d3fa Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 2 Sep 2015 22:03:01 +0200 Subject: [PATCH 31/73] AutoCommit Mit Sep 2 22:03:01 CEST 2015 --- spec/factories/fetprofiles.rb | 9 ++++++ spec/views/fetprofiles/index.html.erb_spec.rb | 32 +++++++------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/spec/factories/fetprofiles.rb b/spec/factories/fetprofiles.rb index 07decc8..ec37f92 100644 --- a/spec/factories/fetprofiles.rb +++ b/spec/factories/fetprofiles.rb @@ -11,6 +11,15 @@ FactoryGirl.define do active false birth_month 4 birth_day 2 + factory :fetprofile2 do + vorname "Sarah" + nachname "Nachname2" + short "j" + end + factory :fetprofile3 do + vorname "Thomas" + nachname "Mustermann" + end factory :fetprofile_withadress do street "some street" plz "1231" diff --git a/spec/views/fetprofiles/index.html.erb_spec.rb b/spec/views/fetprofiles/index.html.erb_spec.rb index 34593da..a00e9bd 100644 --- a/spec/views/fetprofiles/index.html.erb_spec.rb +++ b/spec/views/fetprofiles/index.html.erb_spec.rb @@ -1,32 +1,22 @@ require 'spec_helper' + describe "fetprofiles/index" do + before(:each) do - assign(:fetprofiles, [ - stub_model(Fetprofile, - :vorname => "Vorname", - :nachname => "Nachname", - :short => "Short", - :fetmailalias => "Fetmailalias", - :desc => "MyText", - :picture => "Picture", - :active => false - ), - stub_model(Fetprofile, - :vorname => "Vorname", - :nachname => "Nachname", - :short => "Short", - :fetmailalias => "Fetmailalias", - :desc => "MyText", - :picture => "Picture", - :active => false - ) - ]) + default_url_options[:locale] = :de + fetprofile1 = FactoryGirl.create(:fetprofile) + fetprofile2 = FactoryGirl.create(:fetprofile2) + fetprofile3 = FactoryGirl.create(:fetprofile3) + fetprofile4 = FactoryGirl.create(:fetprofile_withadress) + @fetprofiles=[fetprofile1, fetprofile2, fetprofile3, fetprofile4] + assign(:fetprofiles,@fetprofiles) + end it "renders a list of fetprofiles" do render - # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => "Vorname".to_s, :count => 2 assert_select "tr>td", :text => "Nachname".to_s, :count => 2 assert_select "tr>td", :text => "Short".to_s, :count => 2 From 889d7ac3d09c1fb09d3c17b62c4ea34a42794fdd Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 2 Sep 2015 23:03:01 +0200 Subject: [PATCH 32/73] AutoCommit Mit Sep 2 23:03:01 CEST 2015 --- app/assets/stylesheets/application.css.scss | 1 + app/assets/stylesheets/layout.css.scss | 114 ------------------ .../themes/blue1/application.css.scss | 1 + .../themes/blue1/linkboxes.css.scss | 61 ++++++++++ .../themes/blue2/application.css.scss | 8 +- .../themes/blue2/linkboxes.css.scss | 84 +++++++++++++ app/views/themes/blue2/home/index.html.erb | 2 +- spec/views/fetprofiles/index.html.erb_spec.rb | 33 ++--- 8 files changed, 172 insertions(+), 132 deletions(-) create mode 100644 app/assets/stylesheets/themes/blue1/linkboxes.css.scss create mode 100644 app/assets/stylesheets/themes/blue2/linkboxes.css.scss diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 00161b9..827eddf 100755 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -147,3 +147,4 @@ background:44F; @import 'galleries'; @import 'tinymce'; +@import 'linkboxes'; \ No newline at end of file diff --git a/app/assets/stylesheets/layout.css.scss b/app/assets/stylesheets/layout.css.scss index 0eb9e1b..2fb10ff 100755 --- a/app/assets/stylesheets/layout.css.scss +++ b/app/assets/stylesheets/layout.css.scss @@ -44,98 +44,6 @@ a:hover { -ul.linkbox-list -{ - max-width:70em; -margin-left:auto; -margin-right:auto; -} -a.linkbox, div.contentbox -{ - display:block; - padding:5px; - border-radius:$box-border-radius; - border: $box-border; - background: $box-background; -} - - -a.linkbox:hover -{ -box-shadow: 1px 1px 2px 2px lightgray; -} - -a.linkbox.color-1 -{ -color:$color_schema_1; -} -a.linkbox.color-2 -{ -color:$color_schema_2; -} -a.linkbox.color-3 -{ -color:$color_schema_3; -} -a.linkbox.color-4 -{ -color:$color_schema_4; -} -a.linkbox.color-5 -{ -color:$color_schema_5; -} - -a.color-1-dark -{ -color:$color_schema_1_dark; -} -a.color-2-dark -{ -color:$color_schema_2_dark; -} -a.color-3-dark -{ -color:$color_schema_3_dark; -} -a.color-4-dark -{ -color:$color_schema_4_dark; -} -a.color-5-dark -{ -color:$color_schema_5_dark; -} -a.color-1-dark:hover -{ -color:$color_schema_1; -} -a.color-2-dark:hover -{ -color:$color_schema_2; -} -a.color-3-dark:hover -{ -color:$color_schema_3; -} -a.color-4-dark:hover -{ -color:$color_schema_4; -} -a.color-5-dark:hover -{ -color:$color_schema_5; -} - - -a.linkbox li -{ -} -ul.linkbox-list li -{ -margin-bottom:10px; -} - div.contentbox { margin: 5px; @@ -175,28 +83,6 @@ div.smallspan { min-height:0; } -ul.linklist -{max-width:100%; -padding:0; -margin:5px; -} -ul.linklist li{ -list-style:none; -margin-bottom:2px; -} -ul.linklist li a i{ -vertical-align:middle; -margin-right:6px; -font-size:2em;} -span.linklist a { - padding:5px; - border-radius:$box-border-radius; - border: $box-border; - background: $box-background; - display:block; - float:left; - -} form.inline div { float:left;} diff --git a/app/assets/stylesheets/themes/blue1/application.css.scss b/app/assets/stylesheets/themes/blue1/application.css.scss index fdc57b0..6d7bd7e 100755 --- a/app/assets/stylesheets/themes/blue1/application.css.scss +++ b/app/assets/stylesheets/themes/blue1/application.css.scss @@ -117,5 +117,6 @@ $box-border-radius:0px; $box-background: white; @import 'layout'; +@import 'linkboxes'; @import 'calendars'; @import 'formtastic-bootstrap' \ No newline at end of file diff --git a/app/assets/stylesheets/themes/blue1/linkboxes.css.scss b/app/assets/stylesheets/themes/blue1/linkboxes.css.scss new file mode 100644 index 0000000..15bb687 --- /dev/null +++ b/app/assets/stylesheets/themes/blue1/linkboxes.css.scss @@ -0,0 +1,61 @@ +ul.linkbox-list +{ + max-width:70em; + margin-left:auto; + margin-right:auto; +} +a.linkbox, div.contentbox +{ + display:block; + padding:5px; + border-radius:$box-border-radius; + border: $box-border; + background: $box-background; +} + +a.linkbox:hover{ box-shadow: 1px 1px 2px 2px lightgray; } + +a.linkbox.color-1 { color:$color_schema_1; } +a.linkbox.color-2 { color:$color_schema_2; } +a.linkbox.color-3 { color:$color_schema_3; } +a.linkbox.color-4 { color:$color_schema_4;} +a.linkbox.color-5 { color:$color_schema_5;} + +a.color-1-dark { color:$color_schema_1_dark; } +a.color-2-dark { color:$color_schema_2_dark; } +a.color-3-dark { color:$color_schema_3_dark;} +a.color-4-dark { color:$color_schema_4_dark;} +a.color-5-dark { color:$color_schema_5_dark;} +a.color-1-dark:hover { color:$color_schema_1; } +a.color-2-dark:hover { color:$color_schema_2; } +a.color-3-dark:hover { color:$color_schema_3; } +a.color-4-dark:hover { color:$color_schema_4; } +a.color-5-dark:hover { color:$color_schema_5; } + +a.linkbox li { } +ul.linkbox-list li { + margin-bottom:10px; +} +ul.linklist { + max-width:100%; + padding:0; + margin:5px; +} +ul.linklist li { + list-style:none; + margin-bottom:2px; +} +ul.linklist li a i{ + vertical-align:middle; + margin-right:6px; + font-size:2em;} +span.linklist a { + padding:5px; + border-radius:$box-border-radius; + border: $box-border; + background: $box-background; + display:block; + float:left; + +} + diff --git a/app/assets/stylesheets/themes/blue2/application.css.scss b/app/assets/stylesheets/themes/blue2/application.css.scss index 1db0ed0..dfecb6a 100755 --- a/app/assets/stylesheets/themes/blue2/application.css.scss +++ b/app/assets/stylesheets/themes/blue2/application.css.scss @@ -1,4 +1,6 @@ +/* This is the main file for theme "blue2" + */ /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. @@ -89,9 +91,11 @@ div.header { height:45px; margin-bottom: 0 px } + div.header_span { background:white } + div.header h1 { padding:0; margin:4px; @@ -117,13 +121,13 @@ $navbar-li-minwidth: 0; $box-border: lightgray solid 1px; -$box-border-radius:4px; +$box-border-radius:6px; $box-background: white; @import 'layout'; @import 'calendars'; @import 'formtastic-bootstrap'; - +@import 'linkboxes'; @import 'extra'; body { background: #FFF; //#EFEFEF; diff --git a/app/assets/stylesheets/themes/blue2/linkboxes.css.scss b/app/assets/stylesheets/themes/blue2/linkboxes.css.scss new file mode 100644 index 0000000..789e94f --- /dev/null +++ b/app/assets/stylesheets/themes/blue2/linkboxes.css.scss @@ -0,0 +1,84 @@ +ul.linkbox-list +{ + max-width:70em; + margin-left:auto; + margin-right:auto; +} + +ul.linkbox-list > li { + margin-bottom:0px; +} + +ul.linkbox-list > li:first-child a.linkbox { + border-top-left-radius:$box-border-radius; + border-top-right-radius:$box-border-radius; + border: $box-border; + +} + +ul.linkbox-list > li:last-child a.linkbox { + border-bottom-left-radius:$box-border-radius; + border-bottom-right-radius:$box-border-radius; +} + +ul.linkbox-list > li a.linkbox { + border-radius: 0; + border-top: none; + +} + +ul.linkbox-list > li a.linkbox:hover { + z-index:2000 +} +a.linkbox, div.contentbox +{ + display:block; + padding:5px; + border-radius:$box-border-radius; + border: $box-border; + background: $box-background; +} + +a.linkbox:hover{ box-shadow: 1px 1px 2px 2px lightgray; } + +a.linkbox.color-1 { color:$color_schema_1; } +a.linkbox.color-2 { color:$color_schema_2; } +a.linkbox.color-3 { color:$color_schema_3; } +a.linkbox.color-4 { color:$color_schema_4;} +a.linkbox.color-5 { color:$color_schema_5;} + +a.color-1-dark { color:$color_schema_1_dark; } +a.color-2-dark { color:$color_schema_2_dark; } +a.color-3-dark { color:$color_schema_3_dark;} +a.color-4-dark { color:$color_schema_4_dark;} +a.color-5-dark { color:$color_schema_5_dark;} +a.color-1-dark:hover { color:$color_schema_1; } +a.color-2-dark:hover { color:$color_schema_2; } +a.color-3-dark:hover { color:$color_schema_3; } +a.color-4-dark:hover { color:$color_schema_4; } +a.color-5-dark:hover { color:$color_schema_5; } + +a.linkbox li { } +ul.linklist { + max-width:100%; + padding:0; + margin:5px; +} +ul.linklist li { + list-style:none; + margin-bottom:2px; +} +ul.linklist li a i{ + vertical-align:middle; + margin-right:6px; + font-size:2em;} +span.linklist a { + padding:5px; + border-radius:$box-border-radius; + border: $box-border; + background: $box-background; + display:block; + float:left; + +} + diff --git a/app/views/themes/blue2/home/index.html.erb b/app/views/themes/blue2/home/index.html.erb index 481b871..0b9527b 100644 --- a/app/views/themes/blue2/home/index.html.erb +++ b/app/views/themes/blue2/home/index.html.erb @@ -46,7 +46,7 @@
    -
    <% if can?(:edit, @fetprofile) %>
    - + <%= link_to ff_icon("icon-pencil")+I18n.t('common.edit'), edit_fetprofile_path(@fetprofile) if can?(:edit, @fetprofile) %> <%= link_to fa_icon("trash")+I18n.t('common.delete'), fetprofile_path(@fetprofile),method: :delete, data: { confirm: "Are you sure?" } if can?(:delete, @fetprofile) %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 30fc2c1..782ca37 100755 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -33,7 +33,7 @@ <%= semantic_fields_for "users[#{user.id}]", user do |f|%> - <%= f.input :fetprofile ,:label=>false , :as=>:select , :collection=>Fetprofile.all %> + <%= f.input :fetprofile ,:label=>false , :as=>:select , :collection=>Fetprofile.order(:vorname,:nachname) %> <% end %> From 984e5f4b56e982f92bcdabce8c1ef49cbc027d92 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 3 Sep 2015 12:03:05 +0200 Subject: [PATCH 35/73] AutoCommit Don Sep 3 12:03:05 CEST 2015 --- app/views/fetprofiles/show.html.erb | 2 +- .../themes/blue2/fetprofiles/show.html.erb | 2 +- config/routes.rb | 7 ++++++- spec/factories/gremien.rb | 8 ++++--- spec/factories/memberships.rb | 8 +++---- spec/views/fetprofiles/show.html.erb_spec.rb | 21 +++++++++++++++++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app/views/fetprofiles/show.html.erb b/app/views/fetprofiles/show.html.erb index de3d203..da582a4 100644 --- a/app/views/fetprofiles/show.html.erb +++ b/app/views/fetprofiles/show.html.erb @@ -55,7 +55,7 @@ end
      <% @memberships.each do |m| %>
    • - <%= link_to m.gremium do %> <%= render m %><% end %> + <%= link_to gremium_path(m.gremium) do %> <%= render m %><% end %> <%= link_to I18n.t('common.edit'), edit_fetprofile_membership_path(@fetprofile,m) if params["verwalten"] && can?(:edit, m)%> <%= link_to I18n.t('common.delete'), [@fetprofile, m], method: :delete, data: {confirm: I18n.t('common.sure_del')} if params["verwalten"] && can?(:delete, m ) %>
    • diff --git a/app/views/themes/blue2/fetprofiles/show.html.erb b/app/views/themes/blue2/fetprofiles/show.html.erb index 2d6f85f..26180a8 100644 --- a/app/views/themes/blue2/fetprofiles/show.html.erb +++ b/app/views/themes/blue2/fetprofiles/show.html.erb @@ -55,7 +55,7 @@ end
        <% @memberships.each do |m| %>
      • - <%= link_to m.gremium do %> <%= render m %><% end %> + <%= link_to gremium_path(m.gremium) do %> <%= render m %><% end %> <%= link_to I18n.t('common.edit'), edit_fetprofile_membership_path(@fetprofile,m) if params["verwalten"] && can?(:edit, m)%> <%= link_to I18n.t('common.delete'), [@fetprofile, m], method: :delete, data: {confirm: I18n.t('common.sure_del')} if params["verwalten"] && can?(:delete, m ) %>
      • diff --git a/config/routes.rb b/config/routes.rb index 8b404e4..f677317 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,7 +15,12 @@ get 'internlist' end end - + resources :gremien do + collection do + get 'verwalten' + end + end +# # #------------------------- namespace :survey do diff --git a/spec/factories/gremien.rb b/spec/factories/gremien.rb index fcce55d..7e0dba0 100644 --- a/spec/factories/gremien.rb +++ b/spec/factories/gremien.rb @@ -1,9 +1,11 @@ +# -*- coding: utf-8 -*- + # Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :gremium do - name "MyString" - desc "MyText" - typ "MyString" + name "Kommission" + desc "Das ist eine Kommission die sich mit irgendwas beschäftigt" + typ 1 end end diff --git a/spec/factories/memberships.rb b/spec/factories/memberships.rb index 56a7e0a..aa3968a 100644 --- a/spec/factories/memberships.rb +++ b/spec/factories/memberships.rb @@ -2,10 +2,10 @@ FactoryGirl.define do factory :membership do - fetprofile_id "MyString" - gremium_id "MyString" + fetprofile_id 1 + gremium_id 1 start "2013-08-19" - stop "2013-08-19" - typ "MyString" + stop "2013-08-23" + typ 1 end end diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index bca5af1..080add3 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -13,8 +13,12 @@ describe "fetprofiles/show", :type => :view do default_url_options[:locale] = :de @fetprofile = FactoryGirl.create(:fetprofile_withadress) assign(:fetprofile,@fetprofile) - assign(:memberships, []) - assign(:gremientabs, []) + @gremium = FactoryGirl.create(:gremium) + @gremium2 = FactoryGirl.create(:gremium, name:"Kommission2") + @gremium3 = FactoryGirl.create(:gremium, name:"Kommission3", typ: 2) + + assign(:memberships, [FactoryGirl.create(:membership,gremium_id: @gremium.id, fetprofile_id: @fetprofile.id)]) + assign(:gremientabs, [@gremium2]) # view.theme "blue2" end def self.login_fet_user @@ -82,6 +86,19 @@ end expect(rendered).not_to match(/#{@fetprofile.plz}/) end + it "renders links to gremium" do + render + expect(rendered).to match(/#{gremium_path(@gremium)}/) + end + it "renders gremium links" do + render + expect(rendered).to match(/#{gremium_path(@gremium2)}/) + end + it "doesn't render gremium links for hidden gremium" do + render + expect(rendered).not_to match(/#{gremium_path(@gremium3)}/) + end + describe "with fet user" do login_fet_user From f7ad93c398eba71ec3555f715577b1d3ac70ea7f Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 3 Sep 2015 16:03:01 +0200 Subject: [PATCH 36/73] AutoCommit Don Sep 3 16:03:01 CEST 2015 --- spec/spec_helper.rb | 6 +- spec/support/view_macros.rb | 30 +++ spec/views/fetprofiles/edit.html.erb_spec.rb | 43 +++-- spec/views/fetprofiles/index.html.erb_spec.rb | 3 +- spec/views/fetprofiles/new.html.erb_spec.rb | 43 +++-- spec/views/fetprofiles/show.html.erb_spec.rb | 181 ++++++++---------- 6 files changed, 164 insertions(+), 142 deletions(-) create mode 100644 spec/support/view_macros.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1fcbb8b..088c0ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,8 @@ RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller config.include Devise::TestHelpers, :type => :view -config.include RSpecHtmlMatchers, :type => :view + config.include RSpecHtmlMatchers, :type => :view + config.extend ViewMacros, :type => :view end @@ -42,7 +43,8 @@ RSpec.configure do |config| # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false - + config.add_setting :themes + config.themes =[:blue2, :blue1] # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. diff --git a/spec/support/view_macros.rb b/spec/support/view_macros.rb new file mode 100644 index 0000000..0f6989e --- /dev/null +++ b/spec/support/view_macros.rb @@ -0,0 +1,30 @@ +module ViewMacros + + def foreach_theme + RSpec.configuration.themes.each do |theme| + context " with theme #{theme}" do + before(:each) do + view.view_paths=[ "app/views/themes/#{theme}", "app/views"] + end + + yield + end + end + end + def login_fet_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:user) + user = User.find_by_email(user.email) || user + user.save + user.add_role(:fetuser) + # user.confirm! + @user=user + @ability= Ability.new(@user) + # controller.stub(:current_ability) { @ability } + allow(view).to receive(:current_ability).and_return(@ability) + sign_in user + end + end + +end diff --git a/spec/views/fetprofiles/edit.html.erb_spec.rb b/spec/views/fetprofiles/edit.html.erb_spec.rb index c68d7e3..8efc992 100644 --- a/spec/views/fetprofiles/edit.html.erb_spec.rb +++ b/spec/views/fetprofiles/edit.html.erb_spec.rb @@ -1,30 +1,35 @@ require 'spec_helper' -describe "fetprofiles/edit" do - before(:each) do - @fetprofile = assign(:fetprofile, stub_model(Fetprofile, - :vorname => "MyString", - :nachname => "MyString", - :short => "MyString", - :fetmailalias => "MyString", - :desc => "MyText", - :picture => "MyString", - :active => false - )) +describe "fetprofiles/edit", :type=> :view do + foreach_theme do + login_fet_user + before(:each) do + @fetprofile = FactoryGirl.create(:fetprofile_withadress,:skype => "myskypename") + @memberships = [] end it "renders the edit fetprofile form" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form[action=?][method=?]", fetprofile_path(@fetprofile), "post" do - assert_select "input#fetprofile_vorname[name=?]", "fetprofile[vorname]" - assert_select "input#fetprofile_nachname[name=?]", "fetprofile[nachname]" - assert_select "input#fetprofile_short[name=?]", "fetprofile[short]" - assert_select "input#fetprofile_fetmailalias[name=?]", "fetprofile[fetmailalias]" - assert_select "textarea#fetprofile_desc[name=?]", "fetprofile[desc]" - assert_select "input#fetprofile_picture[name=?]", "fetprofile[picture]" - assert_select "input#fetprofile_active[name=?]", "fetprofile[active]" + expect(rendered).to have_tag('form', with: {method:"post"}) do + with_tag "input", with: {name: "fetprofile[vorname]", value: @fetprofile.vorname} + with_tag "input", with: {name: "fetprofile[nachname]", value: @fetprofile.nachname} + with_tag "input", with: {name: "fetprofile[short]", value: @fetprofile.short} + with_tag "textarea", with: {name: "fetprofile[desc]"} + with_tag "input", with: {name: "fetprofile[picture]"} + with_tag "input", with: {name: "fetprofile[picture_cache]"} + + with_tag "input", with: {name: "fetprofile[street]", value: @fetprofile.street} + with_tag "input", with: {name: "fetprofile[plz]", value: @fetprofile.plz} + with_tag "input", with: {name: "fetprofile[city]", value: @fetprofile.city} + with_tag "input", with: {name: "fetprofile[hdynr]", value: @fetprofile.hdynr} + with_tag "input", with: {name: "fetprofile[telnr]", value: @fetprofile.telnr} + with_tag "input", with: {name: "fetprofile[skype]", value: @fetprofile.skype.to_s} + with_tag "input", with: {name: "fetprofile[birth_day]", value: @fetprofile.birth_day} + with_tag "input", with: {name: "fetprofile[birth_month]", value: @fetprofile.birth_month} + end end end +end diff --git a/spec/views/fetprofiles/index.html.erb_spec.rb b/spec/views/fetprofiles/index.html.erb_spec.rb index acfffba..c0ca1ad 100644 --- a/spec/views/fetprofiles/index.html.erb_spec.rb +++ b/spec/views/fetprofiles/index.html.erb_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "fetprofiles/index" , :type=>:view do - +foreach_theme do before(:each) do # default_url_options[:locale] = :de @fetprofile1 = FactoryGirl.create(:fetprofile) @@ -29,3 +29,4 @@ describe "fetprofiles/index" , :type=>:view do end end +end diff --git a/spec/views/fetprofiles/new.html.erb_spec.rb b/spec/views/fetprofiles/new.html.erb_spec.rb index 8b6ce6c..5202ff4 100644 --- a/spec/views/fetprofiles/new.html.erb_spec.rb +++ b/spec/views/fetprofiles/new.html.erb_spec.rb @@ -1,30 +1,35 @@ require 'spec_helper' -describe "fetprofiles/new" do +describe "fetprofiles/new", :type=> :view do + foreach_theme do before(:each) do - assign(:fetprofile, stub_model(Fetprofile, - :vorname => "MyString", - :nachname => "MyString", - :short => "MyString", - :fetmailalias => "MyString", - :desc => "MyText", - :picture => "MyString", - :active => false - ).as_new_record) + @fetprofile = FactoryGirl.create(:fetprofile_withadress,:skype => "myskypename") + @memberships = [] end - it "renders new fetprofile form" do + it "renders the edit fetprofile form" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form[action=?][method=?]", fetprofiles_path, "post" do - assert_select "input#fetprofile_vorname[name=?]", "fetprofile[vorname]" - assert_select "input#fetprofile_nachname[name=?]", "fetprofile[nachname]" - assert_select "input#fetprofile_short[name=?]", "fetprofile[short]" - assert_select "input#fetprofile_fetmailalias[name=?]", "fetprofile[fetmailalias]" - assert_select "textarea#fetprofile_desc[name=?]", "fetprofile[desc]" - assert_select "input#fetprofile_picture[name=?]", "fetprofile[picture]" - assert_select "input#fetprofile_active[name=?]", "fetprofile[active]" + expect(rendered).to have_tag('form', with: {method:"post"}) do + with_tag "input", with: {name: "fetprofile[vorname]"} + with_tag "input", with: {name: "fetprofile[nachname]"} + with_tag "input", with: {name: "fetprofile[short]"} + with_tag "textarea", with: {name: "fetprofile[desc]"} + with_tag "input", with: {name: "fetprofile[picture]"} + with_tag "input", with: {name: "fetprofile[picture_cache]"} + + with_tag "input", with: {name: "fetprofile[street]"} + with_tag "input", with: {name: "fetprofile[plz]"} + with_tag "input", with: {name: "fetprofile[city]"} + with_tag "input", with: {name: "fetprofile[hdynr]"} + with_tag "input", with: {name: "fetprofile[telnr]"} + with_tag "input", with: {name: "fetprofile[skype]"} + with_tag "input", with: {name: "fetprofile[birth_day]"} + with_tag "input", with: {name: "fetprofile[birth_month]"} + end end + end end + diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 080add3..43f183f 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,122 +1,101 @@ require 'spec_helper' -#ActionView.lookup_context.prefixes = ['app/views/themes/blue2'] -# ActionView.any_instance.stub!(:view_paths).and_return([ 'app/views/themes/blue2']) - -describe "fetprofiles/show", :type => :view do - ["blue2"].each do |theme| - describe "theme #{theme}" do - before(:each) do - view.view_paths=[ "app/views/themes/#{theme}", "app/views"] - end - before(:each) do - default_url_options[:locale] = :de - @fetprofile = FactoryGirl.create(:fetprofile_withadress) - assign(:fetprofile,@fetprofile) +describe "fetprofiles/show", :type => :view do + foreach_theme do + + before(:each) do + default_url_options[:locale] = :de + @fetprofile = FactoryGirl.create(:fetprofile_withadress) + assign(:fetprofile,@fetprofile) @gremium = FactoryGirl.create(:gremium) @gremium2 = FactoryGirl.create(:gremium, name:"Kommission2") @gremium3 = FactoryGirl.create(:gremium, name:"Kommission3", typ: 2) - assign(:memberships, [FactoryGirl.create(:membership,gremium_id: @gremium.id, fetprofile_id: @fetprofile.id)]) - assign(:gremientabs, [@gremium2]) -# view.theme "blue2" - end - def self.login_fet_user - before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:user] - user = FactoryGirl.build(:user) - user = User.find_by_email(user.email) || user - user.save - user.add_role(:fetuser) - # user.confirm! - @user=user - @ability= Ability.new(@user) - # controller.stub(:current_ability) { @ability } - allow(view).to receive(:current_ability).and_return(@ability) - sign_in user + assign(:memberships, [FactoryGirl.create(:membership,gremium_id: @gremium.id, fetprofile_id: @fetprofile.id)]) + assign(:gremientabs, [@gremium2]) + # view.theme "blue2" end - end - it "has working filters" do - expect(true).to be true - end - it "calls vorname on fetprofile" do - expect(@fetprofile).to receive(:vorname).at_least(1).times - render -end - - it "doesn't call users" do - Fetprofile.any_instance.should_not_receive(:users) - # expect(Fetprofile.any_instance).to receive(:vorname) - render -end + it "has working filters" do + expect(true).to be true + end + it "calls vorname on fetprofile" do + expect(@fetprofile).to receive(:vorname).at_least(1).times - it "doesn't call memberships" do - Fetprofile.any_instance.should_not_receive(:memberships) - render - end - - it "doesn't call gremien" do - Fetprofile.any_instance.should_not_receive(:gremien) - render - end - - it "renders public attributes" do - render - expect(rendered).to match(/#{@fetprofile.vorname}/) - expect(rendered).to match(/#{@fetprofile.nachname}/) - expect(rendered).to match(/#{@fetprofile.desc}/) - expect(rendered).to match(/#{@fetprofile.fetmail}/) - - expect(rendered).to have_tag('div') + render + end -# rendered.should match(/Nachname/) -# rendered.should match(/Short/) -# rendered.should match(/Fetmailalias/) -# rendered.should match(/MyText/) + it "doesn't call users" do + Fetprofile.any_instance.should_not_receive(:users) + # expect(Fetprofile.any_instance).to receive(:vorname) + render + end -# rendered.should match(/false/) - end - it "doesn't render address" do - render - expect(rendered).not_to match(/#{@fetprofile.street}/) + it "doesn't call memberships" do + Fetprofile.any_instance.should_not_receive(:memberships) + render + end + + it "doesn't call gremien" do + Fetprofile.any_instance.should_not_receive(:gremien) + render + end + + it "renders public attributes" do + render + expect(rendered).to match(/#{@fetprofile.vorname}/) + expect(rendered).to match(/#{@fetprofile.nachname}/) + expect(rendered).to match(/#{@fetprofile.desc}/) + expect(rendered).to match(/#{@fetprofile.fetmail}/) + + expect(rendered).to have_tag('div') + + # rendered.should match(/Nachname/) + # rendered.should match(/Short/) + # rendered.should match(/Fetmailalias/) + # rendered.should match(/MyText/) + + # rendered.should match(/false/) + end + it "doesn't render address" do + render + expect(rendered).not_to match(/#{@fetprofile.street}/) expect(rendered).not_to match(/#{@fetprofile.city}/) expect(rendered).not_to match(/#{@fetprofile.hdynr}/) expect(rendered).not_to match(/#{@fetprofile.telnr}/) expect(rendered).not_to match(/#{@fetprofile.plz}/) - end - it "renders links to gremium" do - render - expect(rendered).to match(/#{gremium_path(@gremium)}/) - end - it "renders gremium links" do - render - expect(rendered).to match(/#{gremium_path(@gremium2)}/) - end - it "doesn't render gremium links for hidden gremium" do - render - expect(rendered).not_to match(/#{gremium_path(@gremium3)}/) - end - - describe "with fet user" do - login_fet_user - -# let(:current_ability) {@ability} - it "renders address" do - render - expect(rendered).to match(/#{@fetprofile.street}/) - expect(rendered).to match(/#{@fetprofile.plz}/) - expect(rendered).to match(/#{@fetprofile.city}/) - expect(rendered).to match(/#{@fetprofile.hdynr}/) - expect(rendered).to match(/#{@fetprofile.telnr}/) - end - it "renders edit path" do + it "renders links to gremium" do render - expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) + expect(rendered).to match(/#{gremium_path(@gremium)}/) + end + it "renders gremium links" do + render + expect(rendered).to match(/#{gremium_path(@gremium2)}/) + end + it "doesn't render gremium links for hidden gremium" do + render + expect(rendered).not_to match(/#{gremium_path(@gremium3)}/) + end + + describe "with fet user" do + login_fet_user + + # let(:current_ability) {@ability} + it "renders address" do + render + expect(rendered).to match(/#{@fetprofile.street}/) + expect(rendered).to match(/#{@fetprofile.plz}/) + expect(rendered).to match(/#{@fetprofile.city}/) + expect(rendered).to match(/#{@fetprofile.hdynr}/) + expect(rendered).to match(/#{@fetprofile.telnr}/) + + end + it "renders edit path" do + render + expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) + end end end end -end -end From c7d12e9a42db5544ef90a80e86e31888b52ffe58 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 4 Sep 2015 14:03:04 +0200 Subject: [PATCH 37/73] AutoCommit Fre Sep 4 14:03:04 CEST 2015 --- app/models/document.rb | 2 +- app/views/documents/_search_results.html.erb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/document.rb b/app/models/document.rb index f820ebc..5123b52 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -102,7 +102,7 @@ class Document < ActiveRecord::Base end text :name, :boost=>4.0, :stored=> true text :meeting, stored: true do |d| - (d.parent_type == "Meeting")? d.try(:parent).try(:text).to_s : "" + (d.parent.is_a?(Meeting))? d.try(:parent).try(:text).to_s : "" end end def maketoc diff --git a/app/views/documents/_search_results.html.erb b/app/views/documents/_search_results.html.erb index 47d616a..1e1a655 100644 --- a/app/views/documents/_search_results.html.erb +++ b/app/views/documents/_search_results.html.erb @@ -1,17 +1,22 @@ <% unless search_results.nil? %> -<%= search_results %> +<%#= search_results %> + +
          <% search_results.each_hit_with_result do |hit,result| %>
        • <%= link_to result.parent.title+": " + result.name, document_path(result) %> +
          <%= hit.highlights.to_yaml %>
          +
          <%#= hit.to_yaml %>
          + <% hit.highlights(:name).each do |hlgt| %> - <%= raw(hlgt.format{|word|"#{word}" } ) %> + <%= (hlgt.format{|word|"#{word}" } ).html_safe%> <% end %> <% %> <% hit.highlights(:text).each do |hlgt| %> - <%= "text:" + raw(hlgt.format {|word| raw("#{word}") })%> + <%= "text:" + (hlgt.format {|word| raw("#{word}") }).html_safe%> <% end %> <% hit.highlights(:meeting).each do |hlgt| %> - <%= "text:" + raw(hlgt.format {|word| "*#{word}*" })%> + <%= "text:" + (hlgt.format {|word| "*#{word}*" }).html_safe%> <% end %>
        • From eccb090d5c5466a39328575847d21ba0118a8201 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 15:03:11 +0200 Subject: [PATCH 38/73] AutoCommit Sam Sep 5 15:03:11 CEST 2015 --- app/controllers/documents_controller.rb | 2 +- app/views/documents/_search_results.html.erb | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index bacf9af..22361db 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -157,7 +157,7 @@ class DocumentsController < ApplicationController @results = Document.search do fulltext params['query'] do fields :name, :text, :meeting - highlight :text + highlight :text,:name,:meeting end end @res=[] diff --git a/app/views/documents/_search_results.html.erb b/app/views/documents/_search_results.html.erb index 1e1a655..1d72a50 100644 --- a/app/views/documents/_search_results.html.erb +++ b/app/views/documents/_search_results.html.erb @@ -5,15 +5,12 @@
            <% search_results.each_hit_with_result do |hit,result| %>
          • <%= link_to result.parent.title+": " + result.name, document_path(result) %> -
            <%= hit.highlights.to_yaml %>
            -
            <%#= hit.to_yaml %>
            - <% hit.highlights(:name).each do |hlgt| %> <%= (hlgt.format{|word|"#{word}" } ).html_safe%> <% end %> <% %> - <% hit.highlights(:text).each do |hlgt| %> - <%= "text:" + (hlgt.format {|word| raw("#{word}") }).html_safe%> + <% hit.highlights(:text).each do |hlgt| %> + <%= ("
            text: " + hlgt.format {|word| "#{word}" }).html_safe%> <% end %> <% hit.highlights(:meeting).each do |hlgt| %> <%= "text:" + (hlgt.format {|word| "*#{word}*" }).html_safe%> From 4b1d11751db10602d599ff530b2e99cb7ab16c67 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 16:03:02 +0200 Subject: [PATCH 39/73] AutoCommit Sam Sep 5 16:03:02 CEST 2015 --- Gemfile | 3 ++- solr/conf/schema.xml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 9d1a94e..0e3e90a 100755 --- a/Gemfile +++ b/Gemfile @@ -86,7 +86,8 @@ gem 'carrierwave', "~>0.9.0" group :development, :test do gem 'factory_girl_rails',"~>4.5.0" gem 'rspec-rails' -gem 'minitest', "~>4.7.5" +#gem 'minitest', "~>4.7.5" +gem 'progress_bar' gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' gem 'rspec-html-matchers' diff --git a/solr/conf/schema.xml b/solr/conf/schema.xml index adcb9a8..3c66821 100644 --- a/solr/conf/schema.xml +++ b/solr/conf/schema.xml @@ -63,8 +63,9 @@ + - + From a84332d09f47d2561c72fe2a6d81b0b174eee73c Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 17:03:04 +0200 Subject: [PATCH 40/73] AutoCommit Sam Sep 5 17:03:04 CEST 2015 --- solr/conf/schema.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/solr/conf/schema.xml b/solr/conf/schema.xml index 3c66821..8da24f2 100644 --- a/solr/conf/schema.xml +++ b/solr/conf/schema.xml @@ -60,12 +60,17 @@ - - - - + + - + + + + + + + + From a96e48fa36071c06312af91349c81b869ab96ca9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 18:03:02 +0200 Subject: [PATCH 41/73] AutoCommit Sam Sep 5 18:03:02 CEST 2015 --- spec/support/view_macros.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/support/view_macros.rb b/spec/support/view_macros.rb index 0f6989e..ad0d3d2 100644 --- a/spec/support/view_macros.rb +++ b/spec/support/view_macros.rb @@ -26,5 +26,20 @@ module ViewMacros sign_in user end end + def login_fetadmin_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:user) + user = User.find_by_email(user.email) || user + user.save + user.add_role(:fetadmin) + # user.confirm! + @user=user + @ability= Ability.new(@user) + # controller.stub(:current_ability) { @ability } + allow(view).to receive(:current_ability).and_return(@ability) + sign_in user + end + end end From 13f852cf4834bd4ba5b71251c84c4b1285fced29 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 19:03:01 +0200 Subject: [PATCH 42/73] AutoCommit Sam Sep 5 19:03:01 CEST 2015 --- app/models/gremium.rb | 1 + spec/factories/gremien.rb | 3 +++ spec/factories/memberships.rb | 9 +++++++-- spec/models/gremium_spec.rb | 36 ++++++++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/models/gremium.rb b/app/models/gremium.rb index 8fd3c7e..8ee1800 100644 --- a/app/models/gremium.rb +++ b/app/models/gremium.rb @@ -23,6 +23,7 @@ class Gremium < ActiveRecord::Base has_many :memberships, dependent: :destroy # Mitgliedschaften bei dem Gremium has_many :nlinks, as: :link, dependent: :destroy # scope :search, ->(query) {where("gremien.name like ? or gremien.desc like ?", "%#{query}%", "%#{query}%")} +# has_many :members, through: :memberships searchable do text :desc text :name, :boost=>4.0 diff --git a/spec/factories/gremien.rb b/spec/factories/gremien.rb index 7e0dba0..ba025c0 100644 --- a/spec/factories/gremien.rb +++ b/spec/factories/gremien.rb @@ -7,5 +7,8 @@ FactoryGirl.define do name "Kommission" desc "Das ist eine Kommission die sich mit irgendwas beschäftigt" typ 1 + factory :gremium_with_fetprofile do + association :memberships, factory: :membership_with_fetprofile + end end end diff --git a/spec/factories/memberships.rb b/spec/factories/memberships.rb index aa3968a..e73392a 100644 --- a/spec/factories/memberships.rb +++ b/spec/factories/memberships.rb @@ -2,10 +2,15 @@ FactoryGirl.define do factory :membership do - fetprofile_id 1 - gremium_id 1 + start "2013-08-19" stop "2013-08-23" typ 1 + factory :membership_with_fetprofile do + association :fetprofile + end + factory :membership_with_gremium do + association :gremium + end end end diff --git a/spec/models/gremium_spec.rb b/spec/models/gremium_spec.rb index 8f34f2a..08bfae2 100644 --- a/spec/models/gremium_spec.rb +++ b/spec/models/gremium_spec.rb @@ -1,5 +1,39 @@ require 'spec_helper' describe Gremium do - pending "add some examples to (or delete) #{__FILE__}" + it "can be created" do + g=FactoryGirl.build(:gremium) + expect(g.save).to be true + end + it "is valid with all attributes" do + g = FactoryGirl.build(:gremium) + g.should be_valid + end + [:name,:typ].each do |attr| + it "should not be valid without #{attr}" do + g = FactoryGirl.build(:gremium) + g.send("#{attr}=".to_sym,nil) + expect(g).not_to be_valid + end + end + it "is in tabs if typ is 1 or 3" do + g = FactoryGirl.create(:gremium, typ: 1) + expect(Gremium.tabs).to eq([g]) + end + it "is not in tabs if typ is not 1 or 3" do + g = FactoryGirl.create(:gremium, typ: 2) + expect(Gremium.tabs).to eq([]) + end + it "destroys memberships if its destroyed" do + g=FactoryGirl.create(:gremium_with_fetprofile) + expect(Membership.count).to be(1) + g.delete + expect(Membership.count).to be(0) + + end + + it "responds to title" do + g=FactoryGirl.build(:gremium) + expect(g.responds_to?(:title)).to be true + end end From d509884aa1aae47b22bd395a50e40b6d65f04d92 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 5 Sep 2015 21:03:02 +0200 Subject: [PATCH 43/73] AutoCommit Sam Sep 5 21:03:02 CEST 2015 --- spec/factories/gremien.rb | 5 +---- spec/factories/memberships.rb | 10 +++------- spec/models/gremium_spec.rb | 11 ++++++----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/spec/factories/gremien.rb b/spec/factories/gremien.rb index ba025c0..b85811e 100644 --- a/spec/factories/gremien.rb +++ b/spec/factories/gremien.rb @@ -7,8 +7,5 @@ FactoryGirl.define do name "Kommission" desc "Das ist eine Kommission die sich mit irgendwas beschäftigt" typ 1 - factory :gremium_with_fetprofile do - association :memberships, factory: :membership_with_fetprofile - end - end + end end diff --git a/spec/factories/memberships.rb b/spec/factories/memberships.rb index e73392a..5a715d1 100644 --- a/spec/factories/memberships.rb +++ b/spec/factories/memberships.rb @@ -2,15 +2,11 @@ FactoryGirl.define do factory :membership do - + gremium_id 1 + fetprofile_id 1 start "2013-08-19" stop "2013-08-23" typ 1 - factory :membership_with_fetprofile do - association :fetprofile - end - factory :membership_with_gremium do - association :gremium - end + end end diff --git a/spec/models/gremium_spec.rb b/spec/models/gremium_spec.rb index 08bfae2..effb8f6 100644 --- a/spec/models/gremium_spec.rb +++ b/spec/models/gremium_spec.rb @@ -25,15 +25,16 @@ describe Gremium do expect(Gremium.tabs).to eq([]) end it "destroys memberships if its destroyed" do - g=FactoryGirl.create(:gremium_with_fetprofile) - expect(Membership.count).to be(1) - g.delete - expect(Membership.count).to be(0) + g=FactoryGirl.create(:gremium) + fp=FactoryGirl.create(:fetprofile) + m=FactoryGirl.create(:membership, gremium_id: g.id, fetprofile_id: fp.id) + expect{g.destroy}.to change {Membership.count}.by(-1) + end it "responds to title" do g=FactoryGirl.build(:gremium) - expect(g.responds_to?(:title)).to be true + expect(g.respond_to?(:title)).to be true end end From b9079c0525a00966afb31d1df23b425e2eb68460 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 6 Sep 2015 21:03:06 +0200 Subject: [PATCH 44/73] AutoCommit Son Sep 6 21:03:06 CEST 2015 --- spec/controllers/gremien_controller_spec.rb | 47 ++++++--------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/spec/controllers/gremien_controller_spec.rb b/spec/controllers/gremien_controller_spec.rb index 6045afe..693e11d 100644 --- a/spec/controllers/gremien_controller_spec.rb +++ b/spec/controllers/gremien_controller_spec.rb @@ -1,48 +1,27 @@ require 'spec_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. +describe GremienController, :type => :view do + let(:valid_update_attributes) { { "name" => "MyString" } } -describe GremienController do - - # This should return the minimal set of attributes required to create a valid - # Gremium. As you add validations to Gremium, be sure to - # adjust the attributes here as well. - let(:valid_attributes) { { "name" => "MyString" } } - - # 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 - # GremienController. Be sure to keep this updated too. - let(:valid_session) { {} } + def self.create_gremium + before(:each) do + @gremium = FactoryGirl.create(:gremium) + end + end describe "GET index" do + create_gremium + subject(:action) { get :index, {} } it "assigns all gremien as @gremien" do - gremium = Gremium.create! valid_attributes - get :index, {}, valid_session - assigns(:gremien).should eq([gremium]) + expect(assigns(:gremien)).to eq([@gremium]) end end describe "GET show" do + create_gremium + subject(:action) {get :show, {:id => gremium.to_param}} it "assigns the requested gremium as @gremium" do - gremium = Gremium.create! valid_attributes - get :show, {:id => gremium.to_param}, valid_session - assigns(:gremium).should eq(gremium) + expect(assigns(:gremium)).to eq(gremium) end end From 8c2efffff46b29540034ce8ea69beac73841a7d0 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 6 Sep 2015 23:03:05 +0200 Subject: [PATCH 45/73] AutoCommit Son Sep 6 23:03:05 CEST 2015 --- spec/controllers/gremien_controller_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/controllers/gremien_controller_spec.rb b/spec/controllers/gremien_controller_spec.rb index 693e11d..7719266 100644 --- a/spec/controllers/gremien_controller_spec.rb +++ b/spec/controllers/gremien_controller_spec.rb @@ -26,8 +26,10 @@ describe GremienController, :type => :view do end describe "GET new" do + subject(:action) { get :new, {}} + it "assigns a new gremium as @gremium" do - get :new, {}, valid_session + assigns(:gremium).should be_a_new(Gremium) end end From 8fa549ae238b1fb0bd9038bc278456270a3727ff Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 7 Sep 2015 00:03:01 +0200 Subject: [PATCH 46/73] AutoCommit Mon Sep 7 00:03:01 CEST 2015 --- spec/controllers/gremien_controller_spec.rb | 184 ++++++++++++-------- 1 file changed, 111 insertions(+), 73 deletions(-) diff --git a/spec/controllers/gremien_controller_spec.rb b/spec/controllers/gremien_controller_spec.rb index 7719266..03dfc6b 100644 --- a/spec/controllers/gremien_controller_spec.rb +++ b/spec/controllers/gremien_controller_spec.rb @@ -1,141 +1,179 @@ require 'spec_helper' -describe GremienController, :type => :view do - let(:valid_update_attributes) { { "name" => "MyString" } } +describe GremienController, :type => :controller do + let(:valid_update_attributes) { {"name"=>"NeuesGremium"} } + # let(:valid_session) { {locale: :de} } def self.create_gremium before(:each) do @gremium = FactoryGirl.create(:gremium) end end +# def self.create_active_gremium +# before(:each) do +# @gremium = FactoryGirl.create(:gremium, active: true) +# end +# end + + let(:object_variable) {:gremium} + let(:assigned_object_variable) {@gremium} + let(:object_class) {Gremium} describe "GET index" do create_gremium - subject(:action) { get :index, {} } - it "assigns all gremien as @gremien" do - expect(assigns(:gremien)).to eq([@gremium]) - end + subject(:action) { get :index, {} } + let(:object_variable) {:gremien} + let(:assigned_object_variable) {[@gremium]} + it_behaves_like "it is success" + it_behaves_like "it assigns object" end describe "GET show" do create_gremium - subject(:action) {get :show, {:id => gremium.to_param}} - it "assigns the requested gremium as @gremium" do - expect(assigns(:gremium)).to eq(gremium) - end + subject(:action) { get :show, {:id => @gremium.to_param}} + it_behaves_like "it is success" + it_behaves_like "it assigns object" + it "renders the 'show' template" do + expect(action).to render_template("show") + end + it "assigns memberships" do + action + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) + end + end describe "GET new" do subject(:action) { get :new, {}} - - it "assigns a new gremium as @gremium" do - - assigns(:gremium).should be_a_new(Gremium) + describe "with fetuser" do + login_fet_user + it_behaves_like "it assigns new object" + it_behaves_like "it is success" end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end describe "GET edit" do + + subject(:action) {get :edit, :id=>@gremium.to_param} + login_fet_user + create_gremium + it_behaves_like "it is success" + it_behaves_like "it assigns object" + it "assigns memberships" do + action + expect(assigns(:memberships)).to be_a(ActiveRecord::Relation) + end + it "assigns the requested gremium as @gremium" do - gremium = Gremium.create! valid_attributes - get :edit, {:id => gremium.to_param}, valid_session - assigns(:gremium).should eq(gremium) + expect{action}.to change {assigns(:gremium)}.to(@gremium) + # expect(assigns(:gremium)).to eq(@gremium) end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end describe "POST create" do - describe "with valid params" do - it "creates a new Gremium" do - expect { - post :create, {:gremium => valid_attributes}, valid_session - }.to change(Gremium, :count).by(1) - end + subject(:action){post :create, {:gremium => FactoryGirl.attributes_for(:gremium),:format=>:html}} - it "assigns a newly created gremium as @gremium" do - post :create, {:gremium => valid_attributes}, valid_session - assigns(:gremium).should be_a(Gremium) - assigns(:gremium).should be_persisted + login_fet_user + describe "with valid params" do + + it "has a 302 status code" do + expect(action.status).to eq(302) + end + it "creates a new Gremium" do + expect{action}.to change(Gremium, :count).by(1) end + + it_behaves_like "it assigns persisted object" + it "redirects to the created gremium" do - post :create, {:gremium => valid_attributes}, valid_session - response.should redirect_to(Gremium.last) + expect(action).to redirect_to assigns(:gremium) end end describe "with invalid params" do - it "assigns a newly created but unsaved gremium as @gremium" do - # Trigger the behavior that occurs when invalid params are submitted - Gremium.any_instance.stub(:save).and_return(false) - post :create, {:gremium => { "name" => "invalid value" }}, valid_session - assigns(:gremium).should be_a_new(Gremium) - end + has_invalid_params + + it "assigns a newly created but unsaved gremium as @gremium" do + action + assigns(:gremium).should be_a_new(Gremium) + expect(assigns(:gremium)).not_to be_persisted + end it "re-renders the 'new' template" do - # Trigger the behavior that occurs when invalid params are submitted - Gremium.any_instance.stub(:save).and_return(false) - post :create, {:gremium => { "name" => "invalid value" }}, valid_session - response.should render_template("new") + expect(action).to render_template("new") end end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end describe "PUT update" do - describe "with valid params" do - it "updates the requested gremium" do - gremium = Gremium.create! valid_attributes - # Assuming there are no other gremien in the database, this - # specifies that the Gremium created on the previous line - # receives the :update_attributes message with whatever params are - # submitted in the request. - Gremium.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" }) - put :update, {:id => gremium.to_param, :gremium => { "name" => "MyString" }}, valid_session - end + let(:action) { put :update, {:id => @gremium.to_param, :gremium => {"name"=>"neuerName"}} } + + create_gremium + login_fet_user - it "assigns the requested gremium as @gremium" do - gremium = Gremium.create! valid_attributes - put :update, {:id => gremium.to_param, :gremium => valid_attributes}, valid_session - assigns(:gremium).should eq(gremium) + describe "with valid params" do + it_behaves_like "it assigns object" + + it "updates the requested gremium" do + expect { action }.to change{Gremium.find(@gremium.id).name}.to("neuerName") end + it_behaves_like "it assigns persisted object" it "redirects to the gremium" do - gremium = Gremium.create! valid_attributes - put :update, {:id => gremium.to_param, :gremium => valid_attributes}, valid_session - response.should redirect_to(gremium) + expect(action).to redirect_to(@gremium) end end describe "with invalid params" do - it "assigns the gremium as @gremium" do - gremium = Gremium.create! valid_attributes - # Trigger the behavior that occurs when invalid params are submitted - Gremium.any_instance.stub(:save).and_return(false) - put :update, {:id => gremium.to_param, :gremium => { "name" => "invalid value" }}, valid_session - assigns(:gremium).should eq(gremium) - end - + has_invalid_params + it_behaves_like "it assigns object" it "re-renders the 'edit' template" do - gremium = Gremium.create! valid_attributes - # Trigger the behavior that occurs when invalid params are submitted - Gremium.any_instance.stub(:save).and_return(false) - put :update, {:id => gremium.to_param, :gremium => { "name" => "invalid value" }}, valid_session - response.should render_template("edit") + expect(action).to render_template("edit") end end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end end describe "DELETE destroy" do + login_fet_user + create_gremium + subject(:action) { delete :destroy, {:id => @gremium.to_param}} + it "destroys the requested gremium" do - gremium = Gremium.create! valid_attributes expect { - delete :destroy, {:id => gremium.to_param}, valid_session + action }.to change(Gremium, :count).by(-1) end it "redirects to the gremien list" do - gremium = Gremium.create! valid_attributes - delete :destroy, {:id => gremium.to_param}, valid_session + action response.should redirect_to(gremien_url) end + describe "without user" do + logout_user + it_behaves_like "it is restricted" + end + end end + From 5531eb089ee807a9b5c6ae4c283436036955e26e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 8 Sep 2015 14:03:06 +0200 Subject: [PATCH 47/73] AutoCommit Die Sep 8 14:03:06 CEST 2015 --- app/mailers/news_mailer.rb | 4 +-- app/views/news_mailer/neuigkeit_mail.html.erb | 2 +- spec/factories/neuigkeit.rb | 7 +++++ spec/factories/rubrik.rb | 6 ++++ spec/mailers/news_mailer_spec.rb | 28 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 spec/factories/neuigkeit.rb create mode 100644 spec/factories/rubrik.rb diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb index bfb3b1a..86ee2be 100644 --- a/app/mailers/news_mailer.rb +++ b/app/mailers/news_mailer.rb @@ -9,11 +9,11 @@ class NewsMailer < ActionMailer::Base @user=User.first @ability=Ability.new(@user) subject = @neuigkeit.title - subject = subject + " email: " + email if Rails.env=="development" + subject = subject.to_s + " email: " + email.to_s if Rails.env=="development" email = "andis@fet.at" if Rails.env=="development" email="andis@fet.at" mail(to: email, subject: subject) -render locals: {current_user: User.first} + render locals: {current_user: User.first} end def daily_newsletter(user_id) user=User.find(user_id) diff --git a/app/views/news_mailer/neuigkeit_mail.html.erb b/app/views/news_mailer/neuigkeit_mail.html.erb index b66792b..b1c2da5 100644 --- a/app/views/news_mailer/neuigkeit_mail.html.erb +++ b/app/views/news_mailer/neuigkeit_mail.html.erb @@ -4,7 +4,7 @@

            <%= @neuigkeit.title%>

            -<%= content_tag(:img,"",src: "http://"+ActionMailer::Base.default_url_options[:host].to_s+@neuigkeit.picture.big_thumb.url) %> +<%= content_tag(:img,"",src: "http://"+ActionMailer::Base.default_url_options[:host].to_s+@neuigkeit.picture.big_thumb.url.to_s) %> <%=url_for controller: "neuigkeiten",action: :show, :id=>@neuigkeit.id, only_path: false %> <%= raw(@neuigkeit.text) %> <% @neuigkeit.questions.each do |q| %> diff --git a/spec/factories/neuigkeit.rb b/spec/factories/neuigkeit.rb new file mode 100644 index 0000000..e6e3bba --- /dev/null +++ b/spec/factories/neuigkeit.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :neuigkeit do + title "WIChtige Neuigkeit" + text "

            Das ist eine wichtige Information

            " + datum 1.days.ago + end +end diff --git a/spec/factories/rubrik.rb b/spec/factories/rubrik.rb new file mode 100644 index 0000000..b390be5 --- /dev/null +++ b/spec/factories/rubrik.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :rubrik do + name "Allgemeine" + desc "Allgemeine Test News" + end +end diff --git a/spec/mailers/news_mailer_spec.rb b/spec/mailers/news_mailer_spec.rb index 205f934..a123f83 100644 --- a/spec/mailers/news_mailer_spec.rb +++ b/spec/mailers/news_mailer_spec.rb @@ -1,5 +1,33 @@ require "spec_helper" describe NewsMailer do +include Rails.application.routes.url_helpers pending "add some examples to (or delete) #{__FILE__}" + describe 'neuigkeit_mail' do + before(:each) do + + rubrik = FactoryGirl.create(:rubrik) + @neuigkeit=FactoryGirl.create(:neuigkeit, author_id: user.id, rubrik_id: rubrik.id) + NewsMailer.stub(:default_url_options).and_return({host:"localhost", port: 3000}) + end + let(:user) {User.first || FactoryGirl.create(:user)} + let(:email) {"test@mail.com"} + let(:neuigkeit) {@neuigkeit} + + let(:mail) {NewsMailer.neuigkeit_mail(email.to_s, neuigkeit.id)} + it "renders neuigkeit title" do + expect(mail.body.to_s).to match(/#{@neuigkeit.title}/) + end + it "renders neuigkeit expect" do + expect(mail.body.to_s).to match(/#{@neuigkeit.text}/) + end + it "is sent to current user" do + expect(mail.to).to eq([user.email]) + end + it "links to web page" do + expect(mail.body.to_s).to match(/#{neuigkeit_url(@neuigkeit, locale: nil, theme: nil, host:"localhost", port: 3000)}/) + + end + + end end From 0da3ee8ed904cdd187ab640d44c68f6320ea8fe3 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 9 Sep 2015 11:03:37 +0200 Subject: [PATCH 48/73] AutoCommit Mit Sep 9 11:03:36 CEST 2015 --- spec/models/neuigkeit_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/models/neuigkeit_spec.rb diff --git a/spec/models/neuigkeit_spec.rb b/spec/models/neuigkeit_spec.rb new file mode 100644 index 0000000..73f07ba --- /dev/null +++ b/spec/models/neuigkeit_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Neuigkeit do + let(:rubrik) {FactoryGirl.create(:rubrik)} + let(:user) {FactoryGirl.create(:user)} + [:title,:text, :rubrik_id].each do |attr| + it "should not be valid without #{attr}" do + fp = FactoryGirl.build(:fetprofile) + fp.send("#{attr}=".to_sym,nil) + fp.should_not be_valid + end + end + it "should be created" do + + fp=Fetprofile.new(FactoryGirl.attributes_for(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)) + expect(fp.save).to be true + end + + it "should be valid" do + fp = FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id) + fp.should be_valid + end + pending "is parent for attachments " + pending "has questions" + pending "has nlinks" + pending "has calentries" + pending "can be an event" + pending "is published by date" + pending "has meeting" + pending "is shareable" +end From 1e488818301eec8e41f18ec5bb4991c8fc7b4de1 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 9 Sep 2015 22:03:05 +0200 Subject: [PATCH 49/73] AutoCommit Mit Sep 9 22:03:05 CEST 2015 --- Gemfile | 3 ++- spec/models/calentry_spec.rb | 4 ++-- spec/models/crawlobject_spec.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 0e3e90a..b1931b2 100755 --- a/Gemfile +++ b/Gemfile @@ -85,9 +85,10 @@ gem 'annotate', ">=2.5.0" gem 'carrierwave', "~>0.9.0" group :development, :test do gem 'factory_girl_rails',"~>4.5.0" -gem 'rspec-rails' #gem 'minitest', "~>4.7.5" gem 'progress_bar' +gem 'rspec-rails', '~>3.2.0' + gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' gem 'rspec-html-matchers' diff --git a/spec/models/calentry_spec.rb b/spec/models/calentry_spec.rb index 02e654e..8c29c7e 100644 --- a/spec/models/calentry_spec.rb +++ b/spec/models/calentry_spec.rb @@ -4,14 +4,14 @@ describe Calentry do it "should be valid with full data" do e = FactoryGirl.build(:calentry) c = FactoryGirl.create(:calendar) - e.calendars< nil) c=FactoryGirl.create(:calendar) - e.calendars< :model do +RSpec.describe Crawlobject do pending "add some examples to (or delete) #{__FILE__}" end From 01c6fedaeeaa4a47008f5f30ea3178324f3457b8 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 9 Sep 2015 23:03:01 +0200 Subject: [PATCH 50/73] AutoCommit Mit Sep 9 23:03:01 CEST 2015 --- Gemfile | 2 +- spec/spec_helper.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index b1931b2..702aa3c 100755 --- a/Gemfile +++ b/Gemfile @@ -87,7 +87,7 @@ group :development, :test do gem 'factory_girl_rails',"~>4.5.0" #gem 'minitest', "~>4.7.5" gem 'progress_bar' -gem 'rspec-rails', '~>3.2.0' +gem 'rspec-rails', '~>3.3.0' gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 088c0ab..f2cc48a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,8 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' -require 'rspec/autorun' +#require 'rspec/autorun' +# require 'minitest/autorun' require 'sunspot_test/rspec' require 'devise' # Requires supporting ruby files with custom matchers and macros, etc, From 9521f04c72c5ed5ef6e1496c6849d1fc1ddf87a7 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 10 Sep 2015 00:03:03 +0200 Subject: [PATCH 51/73] AutoCommit Don Sep 10 00:03:03 CEST 2015 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 702aa3c..b1931b2 100755 --- a/Gemfile +++ b/Gemfile @@ -87,7 +87,7 @@ group :development, :test do gem 'factory_girl_rails',"~>4.5.0" #gem 'minitest', "~>4.7.5" gem 'progress_bar' -gem 'rspec-rails', '~>3.3.0' +gem 'rspec-rails', '~>3.2.0' gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' From b7abbb8a77e24f26ac0157138232e53844fba08c Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 10 Sep 2015 09:03:01 +0200 Subject: [PATCH 52/73] AutoCommit Don Sep 10 09:03:01 CEST 2015 --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2cc48a..35e791c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' -#require 'rspec/autorun' +require 'rspec/autorun' # require 'minitest/autorun' require 'sunspot_test/rspec' require 'devise' From f59f0cb05a7e534580e57ee7c6302038db00395f Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 10 Sep 2015 20:03:01 +0200 Subject: [PATCH 53/73] AutoCommit Don Sep 10 20:03:01 CEST 2015 --- spec/models/news.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 spec/models/news.rb diff --git a/spec/models/news.rb b/spec/models/news.rb new file mode 100644 index 0000000..a4c7afd --- /dev/null +++ b/spec/models/news.rb @@ -0,0 +1 @@ +require 'neuigkeit_spec.rb' From edaf15454902d62643c8f09fccd8b46f40008b99 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 10 Sep 2015 21:03:02 +0200 Subject: [PATCH 54/73] AutoCommit Don Sep 10 21:03:02 CEST 2015 --- spec/models/calentry_spec.rb | 33 +++++++++++++++++++-------------- spec/models/news.rb | 7 ++++++- spec/models/rubrik_spec.rb | 6 ++++++ spec/spec_helper.rb | 2 +- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 spec/models/rubrik_spec.rb diff --git a/spec/models/calentry_spec.rb b/spec/models/calentry_spec.rb index 8c29c7e..a8ec91b 100644 --- a/spec/models/calentry_spec.rb +++ b/spec/models/calentry_spec.rb @@ -1,20 +1,25 @@ require 'spec_helper' describe Calentry do - it "should be valid with full data" do - e = FactoryGirl.build(:calentry) - c = FactoryGirl.create(:calendar) - e.calendars << c - e.should be_valid - end - [:ende,:start,:typ].each do |attr| - it "should not be valid without #{attr}" do - e= FactoryGirl.build(:calentry, attr => nil) - c=FactoryGirl.create(:calendar) - e.calendars << c - e.should_not be_valid - e.should have_at_least(1).errors_on(attr) - end + before(:each) do + @user = FactoryGirl.create(:user) + end + let(:rubrik) {FactoryGirl.create(:rubrik)} + let(:user) {FactoryGirl.create(:user)} + let(:calendar) {FactoryGirl.create(:calendar)} + let(:neuigkeit) {FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)} + + it "should be valid with full data" do + e = FactoryGirl.build(:calentry, calendar_id: calendar.id, object_type: "Neuigkeit",object_id: neuigkeit.id) + expect(e).to be_valid + end + + [:ende,:start,:typ].each do |attr| + it "is not valid without #{attr}" do + e= FactoryGirl.build(:calentry, calendar_id: calendar.id, object_type: "Neuigkeit",object_id: neuigkeit.id, attr => nil) + expect(e).not_to be_valid + expect(e).to have_at_least(1).errors_on(attr) + end end end diff --git a/spec/models/news.rb b/spec/models/news.rb index a4c7afd..0a49b2b 100644 --- a/spec/models/news.rb +++ b/spec/models/news.rb @@ -1 +1,6 @@ -require 'neuigkeit_spec.rb' +require 'models/neuigkeit_spec.rb' +require 'models/rubrik_spec.rb' +require 'models/attachment_spec.rb' +require 'models/calentry_spec.rb' +require 'models/calendar_spec.rb' +require 'models/nlink_spec.rb' diff --git a/spec/models/rubrik_spec.rb b/spec/models/rubrik_spec.rb new file mode 100644 index 0000000..4251f9c --- /dev/null +++ b/spec/models/rubrik_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +describe Rubrik do + pending "add some examples to (or delete) #{__FILE__}" + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 35e791c..90d68f8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,7 +33,7 @@ RSpec.configure do |config| # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" +# config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false From 68e2d4a5a7049cc93501c1ba10ba5e3319a91516 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 10 Sep 2015 22:03:01 +0200 Subject: [PATCH 55/73] AutoCommit Don Sep 10 22:03:01 CEST 2015 --- spec/models/calentry_spec.rb | 50 +++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/spec/models/calentry_spec.rb b/spec/models/calentry_spec.rb index a8ec91b..6420e6f 100644 --- a/spec/models/calentry_spec.rb +++ b/spec/models/calentry_spec.rb @@ -1,17 +1,15 @@ require 'spec_helper' describe Calentry do - before(:each) do - @user = FactoryGirl.create(:user) - end + let(:rubrik) {FactoryGirl.create(:rubrik)} let(:user) {FactoryGirl.create(:user)} - let(:calendar) {FactoryGirl.create(:calendar)} - let(:neuigkeit) {FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)} + let(:calendar) {FactoryGirl.create(:calendar,updated_at: 1.hour.ago)} + let(:neuigkeit) {FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id, updated_at: 1.hour.ago)} + subject(:calentry) {FactoryGirl.build(:calentry, calendar_id: calendar.id, object_type: "Neuigkeit",object_id: neuigkeit.id)} - it "should be valid with full data" do - e = FactoryGirl.build(:calentry, calendar_id: calendar.id, object_type: "Neuigkeit",object_id: neuigkeit.id) - expect(e).to be_valid + it "is valid with full data" do + expect(calentry).to be_valid end [:ende,:start,:typ].each do |attr| @@ -21,5 +19,39 @@ describe Calentry do expect(e).to have_at_least(1).errors_on(attr) end end - + it "updates updated_at of neuigekit" do + expect {calentry.dauer+=1.hour;calentry.save}.to change{calentry.object.updated_at} + end + it "updates updated_at of calendar" do + expect {calentry.dauer+=1.hour;calentry.save}.to change{calentry.calendar.updated_at} + end + it "changes ende with dauer" do + expect {calentry.dauer=7}.to change(calentry,:ende).to(calentry.start+7.hours) + end + it "changes dauer with ende" do + expect {calentry.ende=calentry.start+7.hours}.to change(calentry,:dauer).to(7) + end + it "sets is upcomming" do + calentry.start=1.hour.from_now + calentry.dauer=2 + expect(calentry.is_upcomming?).to be true + expect(calentry.is_past?).to be false + expect(calentry.is_ongoing?).to be false + + calentry.start=1.hour.ago + calentry.dauer=2 + + expect(calentry.is_upcomming?).to be false + expect(calentry.is_past?).to be false + expect(calentry.is_ongoing?).to be true + + calentry.start=4.hour.ago + calentry.dauer=2 + + expect(calentry.is_upcomming?).to be false + expect(calentry.is_past?).to be true + expect(calentry.is_ongoing?).to be false + + end + end From 9a9c7f74f993bde71936dfb4691c48d530c14837 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 11 Sep 2015 13:03:02 +0200 Subject: [PATCH 56/73] AutoCommit Fre Sep 11 13:03:02 CEST 2015 --- Gemfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index b1931b2..35e99ad 100755 --- a/Gemfile +++ b/Gemfile @@ -60,16 +60,17 @@ gem "paper_trail" , '~>3.0.5'#, :git=>'git://github.com/airblade/paper_trail.git # User management gem "devise" ,'~>2.2.3' -gem "omniauth" -gem "omniauth-facebook" -gem "omniauth-ldap" +gem "omniauth", '~>1.2.2' +gem "omniauth-facebook", '~>2.0.0' +gem "omniauth-ldap", '~>1.0.4' -gem "fb_graph" +gem "fb_graph",'~>2.7.17' gem "meta-tags" # Roles for users -gem "rolify" +gem "rolify", '~>4.0.0' # Abilities -gem "cancan" +gem "cancan", '~>1.6.0' + # Fileupload @@ -87,12 +88,13 @@ group :development, :test do gem 'factory_girl_rails',"~>4.5.0" #gem 'minitest', "~>4.7.5" gem 'progress_bar' -gem 'rspec-rails', '~>3.2.0' - +gem 'rspec-core', '~>3.3.0' +gem 'rspec-rails', '~>3.3.0' gem 'rspec-collection_matchers' gem 'rspec-activemodel-mocks' gem 'rspec-html-matchers' gem 'rspec-expectations' +gem 'capybara', '~>2.5.0' end gem "simple_calendar", "~> 0.1.9" From 0dc83df98cb922a66ea49281a722209723f9a45e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 11 Sep 2015 15:03:05 +0200 Subject: [PATCH 57/73] AutoCommit Fre Sep 11 15:03:05 CEST 2015 --- spec/features/beispielsammlung_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 spec/features/beispielsammlung_spec.rb diff --git a/spec/features/beispielsammlung_spec.rb b/spec/features/beispielsammlung_spec.rb new file mode 100644 index 0000000..fd9fd81 --- /dev/null +++ b/spec/features/beispielsammlung_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' +feature 'Beispielsammlung' do + scenario 'anonym user visits beispielsammlung' do + visit root_path + click_link 'Beispielsammlung' + expect(page).to have_text(studium.title) + expect(page).to have_tag("link to lva") + click_link 'LVA1' + expect(page).to have_text(beispiel.name) + end + +end + From e486ab02fd1e625aca272320cdc9feb529362b9e Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 11 Sep 2015 19:03:01 +0200 Subject: [PATCH 58/73] AutoCommit Fre Sep 11 19:03:01 CEST 2015 --- spec/features/beispielsammlung_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/features/beispielsammlung_spec.rb b/spec/features/beispielsammlung_spec.rb index fd9fd81..6a8af12 100644 --- a/spec/features/beispielsammlung_spec.rb +++ b/spec/features/beispielsammlung_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -feature 'Beispielsammlung' do +feature 'Beispielsammlung', :type=>:feature do scenario 'anonym user visits beispielsammlung' do - visit root_path + visit '/' click_link 'Beispielsammlung' - expect(page).to have_text(studium.title) - expect(page).to have_tag("link to lva") - click_link 'LVA1' - expect(page).to have_text(beispiel.name) + expect(page).to have_text("Elektrotechnik") +# expect(page).to have_tag("link to lva") +# click_link 'LVA1' + # expect(page).to have_text(beispiel.name) end end From 514bdc1ef04785bebc4b90170f97c30f50c4b4a0 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 11 Sep 2015 21:03:01 +0200 Subject: [PATCH 59/73] AutoCommit Fre Sep 11 21:03:01 CEST 2015 --- app/views/layouts/_login.html.erb | 4 +-- spec/features/beispielsammlung_spec.rb | 35 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/_login.html.erb b/app/views/layouts/_login.html.erb index 133ed37..9ba3425 100644 --- a/app/views/layouts/_login.html.erb +++ b/app/views/layouts/_login.html.erb @@ -7,11 +7,11 @@ <%= current_user.email %> is logged in.
          • -
          • <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
          • +
          • <%= link_to('Logout', destroy_user_session_path, :method => :delete,:id => "login_link") %>
          <% else %>
        • - <%= link_to('Login', new_user_session_path) %> + <%= link_to('Login', new_user_session_path, id:"login_link") %>
        • <% end %> diff --git a/spec/features/beispielsammlung_spec.rb b/spec/features/beispielsammlung_spec.rb index 6a8af12..4278fa6 100644 --- a/spec/features/beispielsammlung_spec.rb +++ b/spec/features/beispielsammlung_spec.rb @@ -1,9 +1,38 @@ require 'spec_helper' +Capybara.add_selector(:href) do + xpath {|href| XPath.descendant[XPath.attr(:href).contains(href)] } +end feature 'Beispielsammlung', :type=>:feature do - scenario 'anonym user visits beispielsammlung' do + let!(:rubrik) {FactoryGirl.create(:rubrik)} + let!(:user) {FactoryGirl.create(:user)} + let!(:themengruppe){ FactoryGirl.create(:themengruppe) } + let!(:studium) {FactoryGirl.create(:studium)} + before(:each) do + FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id) + FactoryGirl.create(:thema, id: t=YAML.load_file("#{::Rails.root.to_s}/config/start_topic.yml").to_i, themengruppe_id: themengruppe.id) + studium.id + end + scenario 'login' do + user.add_role(:fetuser) visit '/' - click_link 'Beispielsammlung' - expect(page).to have_text("Elektrotechnik") + find(:href, "sign_in").click + fill_in 'user_email', with: user.email + fill_in 'user_password', with:"password" + click_button 'Sign in' + click_link 'Startseite' + end + def sign_in + visit '/' + find(:href, "sign_in").click + fill_in 'user_email', with: user.email + fill_in 'user_password', with:"password" + click_button 'Sign in' + end + scenario 'anonym user visits beispielsammlung' do + # sign_in + visit "/studien/#{studium.id}" + # click_link 'Beispielsammlung' + expect(page).to have_text(studium.title) # expect(page).to have_tag("link to lva") # click_link 'LVA1' # expect(page).to have_text(beispiel.name) From 52dac513f73658cf2bd38da493fbcc6c6ab38473 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 12 Sep 2015 10:03:56 +0200 Subject: [PATCH 60/73] AutoCommit Sam Sep 12 10:03:56 CEST 2015 --- app/views/beispiele/_form.html.erb | 6 +++--- spec/factories/logo2014_64.png | Bin 0 -> 2455 bytes spec/features/beispielsammlung_spec.rb | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 spec/factories/logo2014_64.png diff --git a/app/views/beispiele/_form.html.erb b/app/views/beispiele/_form.html.erb index 7f6df24..07285a6 100755 --- a/app/views/beispiele/_form.html.erb +++ b/app/views/beispiele/_form.html.erb @@ -12,7 +12,7 @@ <% end %>
    - <% f.file_field :beispieldatei, :label => "Neue Datei hochladen:"%> + <%= f.file_field :beispieldatei, :label => "Neue Datei hochladen:" if @beispiel.beispieldatei.nil? || @beispiel.beispieldatei.blank? %>
    <%=f.input :datum , :as => :datetimepicker %> @@ -20,11 +20,11 @@
    <%= f.input :name %> - + <%= f.input :lva if @beispiel.lva.nil?%> <%= f.input :desc %>
    - <%= f.input :lecturer, :as=>:select, :collection => @beispiel.lva.lecturers %> + <%= f.input :lecturer, :as=>:select, :collection => ((@beispiel.lva.nil?|| @beispiel.lva.lecturers.empty?)? Lecturer.all : @beispiel.lva.lecturers) %>
    <%= f.hidden_field :beispieldatei_cache %> <%= f.actions do %> diff --git a/spec/factories/logo2014_64.png b/spec/factories/logo2014_64.png new file mode 100644 index 0000000000000000000000000000000000000000..10b2ecf27a0780c3942abcfd9d7cf76bef44e350 GIT binary patch literal 2455 zcmV;I3263-P)*VrW9T}Aa@8qMRJd+&e#bLQN~jHoLA&#-b$AlDcaAlC$P zjX?o&O(5486d>0Ga*aU&a!nxD$f^KRT^$lZve{-|$eI8Waffld_yA$|&)I6TKgebT z+zLzu?v%=!(OGQwiU?(~tuOm~!B{r{+ky@fai^gA5VrnKYbqMDK`MI@V3^r+Y)$XQ z>p_r8jP=Xxkjkb2qSJwo{Ie;&c+L0s-^e^64_V9sG6mQP7%-Dktb(A-20)o1D}P^* z4OUqZ!0-BsfFnQ?$b=N9^4LV605}EMgu13>gIjhYz;VX_Lr|K5R-ib=NA&V*@tViX z^p+VlgxS=UoyL-Fs4iyM$9s}|^1D_N4|&m}))H*9 zIHfJGJKay*{FIABFMe9?0P;ybjEKmWfO~-%{VdX=sz39~jsw02e4YMB-~+09OhiWc z?S31`>u1?cV7aPxrnRc-Rc*kp00Zb%Y-|0pcK{z=W!VNmfXTpruClBGuUzSVt||wJ z$i2X0X%yb+?|Z|uB62kx1>aBck+ zZ>rBHUb$`rPV@<%Oe4wao&@GlRb?gk7xBZok!d354}r3m00$7Nsw_(D3n|%@uc}a0 z6{57h5GR_KREHD21}8c!A)10udjTt+9ZqR|A*J;N{fX$llVGR49zz?jfYiasa>{F4 zIX>Zb@RL-h{cG&bnnWiN84BDTDEp+Ux~i%)6^|#c^I=AP=&czv7k!Pqj?);ux4VwA zXGWr&L3zBp?PN4U)teMt{D8cU)8utD%BuC(^>uq83CCt5@$ZAo2M%JJ$F!#6IDk|{ z7lAAX>+`_FfwJcTn^<@rpi=8B0(OA=F0dltdlxVwaP6pwEJ`?!spY6BqUbu+NK9t4UJ*#W#5Ldm(U!KVeVCUCwO@B}E( z6MjbN87vu{?$NXkkY3P@7*-(?Q@8vLaiR|)@-)Yb9swSgaC9k_JOdH}8c@CiJZd3C zF!nTcow*ouBM?W~M*EO=fT>_Tiub;KF3n9O;w4o*k8l>4c=@7;j0P6^=GmD0)iBGi|v}e{RG9CC6PyAvSaC@M>4IC?4h|r=@XCHtnO8d}zQ0jn@ zpuc6rg&Q^M90bs)b5PxIZAv$&>ndA-l|AjsC?Ghx+rW>XK1}o^ge|9s4KmL`pZN(gd{|O>UG%q6i`C)AV`7d z5q<+~O1hV4S6l$X!Fx4X*}N=Y zRV%xR)<&KKp2JOavr193v-?ySL2=7pfxiXndlM(xhH@9in%j^2NkV_-0>SWqkJ9>P zL}EZEDlaElMSTHuGH_j*Hf8`#BGPb$?N%hd3}I}~*ChETRaF!4y5mG_MCC4!ty)`t zn5)DUBS1uof!hL?pCi9xI?5@KHCkKVnq;-($1oufod`S+oCbm)LPq*qI-CRE0_$c_ zo2KHiRIIm%+b`nH0}?;2bpe|YT?nkY(!KPCzFvVzq;^*uHR`kisSBF`ZDZRgJl%!J zWK})q4}l$^u%Ddvs%pDL+*TAY)&!tU-SC@I>&ye5O7Lw|)sw)+e%76WPc$3svr@-x z0NJl@c%ekx`%&4YZus?X`%l)4q9cDk9q~QXR~{o0y`8w-sI}#LyL}?=Vw9IamSD%< zrHh$d8otv{Yy*Z&tqLFQUgcFD0rNnTwY{JSBU{J|Eu*Y%G)A_7NzOHK)8rkP33OSj z5bHIDUl=~nL^C9SHlj?CWt(ka93o9gW^Z*ERL3AX-e+^E~P$*d^K2}Fxf@s`LfN%wRQq0B~^1-d&ER5KI-_I|(mZ+SZtT%-V@4Y(Fn zuQxGPONx)TSTYC5LwPR~Ofw^ZW&CWeo&d%=lO+cj44S$YKk^dJ7gzjXELu2j1@4h%(P zE|Rj2=hYA^Yb3vODrX9VqtO9F=6;b;do5ya1$ip1UF4|0l6O7GtG!m^^#&P3#stvX z@;6BL6}a0$4tXJ$<`o1{s+RewHx!vvjTr:feature do let!(:rubrik) {FactoryGirl.create(:rubrik)} let!(:user) {FactoryGirl.create(:user)} let!(:themengruppe){ FactoryGirl.create(:themengruppe) } - let!(:studium) {FactoryGirl.create(:studium)} + let!(:studium) {FactoryGirl.create(:studium,:visible=>true)} before(:each) do FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id) FactoryGirl.create(:thema, id: t=YAML.load_file("#{::Rails.root.to_s}/config/start_topic.yml").to_i, themengruppe_id: themengruppe.id) @@ -23,20 +24,30 @@ feature 'Beispielsammlung', :type=>:feature do end def sign_in visit '/' + user.add_role(:fetadmin) + find(:href, "sign_in").click fill_in 'user_email', with: user.email fill_in 'user_password', with:"password" click_button 'Sign in' end scenario 'anonym user visits beispielsammlung' do - # sign_in - visit "/studien/#{studium.id}" - # click_link 'Beispielsammlung' +# sign_in + visit "/" + click_link 'Beispielsammlung' expect(page).to have_text(studium.title) # expect(page).to have_tag("link to lva") # click_link 'LVA1' # expect(page).to have_text(beispiel.name) end + scenario 'load something up' do + visit "/" + click_link 'Beispiel hinzufügen' + page.attach_file('beispiel[beispieldatei]', Rails.root + 'spec/factories/logo2014_64.png') + click_button "Create Beispiel" + # find(:href,"/beispiele/new").click + + end end From cfb42584e1daa65d164d0bdc2c07e03a40c19089 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 12 Sep 2015 11:03:02 +0200 Subject: [PATCH 61/73] AutoCommit Sam Sep 12 11:03:02 CEST 2015 --- Gemfile | 2 +- spec/models/beispiel_spec.rb | 36 +++++++++++++++-------------- spec/models/crawlobject_spec.rb | 2 +- spec/models/document_spec.rb | 2 +- spec/models/key_spec.rb | 2 +- spec/models/lva_spec.rb | 36 ++++++++++++----------------- spec/models/meeting_spec.rb | 2 +- spec/models/meetingtyp_spec.rb | 2 +- spec/models/modulgruppe_spec.rb | 6 +++-- spec/models/survey/answer_spec.rb | 2 +- spec/models/survey/choice_spec.rb | 2 +- spec/models/survey/question_spec.rb | 2 +- spec/models/user_spec.rb | 2 ++ spec/spec_helper.rb | 10 ++++++-- spec/support/model_macros.rb | 18 +++++++++++++++ 15 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 spec/support/model_macros.rb diff --git a/Gemfile b/Gemfile index 35e99ad..326bfca 100755 --- a/Gemfile +++ b/Gemfile @@ -86,7 +86,7 @@ gem 'annotate', ">=2.5.0" gem 'carrierwave', "~>0.9.0" group :development, :test do gem 'factory_girl_rails',"~>4.5.0" -#gem 'minitest', "~>4.7.5" +gem 'minitest', "~>4.7.5" gem 'progress_bar' gem 'rspec-core', '~>3.3.0' gem 'rspec-rails', '~>3.3.0' diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index c32600e..7066dd1 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -1,19 +1,21 @@ require 'spec_helper' -describe Beispiel do - before(:each) do - s=FactoryGirl.create(:studium) - mg=FactoryGirl.build(:modulgruppe) - mg.studium= s - mg.save! - m=FactoryGirl.build(:other_modul) - m.modulgruppen << mg - m.save! - @l=FactoryGirl.build(:lva) - @l.modul << m - @l.save! - end +describe Beispiel, :type=>:model do + let_studium_lva +# before(:each) do +# s=FactoryGirl.create(:studium) +# mg=FactoryGirl.create(:modulgruppe, studium_id: s.id)# + +# m=FactoryGirl.build(:other_modul) +# m.modulgruppen << mg +# m.save! + +# @l=FactoryGirl.build(:lva) +# @l.modul << m +# @l.save! +# end before(:each) do + @l=lva @b=FactoryGirl.build(:beispiel) @b.lva=@l end @@ -22,14 +24,14 @@ describe Beispiel do @b.lva=@l expect{@b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) end - it "should not be valid without lva" do + it "is not valid without lva" do b=FactoryGirl.build(:beispiel) expect(b.valid?).to be false end - it "should respond to comments" do + it "responds to comments" do expect(@b.respond_to?(:comments)).to be true end - it "should respond to get_flag" do + it "responds to get_flag" do expect(@b.respond_to?(:get_flag)).to be true end [:delete, :goodquality, :badquality].each do |flg| @@ -40,7 +42,7 @@ describe Beispiel do end it "should respond to flag setter #{flg}" do - puts "flag_#{flg.to_s}" + # puts "flag_#{flg.to_s}" expect(@b.respond_to?("flag_#{flg.to_s}".to_sym)).to be true end end diff --git a/spec/models/crawlobject_spec.rb b/spec/models/crawlobject_spec.rb index 23b9039..87b4ecd 100644 --- a/spec/models/crawlobject_spec.rb +++ b/spec/models/crawlobject_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Crawlobject do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index d39f418..20eb7f2 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Document, :type => :model do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index f94d28a..ae283cf 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Key, :type => :model do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/lva_spec.rb b/spec/models/lva_spec.rb index 435b2ed..4b01478 100644 --- a/spec/models/lva_spec.rb +++ b/spec/models/lva_spec.rb @@ -2,32 +2,26 @@ require 'spec_helper' describe Lva do pending "add some examples to (or delete) #{__FILE__}" - before(:all) do - s=FactoryGirl.create(:studium) - mg=FactoryGirl.build(:modulgruppe) - mg.studium= s - mg.save! - @m=FactoryGirl.build(:other_modul) - @m.modulgruppen << mg - @m.save! - puts "Beispiele before filter" - end + let_studium_lva before(:each) do @l = FactoryGirl.build(:lva) end - it "should be created" do - l=FactoryGirl.build(:lva) - l.modul << @m - expect{l.save!; Sunspot.commit}.to change{Lva.count}.by(1) - end - it "should not be valid without module" do - l=FactoryGirl.build(:lva) - expect(l.valid?).to be false - expect(l.errors[:modul].size).to be(1) + describe "if bare" do + let(:lva) {FactoryGirl.build(:lva)} + it "should be created" do + l=lva + l.modul << modul + expect{l.save!; Sunspot.commit}.to change{Lva.count}.by(1) + end + it "should not be valid without module" do + l=lva + expect(l.valid?).to be false + expect(l.errors[:modul].size).to be(1) + end end it "should respond to semesters" do -@l -end +expect(lva).respond_to?(:semesters).to be true + end pending "should not be valid without modul" pending "should have beispiele" pending "should be flagable" diff --git a/spec/models/meeting_spec.rb b/spec/models/meeting_spec.rb index 93d55f7..2e72528 100644 --- a/spec/models/meeting_spec.rb +++ b/spec/models/meeting_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Meeting, :type => :model do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/meetingtyp_spec.rb b/spec/models/meetingtyp_spec.rb index c55d7c0..09545ef 100644 --- a/spec/models/meetingtyp_spec.rb +++ b/spec/models/meetingtyp_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Meetingtyp, :type => :model do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/modulgruppe_spec.rb b/spec/models/modulgruppe_spec.rb index 3a863e3..d06d7bf 100644 --- a/spec/models/modulgruppe_spec.rb +++ b/spec/models/modulgruppe_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Modulgruppe do +describe Modulgruppe, :type =>:model do it "should not be valid without studium" do mg=FactoryGirl.build(:modulgruppe) mg.should_not be_valid @@ -42,5 +42,7 @@ describe Modulgruppe do mg.should be_valid end - + pending "add some examples to (or delete) #{__FILE__}" + pending "DRY #{__FILE__}" + end diff --git a/spec/models/survey/answer_spec.rb b/spec/models/survey/answer_spec.rb index 518fae0..7dcc5dc 100644 --- a/spec/models/survey/answer_spec.rb +++ b/spec/models/survey/answer_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Survey::Answer, :type => :model do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/survey/choice_spec.rb b/spec/models/survey/choice_spec.rb index 2923d52..46d24ce 100644 --- a/spec/models/survey/choice_spec.rb +++ b/spec/models/survey/choice_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Survey::Choice, :type => :model do pending "picture" diff --git a/spec/models/survey/question_spec.rb b/spec/models/survey/question_spec.rb index bb98bdc..5f26dd3 100644 --- a/spec/models/survey/question_spec.rb +++ b/spec/models/survey/question_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require 'spec_helper' RSpec.describe Survey::Question, :type => :model do pending "have choices" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0f54532..1888364 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' describe User do + pending "add some examples to (or delete) #{__FILE__}" + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90d68f8..f283b59 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,13 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' +require 'rbconfig' + require File.expand_path("../../config/environment", __FILE__) +#require 'rspec/autorun' require 'rspec/rails' -require 'rspec/autorun' -# require 'minitest/autorun' + + +#require 'minitest/autorun' require 'sunspot_test/rspec' require 'devise' # Requires supporting ruby files with custom matchers and macros, etc, @@ -15,6 +19,8 @@ Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| requi RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller + config.extend ModelMacros, :type => :model + config.include Devise::TestHelpers, :type => :view config.include RSpecHtmlMatchers, :type => :view config.extend ViewMacros, :type => :view diff --git a/spec/support/model_macros.rb b/spec/support/model_macros.rb new file mode 100644 index 0000000..5da7d1d --- /dev/null +++ b/spec/support/model_macros.rb @@ -0,0 +1,18 @@ +module ModelMacros + def let_studium_lva + let(:studium) {FactoryGirl.create(:studium)} + let(:modulgruppe){FactoryGirl.create(:modulgruppe,studium_id: studium.id)} + let(:modul) do + m=FactoryGirl.build(:other_modul); + m.modulgruppen << modulgruppe + m.save! + m + end + let(:lva) do + l=FactoryGirl.build(:lva) + l.modul << modul + l.save! + l + end + end +end From 3d87ce6fd2c5d6f44e33b2c70436e970ae14fa89 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 12 Sep 2015 12:03:06 +0200 Subject: [PATCH 62/73] AutoCommit Sam Sep 12 12:03:06 CEST 2015 --- spec/models/beispiel_spec.rb | 34 +++++++++++++++------------------- spec/models/gremium_spec.rb | 2 ++ spec/models/lva_spec.rb | 4 ++-- spec/models/modul_spec.rb | 16 +++++++++------- spec/models/neuigkeit_spec.rb | 16 ++++++++-------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index 7066dd1..cc67f20 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -14,49 +14,45 @@ describe Beispiel, :type=>:model do # @l.modul << m # @l.save! # end - before(:each) do - @l=lva - @b=FactoryGirl.build(:beispiel) - @b.lva=@l - end + let(:lva){FactoryGirl.build_stubbed(:lva)} + let(:beispiel){FactoryGirl.build(:beispiel, lva: lva)} it "should be created" do - @b.lva=@l - expect{@b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) + + expect{beispiel.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) end it "is not valid without lva" do b=FactoryGirl.build(:beispiel) expect(b.valid?).to be false end it "responds to comments" do - expect(@b.respond_to?(:comments)).to be true + expect(beispiel.respond_to?(:comments)).to be true end it "responds to get_flag" do - expect(@b.respond_to?(:get_flag)).to be true + expect(beispiel.respond_to?(:get_flag)).to be true end [:delete, :goodquality, :badquality].each do |flg| - it "should have default false for flag #{flg}" do - b=FactoryGirl.create(:beispiel, lva_id: @l.id) + it " has default false for flag #{flg}" do + b=beispiel expect(b.respond_to?(:get_flag)).to be true expect(b.get_flag(flg)).to be false end - it "should respond to flag setter #{flg}" do - # puts "flag_#{flg.to_s}" - expect(@b.respond_to?("flag_#{flg.to_s}".to_sym)).to be true + it "responds to flag setter #{flg}" do + expect(beispiel.respond_to?("flag_#{flg.to_s}".to_sym)).to be true end end it "should be in not_flag beispiele" do - @b.save! + beispiel.save! bsp= Beispiel.not_flag_delete - expect(bsp).to include @b + expect(bsp).to include beispiel end it "should not be in not_flag" do - @b.save! + beispiel.save! bsp= Beispiel.not_flag_delete - expect{@b.flag_delete=true; @b.save!}.to change{ Beispiel.not_flag_delete.count }.by(-1) - expect{@b.flag_delete=nil; @b.save!}.to change{ Beispiel.not_flag_delete.count }.by(1) + expect{beispiel.flag_delete=true; beispiel.save!}.to change{ Beispiel.not_flag_delete.count }.by(-1) + expect{beispiel.flag_delete=nil; beispiel.save!}.to change{ Beispiel.not_flag_delete.count }.by(1) end diff --git a/spec/models/gremium_spec.rb b/spec/models/gremium_spec.rb index effb8f6..cc6d887 100644 --- a/spec/models/gremium_spec.rb +++ b/spec/models/gremium_spec.rb @@ -14,6 +14,8 @@ describe Gremium do g = FactoryGirl.build(:gremium) g.send("#{attr}=".to_sym,nil) expect(g).not_to be_valid + expect(g.errors[attr]).to have_at_least(1).items + end end it "is in tabs if typ is 1 or 3" do diff --git a/spec/models/lva_spec.rb b/spec/models/lva_spec.rb index 4b01478..5766efd 100644 --- a/spec/models/lva_spec.rb +++ b/spec/models/lva_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Lva do +describe Lva, :type=>:model do pending "add some examples to (or delete) #{__FILE__}" let_studium_lva before(:each) do @@ -20,7 +20,7 @@ describe Lva do end end it "should respond to semesters" do -expect(lva).respond_to?(:semesters).to be true + expect(lva.respond_to?(:semester)).to be true end pending "should not be valid without modul" pending "should have beispiele" diff --git a/spec/models/modul_spec.rb b/spec/models/modul_spec.rb index 2bc5894..262b8dd 100644 --- a/spec/models/modul_spec.rb +++ b/spec/models/modul_spec.rb @@ -1,14 +1,16 @@ require 'spec_helper' describe Modul do - it "should not be valid without name" do - m = FactoryGirl.build(:modul) - m.should_not be_valid - m.should have(1).errors_on(:name) + [:name].each do |attr| + it "should not be valid without #{attr}" do + modul = FactoryGirl.build(:modul) + modul.send("#{attr}=".to_sym,nil) + expect(modul).not_to be_valid + expect(modul).to have_at_least(1).errors_on(attr) + end end - it "should be valid with name" do + it "is valid with everything" do m = FactoryGirl.build(:modul) - m.name = "Grundlagen" - m.should be_valid + expect(m).to be_valid end end diff --git a/spec/models/neuigkeit_spec.rb b/spec/models/neuigkeit_spec.rb index 73f07ba..5b7e972 100644 --- a/spec/models/neuigkeit_spec.rb +++ b/spec/models/neuigkeit_spec.rb @@ -3,22 +3,22 @@ require 'spec_helper' describe Neuigkeit do let(:rubrik) {FactoryGirl.create(:rubrik)} let(:user) {FactoryGirl.create(:user)} - [:title,:text, :rubrik_id].each do |attr| + let(:neuigkeit) {(FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id))} + [:title,:text, :rubrik, :author].each do |attr| it "should not be valid without #{attr}" do - fp = FactoryGirl.build(:fetprofile) - fp.send("#{attr}=".to_sym,nil) - fp.should_not be_valid + neuigkeit.send("#{attr}=".to_sym,nil) + expect(neuigkeit).not_to be_valid + expect(neuigkeit.errors[attr]).to have_at_least(1).items end end it "should be created" do - - fp=Fetprofile.new(FactoryGirl.attributes_for(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)) - expect(fp.save).to be true + expect(neuigkeit).to be_valid + expect(neuigkeit.save).to be true end it "should be valid" do fp = FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id) - fp.should be_valid + expect(fp).to be_valid end pending "is parent for attachments " pending "has questions" From ff70c31c4014116a23512dd1c548eb5d1eabcb19 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 12 Sep 2015 13:03:02 +0200 Subject: [PATCH 63/73] AutoCommit Sam Sep 12 13:03:02 CEST 2015 --- spec/models/beispiel_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index cc67f20..cf86e80 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -18,7 +18,7 @@ describe Beispiel, :type=>:model do let(:beispiel){FactoryGirl.build(:beispiel, lva: lva)} it "should be created" do - + expect{beispiel.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) end it "is not valid without lva" do From 92667b92e9fecf60aba7f87a4403420f69c0fcae Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 12 Sep 2015 22:03:04 +0200 Subject: [PATCH 64/73] AutoCommit Sam Sep 12 22:03:04 CEST 2015 --- app/assets/javascripts/jmpress.js | 2659 +++++++++++++++++ app/controllers/home_controller.rb | 5 + app/views/home/infoscreen.html.erb | 53 + .../neuigkeiten/_neuigkeit_view.html.erb | 2 +- .../themes/blue2/neuigkeiten/_menu.html.erb | 22 +- .../neuigkeiten/_neuigkeit_view.html.erb | 6 +- config/routes.rb | 1 + 7 files changed, 2733 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/jmpress.js create mode 100644 app/views/home/infoscreen.html.erb diff --git a/app/assets/javascripts/jmpress.js b/app/assets/javascripts/jmpress.js new file mode 100644 index 0000000..39f5624 --- /dev/null +++ b/app/assets/javascripts/jmpress.js @@ -0,0 +1,2659 @@ +/*! + * jmpress.js v0.4.5 + * http://jmpressjs.github.com/jmpress.js + * + * A jQuery plugin to build a website on the infinite canvas. + * + * Copyright 115 Kyle Robinson Young @shama & Tobias Koppers @sokra + * Licensed MIT + * http://www.opensource.org/licenses/mit-license.php + * + * Based on the foundation laid by Bartek Szopka @bartaz + */ +/* + * core.js + * The core of jmpress.js + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /** + * Set supported prefixes + * + * @access protected + * @return Function to get prefixed property + */ + var pfx = (function () { + var style = document.createElement('dummy').style, + prefixes = 'Webkit Moz O ms Khtml'.split(' '), + memory = {}; + return function ( prop ) { + if ( typeof memory[ prop ] === "undefined" ) { + var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1), + props = (prop + ' ' + prefixes.join(ucProp + ' ') + ucProp).split(' '); + memory[ prop ] = null; + for ( var i in props ) { + if ( style[ props[i] ] !== undefined ) { + memory[ prop ] = props[i]; + break; + } + } + } + return memory[ prop ]; + }; + }()); + + /** + * map ex. "WebkitTransform" to "-webkit-transform" + */ + function mapProperty( name ) { + if(!name) { + return; + } + var index = 1 + name.substr(1).search(/[A-Z]/); + var prefix = name.substr(0, index).toLowerCase(); + var postfix = name.substr(index).toLowerCase(); + return "-" + prefix + "-" + postfix; + } + function addComma( attribute ) { + if(!attribute) { + return ""; + } + return attribute + ","; + } + /** + * Return an jquery object only if it's not empty + */ + function ifNotEmpty(el) { + if(el.length > 0) { + return el; + } + return null; + } + + /** + * Default Settings + */ + var defaults = { + /* CLASSES */ + stepSelector: '.step' + ,containerClass: '' + ,canvasClass: '' + ,areaClass: '' + ,notSupportedClass: 'not-supported' + + /* CONFIG */ + ,fullscreen: true + + /* ANIMATION */ + ,animation: { + transformOrigin: 'top left' + ,transitionProperty: addComma(mapProperty(pfx('transform'))) + addComma(mapProperty(pfx('perspective'))) + 'opacity' + ,transitionDuration: '1s' + ,transitionDelay: '500ms' + ,transitionTimingFunction: 'ease-in-out' + ,transformStyle: "preserve-3d" + } + ,transitionDuration: 1500 + }; + var callbacks = { + 'beforeChange': 1 + ,'beforeInitStep': 1 + ,'initStep': 1 + ,'checkNoSupport': 1 + ,'beforeInit': 1 + ,'afterInit': 1 + ,'beforeDeinit': 1 + ,'afterDeinit': 1 + ,'applyStep': 1 + ,'unapplyStep': 1 + ,'setInactive': 1 + ,'beforeActive': 1 + ,'setActive': 1 + ,'selectInitialStep': 1 + ,'selectPrev': 1 + ,'selectNext': 1 + ,'selectHome': 1 + ,'selectEnd': 1 + ,'idle': 1 + ,'applyTarget': 1 + }; + for(var callbackName in callbacks) { + defaults[callbackName] = []; + } + + + /** + * Initialize jmpress + */ + function init( args ) { + args = $.extend(true, {}, args || {}); + + // accept functions and arrays of functions as callbacks + var callbackArgs = {}; + var callbackName = null; + for (callbackName in callbacks) { + callbackArgs[callbackName] = $.isFunction( args[callbackName] ) ? + [ args[callbackName] ] : + args[callbackName]; + args[callbackName] = []; + } + + // MERGE SETTINGS + var settings = $.extend(true, {}, defaults, args); + + for (callbackName in callbacks) { + if (callbackArgs[callbackName]) { + Array.prototype.push.apply(settings[callbackName], callbackArgs[callbackName]); + } + } + + /*** MEMBER VARS ***/ + + var jmpress = $( this ) + ,container = null + ,area = null + ,oldStyle = { + container: "" + ,area: "" + } + ,canvas = null + ,current = null + ,active = false + ,activeSubstep = null + ,activeDelegated = false; + + + /*** MEMBER FUNCTIONS ***/ + // functions have to be called with this + + /** + * Init a single step + * + * @param element the element of the step + * @param idx number of step + */ + function doStepInit( element, idx ) { + var data = dataset( element ); + var step = { + oldStyle: $(element).attr("style") || "" + }; + + var callbackData = { + data: data + ,stepData: step + }; + callCallback.call(this, 'beforeInitStep', $(element), callbackData); + step.delegate = data.delegate; + callCallback.call(this, 'initStep', $(element), callbackData); + + $(element).data('stepData', step); + + if ( !$(element).attr('id') ) { + $(element).attr('id', 'step-' + (idx + 1)); + } + + callCallback.call(this, 'applyStep', $(element), callbackData); + } + /** + * Deinit a single step + * + * @param element the element of the step + */ + function doStepDeinit( element ) { + var stepData = $(element).data('stepData'); + + $(element).attr("style", stepData.oldStyle); + + callCallback.call(this, 'unapplyStep', $(element), { + stepData: stepData + }); + } + /** + * Reapplies stepData to the element + * + * @param element + */ + function doStepReapply( element ) { + callCallback.call(this, 'unapplyStep', $(element), { + stepData: element.data("stepData") + }); + + callCallback.call(this, 'applyStep', $(element), { + stepData: element.data("stepData") + }); + } + /** + * Completly deinit jmpress + * + */ + function deinit() { + if ( active ) { + callCallback.call(this, 'setInactive', active, { + stepData: $(active).data('stepData') + ,reason: "deinit" + } ); + } + if (current.jmpressClass) { + $(jmpress).removeClass(current.jmpressClass); + } + + callCallback.call(this, 'beforeDeinit', $(this), {}); + + $(settings.stepSelector, jmpress).each(function( idx ) { + doStepDeinit.call(jmpress, this ); + }); + + container.attr("style", oldStyle.container); + if(settings.fullscreen) { + $("html").attr("style", ""); + } + area.attr("style", oldStyle.area); + $(canvas).children().each(function() { + jmpress.append( $( this ) ); + }); + if( settings.fullscreen ) { + canvas.remove(); + } else { + canvas.remove(); + area.remove(); + } + + callCallback.call(this, 'afterDeinit', $(this), {}); + + $(jmpress).data("jmpressmethods", false); + + if(current.idleTimeout) { + clearTimeout(current.idleTimeout); + } + } + /** + * Call a callback + * + * @param callbackName String callback which should be called + * @param element some arguments to the callback + * @param eventData + */ + function callCallback( callbackName, element, eventData ) { + eventData.settings = settings; + eventData.current = current; + eventData.container = container; + eventData.parents = element ? getStepParents(element) : null; + eventData.current = current; + eventData.jmpress = this; + var result = {}; + $.each( settings[callbackName], function(idx, callback) { + result.value = callback.call( jmpress, element, eventData ) || result.value; + }); + return result.value; + } + /** + * + */ + function getStepParents( el ) { + return $(el).parentsUntil(jmpress).not(jmpress).filter(settings.stepSelector); + } + /** + * Reselect the active step + * + * @param String type reason of reselecting step + */ + function reselect( type ) { + return select( { step: active, substep: activeSubstep }, type); + } + /** + * Select a given step + * + * @param el element to select + * @param type reason of changing step + * @return Object element selected + */ + function select( el, type ) { + var substep; + if ( $.isPlainObject( el ) ) { + substep = el.substep; + el = el.step; + } + if ( typeof el === 'string') { + el = jmpress.find( el ).first(); + } + if ( !el || !$(el).data('stepData') ) { + return false; + } + + scrollFix.call(this); + + var step = $(el).data('stepData'); + + var cancelSelect = false; + callCallback.call(this, "beforeChange", el, { + stepData: step + ,reason: type + ,cancel: function() { + cancelSelect = true; + } + }); + if (cancelSelect) { + return undefined; + } + + var target = {}; + + var delegated = el; + if($(el).data("stepData").delegate) { + delegated = ifNotEmpty($(el).parentsUntil(jmpress).filter(settings.stepSelector).filter(step.delegate)) || + ifNotEmpty($(el).near(step.delegate)) || + ifNotEmpty($(el).near(step.delegate, true)) || + ifNotEmpty($(step.delegate, jmpress)); + if(delegated) { + step = delegated.data("stepData"); + } else { + // Do not delegate if expression not found + delegated = el; + } + } + if ( activeDelegated ) { + callCallback.call(this, 'setInactive', activeDelegated, { + stepData: $(activeDelegated).data('stepData') + ,delegatedFrom: active + ,reason: type + ,target: target + ,nextStep: delegated + ,nextSubstep: substep + ,nextStepData: step + } ); + } + var callbackData = { + stepData: step + ,delegatedFrom: el + ,reason: type + ,target: target + ,substep: substep + ,prevStep: activeDelegated + ,prevSubstep: activeSubstep + ,prevStepData: activeDelegated && $(activeDelegated).data('stepData') + }; + callCallback.call(this, 'beforeActive', delegated, callbackData); + callCallback.call(this, 'setActive', delegated, callbackData); + + // Set on step class on root element + if (current.jmpressClass) { + $(jmpress).removeClass(current.jmpressClass); + } + $(jmpress).addClass(current.jmpressClass = 'step-' + $(delegated).attr('id') ); + if (current.jmpressDelegatedClass) { + $(jmpress).removeClass(current.jmpressDelegatedClass); + } + $(jmpress).addClass(current.jmpressDelegatedClass = 'delegating-step-' + $(el).attr('id') ); + + callCallback.call(this, "applyTarget", delegated, $.extend({ + canvas: canvas + ,area: area + ,beforeActive: activeDelegated + }, callbackData)); + + active = el; + activeSubstep = callbackData.substep; + activeDelegated = delegated; + + if(current.idleTimeout) { + clearTimeout(current.idleTimeout); + } + current.idleTimeout = setTimeout(function() { + callCallback.call(this, 'idle', delegated, callbackData); + }, Math.max(1, settings.transitionDuration - 100)); + + return delegated; + } + /** + * This should fix ANY kind of buggy scrolling + */ + function scrollFix() { + (function fix() { + if ($(container)[0].tagName === "BODY") { + try { + window.scrollTo(0, 0); + } catch(e) {} + } + $(container).scrollTop(0); + $(container).scrollLeft(0); + function check() { + if ($(container).scrollTop() !== 0 || + $(container).scrollLeft() !== 0) { + fix(); + } + } + setTimeout(check, 1); + setTimeout(check, 10); + setTimeout(check, 100); + setTimeout(check, 200); + setTimeout(check, 400); + }()); + } + /** + * Alias for select + */ + function goTo( el ) { + return select.call(this, el, "jump" ); + } + /** + * Goto Next Slide + * + * @return Object newly active slide + */ + function next() { + return select.call(this, callCallback.call(this, 'selectNext', active, { + stepData: $(active).data('stepData') + ,substep: activeSubstep + }), "next" ); + } + /** + * Goto Previous Slide + * + * @return Object newly active slide + */ + function prev() { + return select.call(this, callCallback.call(this, 'selectPrev', active, { + stepData: $(active).data('stepData') + ,substep: activeSubstep + }), "prev" ); + } + /** + * Goto First Slide + * + * @return Object newly active slide + */ + function home() { + return select.call(this, callCallback.call(this, 'selectHome', active, { + stepData: $(active).data('stepData') + }), "home" ); + } + /** + * Goto Last Slide + * + * @return Object newly active slide + */ + function end() { + return select.call(this, callCallback.call(this, 'selectEnd', active, { + stepData: $(active).data('stepData') + }), "end" ); + } + /** + * Manipulate the canvas + * + * @param props + * @return Object + */ + function canvasMod( props ) { + css(canvas, props || {}); + return $(canvas); + } + /** + * Return current step + * + * @return Object + */ + function getActive() { + return activeDelegated && $(activeDelegated); + } + /** + * fire a callback + * + * @param callbackName + * @param element + * @param eventData + * @return void + */ + function fire( callbackName, element, eventData ) { + if( !callbacks[callbackName] ) { + $.error( "callback " + callbackName + " is not registered." ); + } else { + return callCallback.call(this, callbackName, element, eventData); + } + } + + /** + * PUBLIC METHODS LIST + */ + jmpress.data("jmpressmethods", { + select: select + ,reselect: reselect + ,scrollFix: scrollFix + ,goTo: goTo + ,next: next + ,prev: prev + ,home: home + ,end: end + ,canvas: canvasMod + ,container: function() { return container; } + ,settings: function() { return settings; } + ,active: getActive + ,current: function() { return current; } + ,fire: fire + ,init: function(step) { + doStepInit.call(this, $(step), current.nextIdNumber++); + } + ,deinit: function(step) { + if(step) { + doStepDeinit.call(this, $(step)); + } else { + deinit.call(this); + } + } + ,reapply: doStepReapply + }); + + /** + * Check for support + * This will be removed in near future, when support is coming + * + * @access protected + * @return void + */ + function checkSupport() { + var ua = navigator.userAgent.toLowerCase(); + return (ua.search(/(iphone)|(ipod)|(android)/) === -1) || (ua.search(/(chrome)/) !== -1); + } + + // BEGIN INIT + + // CHECK FOR SUPPORT + if (checkSupport() === false || callCallback.call(this, 'checkNoSupport', null, {})) { + // not supported + if (settings.notSupportedClass) { + jmpress.addClass(settings.notSupportedClass); + } + return; + } else { + if (settings.notSupportedClass) { + jmpress.removeClass(settings.notSupportedClass); + } + } + + // grabbing all steps + var steps = $(settings.stepSelector, jmpress); + + // GERNERAL INIT OF FRAME + container = jmpress; + area = $('
    '); + canvas = $('
    '); + $(jmpress).children().filter(steps).each(function() { + canvas.append( $( this ) ); + }); + if(settings.fullscreen) { + container = $('body'); + $("html").css({ + overflow: 'hidden' + }); + area = jmpress; + } + oldStyle.area = area.attr("style") || ""; + oldStyle.container = container.attr("style") || ""; + if(settings.fullscreen) { + container.css({ + height: '100%' + }); + jmpress.append( canvas ); + } else { + container.css({ + position: "relative" + }); + area.append( canvas ); + jmpress.append( area ); + } + + $(container).addClass(settings.containerClass); + $(area).addClass(settings.areaClass); + $(canvas).addClass(settings.canvasClass); + + document.documentElement.style.height = "100%"; + container.css({ + overflow: 'hidden' + }); + + var props = { + position: "absolute" + ,transitionDuration: '0s' + }; + props = $.extend({}, settings.animation, props); + css(area, props); + css(canvas, props); + + current = {}; + + callCallback.call(this, 'beforeInit', null, { + canvas: canvas, + area: area + }); + + // INITIALIZE EACH STEP + steps.each(function( idx ) { + doStepInit.call(jmpress, this, idx ); + }); + current.nextIdNumber = steps.length; + + callCallback.call(this, 'afterInit', null, {}); + + // START + select.call(this, callCallback.call(this, 'selectInitialStep', "init", {}) ); + + if (settings.initClass) { + $(steps).removeClass(settings.initClass); + } + } + /** + * Return default settings + * + * @return Object + */ + function getDefaults() { + return defaults; + } + /** + * Register a callback or a jmpress function + * + * @access public + * @param name String the name of the callback or function + * @param func Function? the function to be added + */ + function register(name, func) { + if( $.isFunction(func) ) { + if( methods[name] ) { + $.error( "function " + name + " is already registered." ); + } else { + methods[name] = func; + } + } else { + if( callbacks[name] ) { + $.error( "callback " + name + " is already registered." ); + } else { + callbacks[name] = 1; + defaults[name] = []; + } + } + } + /** + * Set CSS on element w/ prefixes + * + * @return Object element which properties were set + * + * TODO: Consider bypassing pfx and blindly set as jQuery + * already checks for support + */ + function css( el, props ) { + var key, pkey, cssObj = {}; + for ( key in props ) { + if ( props.hasOwnProperty(key) ) { + pkey = pfx(key); + if ( pkey !== null ) { + cssObj[pkey] = props[key]; + } + } + } + $(el).css(cssObj); + return el; + } + /** + * Return dataset for element + * + * @param el element + * @return Object + */ + function dataset( el ) { + if ( $(el)[0].dataset ) { + return $.extend({}, $(el)[0].dataset); + } + function toCamelcase( str ) { + str = str.split( '-' ); + for( var i = 1; i < str.length; i++ ) { + str[i] = str[i].substr(0, 1).toUpperCase() + str[i].substr(1); + } + return str.join( '' ); + } + var returnDataset = {}; + var attrs = $(el)[0].attributes; + $.each(attrs, function ( idx, attr ) { + if ( attr.nodeName.substr(0, 5) === "data-" ) { + returnDataset[ toCamelcase(attr.nodeName.substr(5)) ] = attr.nodeValue; + } + }); + return returnDataset; + } + /** + * Returns true, if jmpress is initialized + * + * @return bool + */ + function initialized() { + return !!$(this).data("jmpressmethods"); + } + + + /** + * PUBLIC STATIC METHODS LIST + */ + var methods = { + init: init + ,initialized: initialized + ,deinit: function() {} + ,css: css + ,pfx: pfx + ,defaults: getDefaults + ,register: register + ,dataset: dataset + }; + + /** + * $.jmpress() + */ + $.fn.jmpress = function( method ) { + function f() { + var jmpressmethods = $(this).data("jmpressmethods"); + if ( jmpressmethods && jmpressmethods[method] ) { + return jmpressmethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( methods[method] ) { + return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( callbacks[method] && jmpressmethods ) { + var settings = jmpressmethods.settings(); + var func = Array.prototype.slice.call( arguments, 1 )[0]; + if ($.isFunction( func )) { + settings[method] = settings[method] || []; + settings[method].push(func); + } + } else if ( typeof method === 'object' || ! method ) { + return init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.jmpress' ); + } + // to allow chaining + return this; + } + var args = arguments; + var result; + $(this).each(function(idx, element) { + result = f.apply(element, args); + }); + return result; + }; + $.extend({ + jmpress: function( method ) { + if ( methods[method] ) { + return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( callbacks[method] ) { + // plugin interface + var func = Array.prototype.slice.call( arguments, 1 )[0]; + if ($.isFunction( func )) { + defaults[method].push(func); + } else { + $.error( 'Second parameter should be a function: $.jmpress( callbackName, callbackFunction )' ); + } + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.jmpress' ); + } + } + }); + +}(jQuery, document, window)); + +/* + * near.js + * Find steps near each other + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + // add near( selector, backwards = false) to jquery + + + function checkAndGo( elements, func, selector, backwards ) { + var next; + elements.each(function(idx, element) { + if(backwards) { + next = func(element, selector, backwards); + if (next) { + return false; + } + } + if( $(element).is(selector) ) { + next = element; + return false; + } + if(!backwards) { + next = func(element, selector, backwards); + if (next) { + return false; + } + } + }); + return next; + } + function findNextInChildren(item, selector, backwards) { + var children = $(item).children(); + if(backwards) { + children = $(children.get().reverse()); + } + return checkAndGo( children, findNextInChildren, selector, backwards ); + } + function findNextInSiblings(item, selector, backwards) { + return checkAndGo( + $(item)[backwards ? "prevAll" : "nextAll"](), + findNextInChildren, selector, backwards ); + } + function findNextInParents(item, selector, backwards) { + var next; + var parents = $(item).parents(); + parents = $(parents.get()); + $.each(parents.get(), function(idx, element) { + if( backwards && $(element).is(selector) ) { + next = element; + return false; + } + next = findNextInSiblings(element, selector, backwards); + if(next) { + return false; + } + }); + return next; + } + + $.fn.near = function( selector, backwards ) { + var array = []; + $(this).each(function(idx, element) { + var near = (backwards ? + false : + findNextInChildren( element, selector, backwards )) || + findNextInSiblings( element, selector, backwards ) || + findNextInParents( element, selector, backwards ); + if( near ) { + array.push(near); + } + }); + return $(array); + }; +}(jQuery, document, window)); +/* + * transform.js + * The engine that powers the transforms or falls back to other methods + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* FUNCTIONS */ + function toCssNumber(number) { + return (Math.round(10000*number)/10000)+""; + } + + /** + * 3D and 2D engines + */ + var engines = { + 3: { + transform: function( el, data, settings ) { + var transform = 'translate(-' + settings.originX + ',-' + settings.originY + ')'; + $.each(data, function(idx, item) { + var coord = ["X", "Y", "Z"]; + var i; + if(item[0] === "translate") { // ["translate", x, y, z] + transform += " translate3d(" + toCssNumber(item[1] || 0) + "px," + toCssNumber(item[2] || 0) + "px," + toCssNumber(item[3] || 0) + "px)"; + } else if(item[0] === "rotate") { + var order = item[4] ? [1, 2, 3] : [3, 2, 1]; + for(i = 0; i < 3; i++) { + transform += " rotate" + coord[order[i]-1] + "(" + toCssNumber(item[order[i]] || 0) + "deg)"; + } + } else if(item[0] === "scale") { + for(i = 0; i < 3; i++) { + transform += " scale" + coord[i] + "(" + toCssNumber(item[i+1] || 1) + ")"; + } + } + }); + $.jmpress("css", el, $.extend({}, { transform: transform })); + } + } + ,2: { + transform: function( el, data, settings ) { + var transform = 'translate(-' + settings.originX + ',-' + settings.originY + ')'; + $.each(data, function(idx, item) { + var coord = ["X", "Y"]; + if(item[0] === "translate") { // ["translate", x, y, z] + transform += " translate(" + toCssNumber(item[1] || 0) + "px," + toCssNumber(item[2] || 0) + "px)"; + } else if(item[0] === "rotate") { + transform += " rotate(" + toCssNumber(item[3] || 0) + "deg)"; + } else if(item[0] === "scale") { + for(var i = 0; i < 2; i++) { + transform += " scale" + coord[i] + "(" + toCssNumber(item[i+1] || 1) + ")"; + } + } + }); + $.jmpress("css", el, $.extend({}, { transform: transform })); + } + } + }; + + /** + * Engine to power cross-browser translate, scale and rotate. + */ + var engine = (function() { + if ($.jmpress("pfx", "perspective")) { + return engines[3]; + } else if ($.jmpress("pfx", "transform")) { + return engines[2]; + } + }()); + + if(!engine) { + $.jmpress("checkNoSupport", function() { + return true; + }); + } + + var jmpressDefaults = $.jmpress("defaults"); + jmpressDefaults.reasonableAnimation = {}; + jmpressDefaults.originX = "50%"; + jmpressDefaults.originY = "50%"; + $.jmpress("initStep", function( step, eventData ) { + var data = eventData.data; + var stepData = eventData.stepData; + var pf = parseFloat; + $.extend(stepData, { + x: pf(data.x) || 0 + ,y: pf(data.y) || 0 + ,z: pf(data.z) || 0 + ,r: pf(data.r) || 0 + ,phi: pf(data.phi) || 0 + ,rotate: pf(data.rotate) || 0 + ,rotateX: pf(data.rotateX) || 0 + ,rotateY: pf(data.rotateY) || 0 + ,rotateZ: pf(data.rotateZ) || 0 + ,revertRotate: false + ,scale: pf(data.scale) || 1 + ,scaleX: pf(data.scaleX) || false + ,scaleY: pf(data.scaleY) || false + ,scaleZ: pf(data.scaleZ) || 1 + }); + }); + $.jmpress("beforeInit", function( nil, eventData ) { + $.jmpress("css", eventData.area, { + left: eventData.settings.originX, + top: eventData.settings.originY, + perspective: '1000px', + }); + }); + $.jmpress("afterInit", function( nil, eventData ) { + var stepSelector = eventData.settings.stepSelector, + current = eventData.current; + current.perspectiveScale = 1; + current.maxNestedDepth = 0; + var nestedSteps = $(eventData.jmpress).find(stepSelector).children(stepSelector); + while(nestedSteps.length) { + current.maxNestedDepth++; + nestedSteps = nestedSteps.children(stepSelector); + } + }); + $.jmpress("applyStep", function( step, eventData ) { + $.jmpress("css", $(step), { + position: "absolute" + ,transformStyle: "preserve-3d" + }); + if ( eventData.parents.length > 0 ) { + $.jmpress("css", $(step), { + top: "50%" + ,left: "50%" + }); + } + var sd = eventData.stepData; + var transform = [ + ["translate", + sd.x || (sd.r * Math.sin(sd.phi*Math.PI/180)), + sd.y || (-sd.r * Math.cos(sd.phi*Math.PI/180)), + sd.z], + ["rotate", + sd.rotateX, + sd.rotateY, + sd.rotateZ || sd.rotate, + true], + ["scale", + sd.scaleX || sd.scale, + sd.scaleY || sd.scale, + sd.scaleZ || sd.scale] + ]; + engine.transform( step, transform, eventData.settings ); + }); + $.jmpress("setActive", function( element, eventData ) { + var target = eventData.target; + var step = eventData.stepData; + var tf = target.transform = []; + target.perspectiveScale = 1; + + for(var i = eventData.current.maxNestedDepth; i > (eventData.parents.length || 0); i--) { + tf.push(["scale"], ["rotate"], ["translate"]); + } + + tf.push(["scale", + 1 / (step.scaleX || step.scale), + 1 / (step.scaleY || step.scale), + 1 / (step.scaleZ)]); + tf.push(["rotate", + -step.rotateX, + -step.rotateY, + -(step.rotateZ || step.rotate)]); + tf.push(["translate", + -(step.x || (step.r * Math.sin(step.phi*Math.PI/180))), + -(step.y || (-step.r * Math.cos(step.phi*Math.PI/180))), + -step.z]); + target.perspectiveScale *= (step.scaleX || step.scale); + + $.each(eventData.parents, function(idx, element) { + var step = $(element).data("stepData"); + tf.push(["scale", + 1 / (step.scaleX || step.scale), + 1 / (step.scaleY || step.scale), + 1 / (step.scaleZ)]); + tf.push(["rotate", + -step.rotateX, + -step.rotateY, + -(step.rotateZ || step.rotate)]); + tf.push(["translate", + -(step.x || (step.r * Math.sin(step.phi*Math.PI/180))), + -(step.y || (-step.r * Math.cos(step.phi*Math.PI/180))), + -step.z]); + target.perspectiveScale *= (step.scaleX || step.scale); + }); + + $.each(tf, function(idx, item) { + if(item[0] !== "rotate") { + return; + } + function lowRotate(name) { + if(eventData.current["rotate"+name+"-"+idx] === undefined) { + eventData.current["rotate"+name+"-"+idx] = item[name] || 0; + } + var cur = eventData.current["rotate"+name+"-"+idx], tar = item[name] || 0, + curmod = cur % 360, tarmod = tar % 360; + if(curmod < 0) { + curmod += 360; + } + if(tarmod < 0) { + tarmod += 360; + } + var diff = tarmod - curmod; + if(diff < -180) { + diff += 360; + } else if(diff > 180) { + diff -= 360; + } + eventData.current["rotate"+name+"-"+idx] = item[name] = cur + diff; + } + lowRotate(1); + lowRotate(2); + lowRotate(3); + }); + }); + $.jmpress("applyTarget", function( active, eventData ) { + + var target = eventData.target, + props, step = eventData.stepData, + settings = eventData.settings, + zoomin = target.perspectiveScale * 1.3 < eventData.current.perspectiveScale, + zoomout = target.perspectiveScale > eventData.current.perspectiveScale * 1.3; + + // extract first scale from transform + var lastScale = -1; + $.each(target.transform, function(idx, item) { + if(item.length <= 1) { + return; + } + if(item[0] === "rotate" && + item[1] % 360 === 0 && + item[2] % 360 === 0 && + item[3] % 360 === 0) { + return; + } + if(item[0] === "scale") { + lastScale = idx; + } else { + return false; + } + }); + + if(lastScale !== eventData.current.oldLastScale) { + zoomin = zoomout = false; + eventData.current.oldLastScale = lastScale; + } + + var extracted = []; + if(lastScale !== -1) { + while(lastScale >= 0) { + if(target.transform[lastScale][0] === "scale") { + extracted.push(target.transform[lastScale]); + target.transform[lastScale] = ["scale"]; + } + lastScale--; + } + } + + var animation = settings.animation; + if(settings.reasonableAnimation[eventData.reason]) { + animation = $.extend({}, + animation, + settings.reasonableAnimation[eventData.reason]); + } + + props = { + // to keep the perspective look similar for different scales + // we need to 'scale' the perspective, too + perspective: Math.round(target.perspectiveScale * 1000) + "px" + }; + props = $.extend({}, animation, props); + if (!zoomin) { + props.transitionDelay = '0s'; + } + if (!eventData.beforeActive) { + props.transitionDuration = '0s'; + props.transitionDelay = '0s'; + } + $.jmpress("css", eventData.area, props); + engine.transform(eventData.area, extracted, eventData.settings); + + props = $.extend({}, animation); + if (!zoomout) { + props.transitionDelay = '0s'; + } + if (!eventData.beforeActive) { + props.transitionDuration = '0s'; + props.transitionDelay = '0s'; + } + + eventData.current.perspectiveScale = target.perspectiveScale; + + $.jmpress("css", eventData.canvas, props); + engine.transform(eventData.canvas, target.transform, eventData.settings); + }); + +}(jQuery, document, window)); +/* + * circular.js + * Repeat from start after end + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function firstSlide( step, eventData ) { + return $(this).find(eventData.settings.stepSelector).first(); + } + function prevOrNext( jmpress, step, eventData, prev) { + if (!step) { + return false; + } + var stepSelector = eventData.settings.stepSelector; + step = $(step); + do { + var item = step.near( stepSelector, prev ); + if (item.length === 0 || item.closest(jmpress).length === 0) { + item = $(jmpress).find(stepSelector)[prev?"last":"first"](); + } + if (!item.length) { + return false; + } + step = item; + } while( step.data("stepData").exclude ); + return step; + } + + /* HOOKS */ + $jmpress( 'initStep', function( step, eventData ) { + eventData.stepData.exclude = eventData.data.exclude && ["false", "no"].indexOf(eventData.data.exclude) === -1; + }); + $jmpress( 'selectInitialStep', firstSlide); + $jmpress( 'selectHome', firstSlide); + $jmpress( 'selectEnd', function( step, eventData ) { + return $(this).find(eventData.settings.stepSelector).last(); + }); + $jmpress( 'selectPrev', function( step, eventData ) { + return prevOrNext(this, step, eventData, true); + }); + $jmpress( 'selectNext', function( step, eventData ) { + return prevOrNext(this, step, eventData); + }); +}(jQuery, document, window)); +/* + * start.js + * Set the first step to start on + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* HOOKS */ + $.jmpress( 'selectInitialStep', function( nil, eventData ) { + return eventData.settings.start; + }); + +}(jQuery, document, window)); +/* + * ways.js + * Control the flow of the steps + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function routeFunc( jmpress, route, type ) { + for(var i = 0; i < route.length - 1; i++) { + var from = route[i]; + var to = route[i+1]; + if($(jmpress).jmpress("initialized")) { + $(from, jmpress).data("stepData")[type] = to; + } else { + $(from, jmpress).attr('data-' + type, to); + } + } + } + function selectPrevOrNext( step, eventData, attr, prev ) { + var stepData = eventData.stepData; + if(stepData[attr]) { + var near = $(step).near(stepData[attr], prev); + if(near && near.length) { + return near; + } + near = $(stepData[attr], this)[prev?"last":"first"](); + if(near && near.length) { + return near; + } + } + } + + /* EXPORTED FUNCTIONS */ + $jmpress( 'register', 'route', function( route, unidirectional, reversedRoute ) { + if( typeof route === "string" ) { + route = [route, route]; + } + routeFunc(this, route, reversedRoute ? "prev" : "next"); + if (!unidirectional) { + routeFunc(this, route.reverse(), reversedRoute ? "next" : "prev"); + } + }); + + /* HOOKS */ + $jmpress( 'initStep', function( step, eventData ) { + for(var attr in {next:1,prev:1}) { + eventData.stepData[attr] = eventData.data[attr]; + } + }); + $jmpress( 'selectNext', function( step, eventData ) { + return selectPrevOrNext.call(this, step, eventData, "next"); + }); + $jmpress( 'selectPrev', function( step, eventData ) { + return selectPrevOrNext.call(this, step, eventData, "prev", true); + }); + +}(jQuery, document, window)); +/* + * ajax.js + * Load steps via ajax + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* DEFINES */ + var afterStepLoaded = 'ajax:afterStepLoaded', + loadStep = 'ajax:loadStep'; + + /* REGISTER EVENTS */ + $jmpress('register', loadStep); + $jmpress('register', afterStepLoaded); + + /* DEFAULTS */ + $jmpress('defaults').ajaxLoadedClass = "loaded"; + + /* HOOKS */ + $jmpress('initStep', function( step, eventData ) { + eventData.stepData.src = $(step).attr('href') || eventData.data.src || false; + eventData.stepData.srcLoaded = false; + }); + $jmpress(loadStep, function( step, eventData ) { + var stepData = eventData.stepData, + href = stepData && stepData.src, + settings = eventData.settings; + if ( href ) { + $(step).addClass( settings.ajaxLoadedClass ); + stepData.srcLoaded = true; + $(step).load(href, function(response, status, xhr) { + $(eventData.jmpress).jmpress('fire', afterStepLoaded, step, $.extend({}, eventData, { + response: response + ,status: status + ,xhr: xhr + })); + }); + } + }); + $jmpress('idle', function( step, eventData ) { + if (!step) { + return; + } + var settings = eventData.settings, + jmpress = $(this), + stepData = eventData.stepData; + var siblings = $(step) + .add( $(step).near( settings.stepSelector ) ) + .add( $(step).near( settings.stepSelector, true) ) + .add( jmpress.jmpress('fire', 'selectPrev', step, { + stepData: $(step).data('stepData') + })) + .add( jmpress.jmpress('fire', 'selectNext', step, { + stepData: $(step).data('stepData') + })); + siblings.each(function() { + var step = this, + stepData = $(step).data("stepData"); + if(!stepData.src || stepData.srcLoaded) { + return; + } + jmpress.jmpress('fire', loadStep, step, { + stepData: $(step).data('stepData') + }); + }); + }); + $jmpress("setActive", function(step, eventData) { + var stepData = $(step).data("stepData"); + if(!stepData.src || stepData.srcLoaded) { + return; + } + $(this).jmpress('fire', loadStep, step, { + stepData: $(step).data('stepData') + }); + }); + +}(jQuery, document, window)); +/* + * hash.js + * Detect and set the URL hash + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + hashLink = "a[href^=#]"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + /** + * getElementFromUrl + * + * @return String or undefined + */ + function getElementFromUrl(settings) { + // get id from url # by removing `#` or `#/` from the beginning, + // so both "fallback" `#slide-id` and "enhanced" `#/slide-id` will work + // TODO SECURITY check user input to be valid! + try { + var el = $( '#' + window.location.hash.replace(/^#\/?/,"") ); + return el.length > 0 && el.is(settings.stepSelector) ? el : undefined; + } catch(e) {} + } + function setHash(stepid) { + var shouldBeHash = "#/" + stepid; + if(window.history && window.history.pushState) { + // shouldBeHash = "#" + stepid; + // consider this for future versions + // it has currently issues, when startup with a link with hash (webkit) + if(window.location.hash !== shouldBeHash) { + window.history.pushState({}, '', shouldBeHash); + } + } else { + if(window.location.hash !== shouldBeHash) { + window.location.hash = shouldBeHash; + } + } + } + + /* DEFAULTS */ + $jmpress('defaults').hash = { + use: true + ,update: true + ,bindChange: true + // NOTICE: {use: true, update: false, bindChange: true} + // will cause a error after clicking on a link to the current step + }; + + /* HOOKS */ + $jmpress('selectInitialStep', function( step, eventData ) { + var settings = eventData.settings, + hashSettings = settings.hash, + current = eventData.current, + jmpress = $(this); + eventData.current.hashNamespace = ".jmpress-"+randomString(); + // HASH CHANGE EVENT + if ( hashSettings.use ) { + if ( hashSettings.bindChange ) { + $(window).bind('hashchange'+current.hashNamespace, function(event) { + var urlItem = getElementFromUrl(settings); + if ( jmpress.jmpress('initialized') ) { + jmpress.jmpress("scrollFix"); + } + if(urlItem && urlItem.length) { + if(urlItem.attr("id") !== jmpress.jmpress("active").attr("id")) { + jmpress.jmpress('select', urlItem); + } + setHash(urlItem.attr("id")); + } + event.preventDefault(); + }); + $(hashLink).on("click"+current.hashNamespace, function(event) { + var href = $(this).attr("href"); + try { + if($(href).is(settings.stepSelector)) { + jmpress.jmpress("select", href); + event.preventDefault(); + event.stopPropagation(); + } + } catch(e) {} + }); + } + return getElementFromUrl(settings); + } + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(hashLink).off(eventData.current.hashNamespace); + $(window).unbind(eventData.current.hashNamespace); + }); + $jmpress('setActive', function( step, eventData ) { + var settings = eventData.settings, + current = eventData.current; + // `#/step-id` is used instead of `#step-id` to prevent default browser + // scrolling to element in hash + if ( settings.hash.use && settings.hash.update ) { + clearTimeout(current.hashtimeout); + current.hashtimeout = setTimeout(function() { + setHash($(eventData.delegatedFrom).attr('id')); + }, settings.transitionDuration + 200); + } + }); + +}(jQuery, document, window)); +/* + * keyboard.js + * Keyboard event mapping and default keyboard actions + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + jmpressNext = "next", + jmpressPrev = "prev"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + function stopEvent(event) { + event.preventDefault(); + event.stopPropagation(); + } + + /* DEFAULTS */ + $jmpress('defaults').keyboard = { + use: true + ,keys: { + 33: jmpressPrev // pg up + ,37: jmpressPrev // left + ,38: jmpressPrev // up + + ,9: jmpressNext+":"+jmpressPrev // tab + ,32: jmpressNext // space + ,34: jmpressNext // pg down + ,39: jmpressNext // right + ,40: jmpressNext // down + + ,36: "home" // home + + ,35: "end" // end + } + ,ignore: { + "INPUT": [ + 32 // space + ,37 // left + ,38 // up + ,39 // right + ,40 // down + ] + ,"TEXTAREA": [ + 32 // space + ,37 // left + ,38 // up + ,39 // right + ,40 // down + ] + ,"SELECT": [ + 38 // up + ,40 // down + ] + } + ,tabSelector: "a[href]:visible, :input:visible" + }; + + /* HOOKS */ + $jmpress('afterInit', function( nil, eventData ) { + var settings = eventData.settings, + keyboardSettings = settings.keyboard, + ignoreKeyboardSettings = keyboardSettings.ignore, + current = eventData.current, + jmpress = $(this); + + // tabindex make it focusable so that it can recieve key events + if(!settings.fullscreen) { + jmpress.attr("tabindex", 0); + } + + current.keyboardNamespace = ".jmpress-"+randomString(); + + // KEYPRESS EVENT: this fixes a Opera bug + $(settings.fullscreen ? document : jmpress) + .bind("keypress"+current.keyboardNamespace, function( event ) { + + for( var nodeName in ignoreKeyboardSettings ) { + if ( event.target.nodeName === nodeName && ignoreKeyboardSettings[nodeName].indexOf(event.which) !== -1 ) { + return; + } + } + if(event.which >= 37 && event.which <= 40 || event.which === 32) { + stopEvent(event); + } + }); + // KEYDOWN EVENT + $(settings.fullscreen ? document : jmpress) + .bind("keydown"+current.keyboardNamespace, function( event ) { + var eventTarget = $(event.target); + + if ( !settings.fullscreen && !eventTarget.closest(jmpress).length || !keyboardSettings.use ) { + return; + } + + for( var nodeName in ignoreKeyboardSettings ) { + if ( eventTarget[0].nodeName === nodeName && ignoreKeyboardSettings[nodeName].indexOf(event.which) !== -1 ) { + return; + } + } + + var reverseSelect = false; + var nextFocus; + if (event.which === 9) { + // tab + if ( !eventTarget.closest( jmpress.jmpress('active') ).length ) { + if ( !event.shiftKey ) { + nextFocus = jmpress.jmpress('active').find("a[href], :input").filter(":visible").first(); + } else { + reverseSelect = true; + } + } else { + nextFocus = eventTarget.near( keyboardSettings.tabSelector, event.shiftKey ); + if( !$(nextFocus) + .closest( settings.stepSelector ) + .is(jmpress.jmpress('active') ) ) { + nextFocus = undefined; + } + } + if( nextFocus && nextFocus.length > 0 ) { + nextFocus.focus(); + jmpress.jmpress("scrollFix"); + stopEvent(event); + return; + } else { + if(event.shiftKey) { + reverseSelect = true; + } + } + } + + var action = keyboardSettings.keys[ event.which ]; + if ( typeof action === "string" ) { + if (action.indexOf(":") !== -1) { + action = action.split(":"); + action = event.shiftKey ? action[1] : action[0]; + } + jmpress.jmpress( action ); + stopEvent(event); + } else if ( $.isFunction(action) ) { + action.call(jmpress, event); + } else if ( action ) { + jmpress.jmpress.apply( jmpress, action ); + stopEvent(event); + } + + if (reverseSelect) { + // tab + nextFocus = jmpress.jmpress('active').find("a[href], :input").filter(":visible").last(); + nextFocus.focus(); + jmpress.jmpress("scrollFix"); + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(document).unbind(eventData.current.keyboardNamespace); + }); + + +}(jQuery, document, window)); +/* + * viewport.js + * Scale to fit a given viewport + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + var browser = (function() { + var ua = navigator.userAgent.toLowerCase(); + var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || + /(webkit)[ \/]([\w.]+)/.exec(ua) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || + /(msie) ([\w.]+)/.exec(ua) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || + []; + return match[1] || ""; + }()); + + var defaults = $.jmpress("defaults"); + defaults.viewPort = { + width: false + ,height: false + ,maxScale: 0 + ,minScale: 0 + ,zoomable: 0 + ,zoomBindMove: true + ,zoomBindWheel: true + }; + var keys = defaults.keyboard.keys; + keys[browser === 'mozilla' ? 107 : 187] = "zoomIn"; // + + keys[browser === 'mozilla' ? 109 : 189] = "zoomOut"; // - + defaults.reasonableAnimation.resize = { + transitionDuration: '0s' + ,transitionDelay: '0ms' + }; + defaults.reasonableAnimation.zoom = { + transitionDuration: '0s' + ,transitionDelay: '0ms' + }; + $.jmpress("initStep", function( step, eventData ) { + for(var variable in {"viewPortHeight":1, "viewPortWidth":1, "viewPortMinScale":1, "viewPortMaxScale":1, "viewPortZoomable":1}) { + eventData.stepData[variable] = eventData.data[variable] && parseFloat(eventData.data[variable]); + } + }); + $.jmpress("afterInit", function( nil, eventData ) { + var jmpress = this; + eventData.current.viewPortNamespace = ".jmpress-"+randomString(); + $(window).bind("resize"+eventData.current.viewPortNamespace, function (event) { + $(jmpress).jmpress("reselect", "resize"); + }); + eventData.current.userZoom = 0; + eventData.current.userTranslateX = 0; + eventData.current.userTranslateY = 0; + if(eventData.settings.viewPort.zoomBindWheel) { + $(eventData.settings.fullscreen ? document : this) + .bind("mousewheel"+eventData.current.viewPortNamespace+" DOMMouseScroll"+eventData.current.viewPortNamespace, function( event, delta ) { + delta = delta || event.originalEvent.wheelDelta || -event.originalEvent.detail /* mozilla */; + var direction = (delta / Math.abs(delta)); + if(direction < 0) { + $(eventData.jmpress).jmpress("zoomOut", event.originalEvent.clientX, event.originalEvent.clientY); + } else if(direction > 0) { + $(eventData.jmpress).jmpress("zoomIn", event.originalEvent.clientX, event.originalEvent.clientY); + } + return false; + }); + } + if(eventData.settings.viewPort.zoomBindMove) { + $(eventData.settings.fullscreen ? document : this).bind("mousedown"+eventData.current.viewPortNamespace, function (event) { + if(eventData.current.userZoom) { + eventData.current.userTranslating = { x: event.clientX, y: event.clientY }; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }).bind("mousemove"+eventData.current.viewPortNamespace, function (event) { + var userTranslating = eventData.current.userTranslating; + if(userTranslating) { + $(jmpress).jmpress("zoomTranslate", event.clientX - userTranslating.x, event.clientY - userTranslating.y); + userTranslating.x = event.clientX; + userTranslating.y = event.clientY; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }).bind("mouseup"+eventData.current.viewPortNamespace, function (event) { + if(eventData.current.userTranslating) { + eventData.current.userTranslating = undefined; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }); + } + }); + function maxAbs(value, range) { + return Math.max(Math.min(value, range), -range); + } + function zoom(x, y, direction) { + var current = $(this).jmpress("current"), + settings = $(this).jmpress("settings"), + stepData = $(this).jmpress("active").data("stepData"), + container = $(this).jmpress("container"); + if(current.userZoom === 0 && direction < 0) { + return; + } + var zoomableSteps = stepData.viewPortZoomable || settings.viewPort.zoomable; + if(current.userZoom === zoomableSteps && direction > 0) { + return; + } + current.userZoom += direction; + + var halfWidth = $(container).innerWidth()/2, + halfHeight = $(container).innerHeight()/2; + + x = x ? x - halfWidth : x; + y = y ? y - halfHeight : y; + + // TODO this is not perfect... too much math... :( + current.userTranslateX = + maxAbs(current.userTranslateX - direction * x / current.zoomOriginWindowScale / zoomableSteps, + halfWidth * current.userZoom * current.userZoom / zoomableSteps); + current.userTranslateY = + maxAbs(current.userTranslateY - direction * y / current.zoomOriginWindowScale / zoomableSteps, + halfHeight * current.userZoom * current.userZoom / zoomableSteps); + + $(this).jmpress("reselect", "zoom"); + } + $.jmpress("register", "zoomIn", function(x, y) { + zoom.call(this, x||0, y||0, 1); + }); + $.jmpress("register", "zoomOut", function(x, y) { + zoom.call(this, x||0, y||0, -1); + }); + $.jmpress("register", "zoomTranslate", function(x, y) { + var current = $(this).jmpress("current"), + settings = $(this).jmpress("settings"), + stepData = $(this).jmpress("active").data("stepData"), + container = $(this).jmpress("container"); + var zoomableSteps = stepData.viewPortZoomable || settings.viewPort.zoomable; + var halfWidth = $(container).innerWidth(), + halfHeight = $(container).innerHeight(); + current.userTranslateX = + maxAbs(current.userTranslateX + x / current.zoomOriginWindowScale, + halfWidth * current.userZoom * current.userZoom / zoomableSteps); + current.userTranslateY = + maxAbs(current.userTranslateY + y / current.zoomOriginWindowScale, + halfHeight * current.userZoom * current.userZoom / zoomableSteps); + $(this).jmpress("reselect", "zoom"); + }); + $.jmpress('afterDeinit', function( nil, eventData ) { + $(eventData.settings.fullscreen ? document : this).unbind(eventData.current.viewPortNamespace); + $(window).unbind(eventData.current.viewPortNamespace); + }); + $.jmpress("setActive", function( step, eventData ) { + var viewPort = eventData.settings.viewPort; + var viewPortHeight = eventData.stepData.viewPortHeight || viewPort.height; + var viewPortWidth = eventData.stepData.viewPortWidth || viewPort.width; + var viewPortMaxScale = eventData.stepData.viewPortMaxScale || viewPort.maxScale; + var viewPortMinScale = eventData.stepData.viewPortMinScale || viewPort.minScale; + // Correct the scale based on the window's size + var windowScaleY = viewPortHeight && $(eventData.container).innerHeight()/viewPortHeight; + var windowScaleX = viewPortWidth && $(eventData.container).innerWidth()/viewPortWidth; + var windowScale = (windowScaleX || windowScaleY) && Math.min( windowScaleX || windowScaleY, windowScaleY || windowScaleX ); + + if(windowScale) { + windowScale = windowScale || 1; + if(viewPortMaxScale) { + windowScale = Math.min(windowScale, viewPortMaxScale); + } + if(viewPortMinScale) { + windowScale = Math.max(windowScale, viewPortMinScale); + } + + var zoomableSteps = eventData.stepData.viewPortZoomable || eventData.settings.viewPort.zoomable; + if(zoomableSteps) { + var diff = (1/windowScale) - (1/viewPortMaxScale); + diff /= zoomableSteps; + windowScale = 1/((1/windowScale) - diff * eventData.current.userZoom); + } + + eventData.target.transform.reverse(); + if(eventData.current.userTranslateX && eventData.current.userTranslateY) { + eventData.target.transform.push(["translate", eventData.current.userTranslateX, eventData.current.userTranslateY, 0]); + } else { + eventData.target.transform.push(["translate"]); + } + eventData.target.transform.push(["scale", + windowScale, + windowScale, + 1]); + eventData.target.transform.reverse(); + eventData.target.perspectiveScale /= windowScale; + } + eventData.current.zoomOriginWindowScale = windowScale; + }); + $.jmpress("setInactive", function( step, eventData ) { + if(!eventData.nextStep || !step || $(eventData.nextStep).attr("id") !== $(step).attr("id")) { + eventData.current.userZoom = 0; + eventData.current.userTranslateX = 0; + eventData.current.userTranslateY = 0; + } + }); + +}(jQuery, document, window)); + +/* + * mouse.js + * Clicking to select a step + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* DEFAULTS */ + $jmpress("defaults").mouse = { + clickSelects: true + }; + + /* HOOKS */ + $jmpress("afterInit", function( nil, eventData ) { + var settings = eventData.settings, + stepSelector = settings.stepSelector, + current = eventData.current, + jmpress = $(this); + current.clickableStepsNamespace = ".jmpress-"+randomString(); + jmpress.bind("click"+current.clickableStepsNamespace, function(event) { + if (!settings.mouse.clickSelects || current.userZoom) { + return; + } + + // get clicked step + var clickedStep = $(event.target).closest(stepSelector); + + // clicks on the active step do default + if ( clickedStep.is( jmpress.jmpress("active") ) ) { + return; + } + + if (clickedStep.length) { + // select the clicked step + jmpress.jmpress("select", clickedStep[0], "click"); + event.preventDefault(); + event.stopPropagation(); + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(this).unbind(eventData.current.clickableStepsNamespace); + }); + +}(jQuery, document, window)); +/* + * mobile.js + * Adds support for swipe on touch supported browsers + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* HOOKS */ + $jmpress( 'afterInit', function( step, eventData ) { + var settings = eventData.settings, + current = eventData.current, + jmpress = eventData.jmpress; + current.mobileNamespace = ".jmpress-"+randomString(); + var data, start = [0,0]; + $(settings.fullscreen ? document : jmpress) + .bind("touchstart"+current.mobileNamespace, function( event ) { + + data = event.originalEvent.touches[0]; + start = [ data.pageX, data.pageY ]; + + }).bind("touchmove"+current.mobileNamespace, function( event ) { + data = event.originalEvent.touches[0]; + event.preventDefault(); + return false; + }).bind("touchend"+current.mobileNamespace, function( event ) { + var end = [ data.pageX, data.pageY ], + diff = [ end[0]-start[0], end[1]-start[1] ]; + + if(Math.max(Math.abs(diff[0]), Math.abs(diff[1])) > 50) { + diff = Math.abs(diff[0]) > Math.abs(diff[1]) ? diff[0] : diff[1]; + $(jmpress).jmpress(diff > 0 ? "prev" : "next"); + event.preventDefault(); + return false; + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + var settings = eventData.settings, + current = eventData.current, + jmpress = eventData.jmpress; + $(settings.fullscreen ? document : jmpress).unbind(current.mobileNamespace); + }); + +}(jQuery, document, window)); +/* + * templates.js + * The amazing template engine + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + templateFromParentIdent = "_template_", + templateFromApplyIdent = "_applied_template_"; + + /* STATIC VARS */ + var templates = {}; + + /* FUNCTIONS */ + function addUndefined( target, values, prefix ) { + for( var name in values ) { + var targetName = name; + if ( prefix ) { + targetName = prefix + targetName.substr(0, 1).toUpperCase() + targetName.substr(1); + } + if ( $.isPlainObject(values[name]) ) { + addUndefined( target, values[name], targetName ); + } else if( target[targetName] === undefined ) { + target[targetName] = values[name]; + } + } + } + function applyChildrenTemplates( children, templateChildren ) { + if ($.isArray(templateChildren)) { + if (templateChildren.length < children.length) { + $.error("more nested steps than children in template"); + } else { + children.each(function(idx, child) { + child = $(child); + var tmpl = child.data(templateFromParentIdent) || {}; + addUndefined(tmpl, templateChildren[idx]); + child.data(templateFromParentIdent, tmpl); + }); + } + } else if($.isFunction(templateChildren)) { + children.each(function(idx, child) { + child = $(child); + var tmpl = child.data(templateFromParentIdent) || {}; + addUndefined(tmpl, templateChildren(idx, child, children)); + child.data(templateFromParentIdent, tmpl); + }); + } // TODO: else if(object) + } + function applyTemplate( data, element, template, eventData ) { + if (template.children) { + var children = element.children( eventData.settings.stepSelector ); + applyChildrenTemplates( children, template.children ); + } + applyTemplateData( data, template ); + } + function applyTemplateData( data, template ) { + addUndefined(data, template); + } + + /* HOOKS */ + $jmpress("beforeInitStep", function( step, eventData ) { + step = $(step); + var data = eventData.data, + templateFromAttr = data.template, + templateFromApply = step.data(templateFromApplyIdent), + templateFromParent = step.data(templateFromParentIdent); + if(templateFromAttr) { + $.each(templateFromAttr.split(" "), function(idx, tmpl) { + var template = templates[tmpl]; + applyTemplate( data, step, template, eventData ); + }); + } + if (templateFromApply) { + applyTemplate( data, step, templateFromApply, eventData ); + } + if (templateFromParent) { + applyTemplate( data, step, templateFromParent, eventData ); + step.data(templateFromParentIdent, null); + if(templateFromParent.template) { + $.each(templateFromParent.template.split(" "), function(idx, tmpl) { + var template = templates[tmpl]; + applyTemplate( data, step, template, eventData ); + }); + } + } + }); + $jmpress("beforeInit", function( nil, eventData ) { + var data = $jmpress("dataset", this), + dataTemplate = data.template, + stepSelector = eventData.settings.stepSelector; + if (dataTemplate) { + var template = templates[dataTemplate]; + applyChildrenTemplates( $(this).find(stepSelector).filter(function() { + return !$(this).parent().is(stepSelector); + }), template.children ); + } + }); + + /* EXPORTED FUNCTIONS */ + $jmpress("register", "template", function( name, tmpl ) { + if (templates[name]) { + templates[name] = $.extend(true, {}, templates[name], tmpl); + } else { + templates[name] = $.extend(true, {}, tmpl); + } + }); + $jmpress("register", "apply", function( selector, tmpl ) { + if( !tmpl ) { + // TODO ERROR because settings not found + var stepSelector = $(this).jmpress("settings").stepSelector; + applyChildrenTemplates( $(this).find(stepSelector).filter(function() { + return !$(this).parent().is(stepSelector); + }), selector ); + } else if($.isArray(tmpl)) { + applyChildrenTemplates( $(selector), tmpl ); + } else { + var template; + if(typeof tmpl === "string") { + template = templates[tmpl]; + } else { + template = $.extend(true, {}, tmpl); + } + $(selector).each(function(idx, element) { + element = $(element); + var tmpl = element.data(templateFromApplyIdent) || {}; + addUndefined(tmpl, template); + element.data(templateFromApplyIdent, tmpl); + }); + } + }); + +}(jQuery, document, window)); +/* + * jqevents.js + * Fires jQuery events + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* HOOKS */ + // the events should not bubble up the tree + // elsewise nested jmpress would cause buggy behavior + $.jmpress("setActive", function( step, eventData ) { + if(eventData.prevStep !== step) { + $(step).triggerHandler("enterStep"); + } + }); + $.jmpress("setInactive", function( step, eventData ) { + if(eventData.nextStep !== step) { + $(step).triggerHandler("leaveStep"); + } + }); + +}(jQuery, document, window)); +/* + * animation.js + * Apply custom animations to steps + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + function parseSubstepInfo(str) { + var arr = str.split(" "); + var className = arr[0]; + var config = { willClass: "will-"+className, doClass: "do-"+className, hasClass: "has-"+className }; + var state = ""; + for(var i = 1; i < arr.length; i++) { + var s = arr[i]; + switch(state) { + case "": + if(s === "after") { + state = "after"; + } else { + $.warn("unknown keyword in '"+str+"'. '"+s+"' unknown."); + } + break; + case "after": + if(s.match(/^[1-9][0-9]*m?s?/)) { + var value = parseFloat(s); + if(s.indexOf("ms") !== -1) { + value *= 1; + } else if(s.indexOf("s") !== -1) { + value *= 1000; + } else if(s.indexOf("m") !== -1) { + value *= 60000; + } + config.delay = value; + } else { + config.after = Array.prototype.slice.call(arr, i).join(" "); + i = arr.length; + } + } + } + return config; + } + function find(array, selector, start, end) { + end = end || (array.length - 1); + start = start || 0; + for(var i = start; i < end + 1; i++) { + if($(array[i].element).is(selector)) { + return i; + } + } + } + function addOn(list, substep, delay) { + $.each(substep._on, function(idx, child) { + list.push({substep: child.substep, delay: child.delay + delay}); + addOn(list, child.substep, child.delay + delay); + }); + } + $.jmpress("defaults").customAnimationDataAttribute = "jmpress"; + $.jmpress("afterInit", function( nil, eventData ) { + eventData.current.animationTimeouts = []; + eventData.current.animationCleanupWaiting = []; + }); + $.jmpress("applyStep", function( step, eventData ) { + // read custom animation from elements + var substepsData = {}; + var listOfSubsteps = []; + $(step).find("[data-"+eventData.settings.customAnimationDataAttribute+"]") + .each(function(idx, element) { + if($(element).closest(eventData.settings.stepSelector).is(step)) { + listOfSubsteps.push({element: element}); + } + }); + if(listOfSubsteps.length === 0) { + return; + } + $.each(listOfSubsteps, function(idx, substep) { + substep.info = parseSubstepInfo( + $(substep.element).data(eventData.settings.customAnimationDataAttribute)); + $(substep.element).addClass(substep.info.willClass); + substep._on = []; + substep._after = null; + }); + var current = {_after: undefined, _on: [], info: {}}; // virtual zero step + $.each(listOfSubsteps, function(idx, substep) { + var other = substep.info.after; + if(other) { + if(other === "step") { + other = current; + } else if(other === "prev") { + other = listOfSubsteps[idx-1]; + } else { + var index = find(listOfSubsteps, other, 0, idx - 1); + if(index === undefined) { + index = find(listOfSubsteps, other); + } + other = (index === undefined || index === idx) ? listOfSubsteps[idx-1] : listOfSubsteps[index]; + } + } else { + other = listOfSubsteps[idx-1]; + } + if(other) { + if(!substep.info.delay) { + if(!other._after) { + other._after = substep; + return; + } + other = other._after; + } + other._on.push({substep: substep, delay: substep.info.delay || 0}); + } + }); + if(current._after === undefined && current._on.length === 0) { + var startStep = find(listOfSubsteps, eventData.stepData.startSubstep) || 0; + current._after = listOfSubsteps[startStep]; + } + var substepsInOrder = []; + function findNextFunc(idx, item) { + if(item.substep._after) { + current = item.substep._after; + return false; + } + } + do { + var substepList = [{substep: current, delay: 0}]; + addOn(substepList, current, 0); + substepsInOrder.push(substepList); + current = null; + $.each(substepList, findNextFunc); + } while(current); + substepsData.list = substepsInOrder; + $(step).data("substepsData", substepsData); + }); + $.jmpress("unapplyStep", function( step, eventData ) { + var substepsData = $(step).data("substepsData"); + if(substepsData) { + $.each(substepsData.list, function(idx, activeSubsteps) { + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.willClass) { + $(substep.substep.element).removeClass(substep.substep.info.willClass); + } + if(substep.substep.info.hasClass) { + $(substep.substep.element).removeClass(substep.substep.info.hasClass); + } + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + } + }); + }); + } + }); + $.jmpress("setActive", function(step, eventData) { + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep === undefined) { + eventData.substep = + (eventData.reason === "prev" ? + substepsData.list.length-1 : + 0 + ); + } + var substep = eventData.substep; + $.each(eventData.current.animationTimeouts, function(idx, timeout) { + clearTimeout(timeout); + }); + eventData.current.animationTimeouts = []; + $.each(substepsData.list, function(idx, activeSubsteps) { + var applyHas = idx < substep; + var applyDo = idx <= substep; + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.hasClass) { + $(substep.substep.element)[(applyHas?"add":"remove")+"Class"](substep.substep.info.hasClass); + } + function applyIt() { + $(substep.substep.element).addClass(substep.substep.info.doClass); + } + if(applyDo && !applyHas && substep.delay && eventData.reason !== "prev") { + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + eventData.current.animationTimeouts.push(setTimeout(applyIt, substep.delay)); + } + } else { + if(substep.substep.info.doClass) { + $(substep.substep.element)[(applyDo?"add":"remove")+"Class"](substep.substep.info.doClass); + } + } + }); + }); + }); + $.jmpress("setInactive", function(step, eventData) { + if(eventData.nextStep === step) { + return; + } + function cleanupAnimation( substepsData ) { + $.each(substepsData.list, function(idx, activeSubsteps) { + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.hasClass) { + $(substep.substep.element).removeClass(substep.substep.info.hasClass); + } + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + } + }); + }); + } + $.each(eventData.current.animationCleanupWaiting, function(idx, item) { + cleanupAnimation(item); + }); + eventData.current.animationCleanupWaiting = []; + var substepsData = $(step).data("substepsData"); + if(substepsData) { + eventData.current.animationCleanupWaiting.push( substepsData ); + } + }); + $.jmpress("selectNext", function( step, eventData ) { + if(eventData.substep === undefined) { + return; + } + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep < substepsData.list.length-1) { + return {step: step, substep: eventData.substep+1}; + } + }); + $.jmpress("selectPrev", function( step, eventData ) { + if(eventData.substep === undefined) { + return; + } + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep > 0) { + return {step: step, substep: eventData.substep-1}; + } + }); + +}(jQuery, document, window)); +/* + * jmpress.toggle plugin + * For binding a key to toggle de/initialization of jmpress.js. + */ +(function( $, document, window, undefined ) { + 'use strict'; + $.jmpress("register", "toggle", function( key, config, initial ) { + var jmpress = this; + $(document).bind("keydown", function( event ) { + if ( event.keyCode === key ) { + if ($(jmpress).jmpress("initialized")) { + $(jmpress).jmpress("deinit"); + } else { + $(jmpress).jmpress(config); + } + } + }); + if ( initial ) { + $(jmpress).jmpress(config); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.secondary plugin + * Apply a secondary animation when step is selected. + */ +(function( $, document, window, undefined ) { + 'use strict'; + $.jmpress("initStep", function( step, eventData ) { + for(var name in eventData.data) { + if(name.indexOf("secondary") === 0) { + eventData.stepData[name] = eventData.data[name]; + } + } + }); + function exchangeIf(childStepData, condition, step) { + if(childStepData.secondary && + childStepData.secondary.split(" ").indexOf(condition) !== -1) { + for(var name in childStepData) { + if(name.length > 9 && name.indexOf("secondary") === 0) { + var tmp = childStepData[name]; + var normal = name.substr(9); + normal = normal.substr(0, 1).toLowerCase() + normal.substr(1); + childStepData[name] = childStepData[normal]; + childStepData[normal] = tmp; + } + } + $(this).jmpress("reapply", $(step)); + } + } + $.jmpress("beforeActive", function( step, eventData ) { + exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step); + var parent = $(step).parent(); + $(parent) + .children(eventData.settings.stepSelector) + .each(function(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "siblings", child); + }); + function grandchildrenFunc(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child); + } + for(var i = 1; i < eventData.parents.length; i++) { + $(eventData.parents[i]) + .children(eventData.settings.stepSelector) + .each(); + } + }); + $.jmpress("setInactive", function( step, eventData ) { + exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step); + var parent = $(step).parent(); + $(parent) + .children(eventData.settings.stepSelector) + .each(function(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "siblings", child); + }); + function grandchildrenFunc(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child); + } + for(var i = 1; i < eventData.parents.length; i++) { + $(eventData.parents[i]) + .children(eventData.settings.stepSelector) + .each(grandchildrenFunc); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.duration plugin + * For auto advancing steps after a given duration and optionally displaying a + * progress bar. + */ +(function( $, document, window, undefined ) { + 'use strict'; + + $.jmpress("defaults").duration = { + defaultValue: -1 + ,defaultAction: "next" + ,barSelector: undefined + ,barProperty: "width" + ,barPropertyStart: "0" + ,barPropertyEnd: "100%" + }; + $.jmpress("initStep", function( step, eventData ) { + eventData.stepData.duration = eventData.data.duration && parseInt(eventData.data.duration, 10); + eventData.stepData.durationAction = eventData.data.durationAction; + }); + $.jmpress("setInactive", function( step, eventData ) { + var settings = eventData.settings, + durationSettings = settings.duration, + current = eventData.current; + var dur = eventData.stepData.duration || durationSettings.defaultValue; + if( current.durationTimeout ) { + if( durationSettings.barSelector ) { + var css = { + transitionProperty: durationSettings.barProperty + ,transitionDuration: '0' + ,transitionDelay: '0' + ,transitionTimingFunction: 'linear' + }; + css[durationSettings.barProperty] = durationSettings.barPropertyStart; + var bars = $(durationSettings.barSelector); + $.jmpress("css", bars, css); + bars.each(function(idx, element) { + var next = $(element).next(); + var parent = $(element).parent(); + $(element).detach(); + if(next.length) { + next.insertBefore(element); + } else { + parent.append(element); + } + }); + } + clearTimeout(current.durationTimeout); + delete current.durationTimeout; + } + }); + $.jmpress("setActive", function( step, eventData ) { + var settings = eventData.settings, + durationSettings = settings.duration, + current = eventData.current; + var dur = eventData.stepData.duration || durationSettings.defaultValue; + if( dur && dur > 0 ) { + if( durationSettings.barSelector ) { + var css = { + transitionProperty: durationSettings.barProperty + ,transitionDuration: (dur-settings.transitionDuration*2/3-100)+"ms" + ,transitionDelay: (settings.transitionDuration*2/3)+'ms' + ,transitionTimingFunction: 'linear' + }; + css[durationSettings.barProperty] = durationSettings.barPropertyEnd; + $.jmpress("css", $(durationSettings.barSelector), css); + } + var jmpress = this; + if(current.durationTimeout) { + clearTimeout(current.durationTimeout); + current.durationTimeout = undefined; + } + current.durationTimeout = setTimeout(function() { + var action = eventData.stepData.durationAction || durationSettings.defaultAction; + $(jmpress).jmpress(action); + }, dur); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.presentation-mode plugin + * Display a window for the presenter with notes and a control and view of the + * presentation + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + var PREFIX = "jmpress-presentation-"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* DEFAULTS */ + $jmpress("defaults").presentationMode = { + use: true, + url: "presentation-screen.html", + notesUrl: false, + transferredValues: ["userZoom", "userTranslateX", "userTranslateY"] + }; + $jmpress("defaults").keyboard.keys[80] = "presentationPopup"; // p key + + /* HOOKS */ + $jmpress("afterInit", function( nil, eventData) { + var current = eventData.current; + + current.selectMessageListeners = []; + + if(eventData.settings.presentationMode.use) { + + window.addEventListener("message", function(event) { + // We do not test orgin, because we want to accept messages + // from all orgins + try { + if(typeof event.data !== "string" || event.data.indexOf(PREFIX) !== 0) { + return; + } + var json = JSON.parse(event.data.slice(PREFIX.length)); + switch(json.type) { + case "select": + $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) { + eventData.current[name] = json[name]; + }); + if(/[a-z0-9\-]+/i.test(json.targetId) && typeof json.substep in {number:1,undefined:1}) { + $(eventData.jmpress).jmpress("select", {step: "#"+json.targetId, substep: json.substep}, json.reason); + } else { + $.error("For security reasons the targetId must match /[a-z0-9\\-]+/i and substep must be a number."); + } + break; + case "listen": + current.selectMessageListeners.push(event.source); + break; + case "ok": + clearTimeout(current.presentationPopupTimeout); + break; + case "read": + try { + event.source.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: eventData.settings.presentationMode.notesUrl}), "*"); + } catch(e) { + $.error("Cannot post message to source: " + e); + } + break; + default: + throw "Unknown message type: " + json.type; + } + } catch(e) { + $.error("Received message is malformed: " + e); + } + }); + try { + if(window.parent && window.parent !== window) { + window.parent.postMessage(PREFIX + JSON.stringify({ + "type": "afterInit" + }), "*"); + } + } catch(e) { + $.error("Cannot post message to parent: " + e); + } + } + }); + $jmpress("afterDeinit", function( nil, eventData) { + if(eventData.settings.presentationMode.use) { + try { + if(window.parent && window.parent !== window) { + window.parent.postMessage(PREFIX + JSON.stringify({ + "type": "afterDeinit" + }), "*"); + } + } catch(e) { + $.error("Cannot post message to parent: " + e); + } + } + }); + $jmpress("setActive", function( step, eventData) { + var stepId = $(eventData.delegatedFrom).attr("id"), + substep = eventData.substep, + reason = eventData.reason; + $.each(eventData.current.selectMessageListeners, function(idx, listener) { + try { + var msg = { + "type": "select", + "targetId": stepId, + "substep": substep, + "reason": reason + }; + $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) { + msg[name] = eventData.current[name]; + }); + listener.postMessage(PREFIX + JSON.stringify(msg), "*"); + } catch(e) { + $.error("Cannot post message to listener: " + e); + } + }); + }); + $jmpress("register", "presentationPopup", function() { + function trySend() { + jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100); + try { + popup.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: jmpress.jmpress("settings").presentationMode.notesUrl}), "*"); + } catch(e) { + } + } + var jmpress = $(this), + popup; + if(jmpress.jmpress("settings").presentationMode.use) { + popup = window.open($(this).jmpress("settings").presentationMode.url); + jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100); + } + }); +}(jQuery, document, window)); diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d177155..ebf2870 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -19,6 +19,11 @@ class HomeController < ApplicationController end def dev + end + def infoscreen + authorize! :doadmin, User + @neuigkeiten = Neuigkeit.accessible_by(current_ability, :show).limit(10) + render layout: false end def kontakt t=YAML.load_file("#{::Rails.root.to_s}/config/contact_topic.yml") diff --git a/app/views/home/infoscreen.html.erb b/app/views/home/infoscreen.html.erb new file mode 100644 index 0000000..d1ce481 --- /dev/null +++ b/app/views/home/infoscreen.html.erb @@ -0,0 +1,53 @@ + + + + <%= stylesheet_link_tag "themes/"+theme_name+"/application", :media => "all" unless theme_name.empty? %> + <%= stylesheet_link_tag "application", :media=>"all" if theme_name.empty? %> + + <%= javascript_include_tag "application" %> + <%= javascript_include_tag "jmpress" %> + + + +
    +<% i=1 %> +<% @neuigkeiten.each do |n| %> + +
    <% @toolbar_elements=[];@questions=[] %> +
    + <% unless n.picture_robust.big_thumb.to_s.empty? %> +
    +


    <%= link_to image_tag(n.picture_robust.big_thumb),n.picture_robust.try(:url) %> +

    +
    + <% end %> +
    +

    + <%= raw(n.title) %> <%#= link_to fa_icon("edit"), edit_rubrik_neuigkeit_path(n.rubrik, n), remote: true if can? :edit, n %> +

    +
    + <%= raw(n.text) %> + <% if n.has_calentries? %> +
    + <%= fa_icon("calendar 2x") %> + <%= n.relevant_calentry.text %> +
    +<% end %> +
    +
    +
    + + + + +
    +<% i = i+1 %> +<% end %> +
    + + + diff --git a/app/views/neuigkeiten/_neuigkeit_view.html.erb b/app/views/neuigkeiten/_neuigkeit_view.html.erb index f29e612..3d9a78e 100644 --- a/app/views/neuigkeiten/_neuigkeit_view.html.erb +++ b/app/views/neuigkeiten/_neuigkeit_view.html.erb @@ -16,7 +16,7 @@ <% end %>
    <% unless neuigkeit_view.published? %> -
    Not Published <%= link_to "Publish", publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),remote:true, class: :btn if can? :publish, neuigkeit_view %>
    +
    Not Published <%= link_to "Publish", publish_rubrik_neuigkeit_path(neuigkeit_view.rubrik,neuigkeit_view),remote:true, class: :btn if can? :publish, neuigkeit_view %>
    <% end %> <% unless neuigkeit_view.origurl.nil? || neuigkeit_view.origurl.empty? %>
    <%= link_to "Zitiert von "+ neuigkeit_view.origurl, neuigkeit_view.origurl %> diff --git a/app/views/themes/blue2/neuigkeiten/_menu.html.erb b/app/views/themes/blue2/neuigkeiten/_menu.html.erb index a0b1f9d..0b666b5 100644 --- a/app/views/themes/blue2/neuigkeiten/_menu.html.erb +++ b/app/views/themes/blue2/neuigkeiten/_menu.html.erb @@ -1,40 +1,40 @@
    - <%= link_to(fa_icon("edit"), edit_rubrik_neuigkeit_path( @neuigkeit.rubrik, @neuigkeit), remote: true , class: "btn", title: "Edit") if can? :edit, @neuigkeit + <%= link_to(fa_icon("edit"), edit_rubrik_neuigkeit_path( menu.rubrik, menu), remote: true , class: "btn", title: "Edit") if can? :edit, menu %> - <%= link_to(fa_icon("paperclip"), "#", class: "btn", id: "attachments-form-open", title: "Attachments") if can? :edit, @neuigkeit + <%= link_to(fa_icon("paperclip"), "#", class: "btn", id: "attachments-form-open", title: "Attachments") if can? :edit, menu %> - <%= link_to(fa_icon("calendar-o"), new_calentry_path(:object_id=>@neuigkeit.id, :object_type=>"Neuigkeit"), :remote=>true, class: :btn) if can? :edit, @neuigkeit + <%= link_to(fa_icon("calendar-o"), new_calentry_path(:object_id=>menu.id, :object_type=>"Neuigkeit"), :remote=>true, class: :btn) if can? :edit, menu %> - <%= link_to(fa_icon("link") , "#", id: "findlink-open",title: "Neue Verknüpfung" , class: "btn") if can? :find_link, @neuigkeit + <%= link_to(fa_icon("link") , "#", id: "findlink-open",title: "Neue Verknüpfung" , class: "btn") if can? :find_link, menu %> - <%= new_question_for(@neuigkeit, fa_icon("question")) if can? :new, Survey::Question %> + <%= new_question_for(menu, fa_icon("question")) if can? :new, Survey::Question %> - <%= link_to(fa_icon("globe"), publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), title: I18n.t('neuigkeit.publish'), class: "btn") if can?(:publish, @neuigkeit) && !@neuigkeit.published? + <%= link_to(fa_icon("globe"), publish_rubrik_neuigkeit_path(menu.rubrik,menu), title: I18n.t('neuigkeit.publish'), class: "btn") if can?(:publish, menu) && !menu.published? %> - <%= link_to(fa_stack("globe","ban"), unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :remote=>true, class: "btn stacked") if can?(:unpublish, @neuigkeit) && @neuigkeit.published? + <%= link_to(fa_stack("globe","ban"), unpublish_rubrik_neuigkeit_path(menu.rubrik,menu), :remote=>true, class: "btn stacked") if can?(:unpublish, menu) && menu.published? %> - <% if @neuigkeit.published? %> + <% if menu.published? %> <% end %>
    - <%= render_new_attachments_for(@neuigkeit, fa_icon("plus"), {class: "btn"}) %> + <%= render_new_attachments_for(menu, fa_icon("plus"), {class: "btn"}) %>
    From 4a8e5d393ea22109f6bff214505be928d1dbdf56 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 13 Sep 2015 10:03:11 +0200 Subject: [PATCH 66/73] AutoCommit Son Sep 13 10:03:11 CEST 2015 --- app/views/home/infoscreen.html.erb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/home/infoscreen.html.erb b/app/views/home/infoscreen.html.erb index 6cce21f..3bc70dc 100644 --- a/app/views/home/infoscreen.html.erb +++ b/app/views/home/infoscreen.html.erb @@ -51,16 +51,17 @@
    <% i = i+1 %> <% end %> -
    -
    -
    +
    +
    +
    From b073a1a0987c939e9ba989e24852b0569f9697a7 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 13 Sep 2015 12:03:21 +0200 Subject: [PATCH 68/73] AutoCommit Son Sep 13 12:03:20 CEST 2015 --- Gemfile | 6 ++--- app/controllers/home_controller.rb | 2 +- app/controllers/neuigkeiten_controller.rb | 1 + app/models/neuigkeit.rb | 6 +++++ app/views/home/infoscreen.html.erb | 23 +++++++++++++++---- .../themes/blue2/neuigkeiten/_menu.html.erb | 2 ++ config/routes.rb | 2 +- ...50913090628_add_infoscreen_to_neuigkeit.rb | 7 ++++++ 8 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20150913090628_add_infoscreen_to_neuigkeit.rb diff --git a/Gemfile b/Gemfile index fefe5f6..39c0935 100755 --- a/Gemfile +++ b/Gemfile @@ -13,8 +13,8 @@ gem 'webrick', '1.3.1' # Gems used only for assets and not required # in production environments by default. - gem 'sass-rails', '~> 4.0.0' - gem 'coffee-rails', '~> 4.0.0' + gem 'sass-rails', '~> 3.0' + gem 'coffee-rails', '~> 3.0' gem 'bootstrap-sass','~> 2.3.2.1' group :assets do @@ -102,7 +102,7 @@ gem 'rmagick' gem 'bootstrap-addons-rails' gem "jquery-fileupload-rails", "0.4.1" -gem "jquery-ui-rails","~> 4.2.0" +gem "jquery-ui-rails","~> 4.1.0" gem "font-awesome-rails" gem "jquery-datetimepicker-rails" # gem "jquery-sortable-rails" diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index ebf2870..28fd237 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -22,7 +22,7 @@ class HomeController < ApplicationController end def infoscreen authorize! :doadmin, User - @neuigkeiten = Neuigkeit.accessible_by(current_ability, :show).limit(10) + @neuigkeiten = Neuigkeit.accessible_by(current_ability, :show).where(flag_infoscreen: true) render layout: false end def kontakt diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 6410924..ce08d18 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -3,6 +3,7 @@ class NeuigkeitenController < ApplicationController before_filter :load_toolbar_elements, :only=>[:show,:find_link] before_filter :load_toolbar_elements_edit, :only=>[:edit] + acts_as_flagable diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index 6bab7a0..a89812a 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -44,6 +44,12 @@ class Neuigkeit < ActiveRecord::Base before_validation :sanitize after_save :update_cache attr_accessor :no_fallbacks + + acts_as_flagable + + FLAG_ICONS={"infoscreen" => "fa fa-flag"} + FLAG_CONFIRM={"infoscreen" => "Neuigkeit am Infoscreen anzeigen"} + def globalize_fallbacks(locale) if self.no_fallbacks [locale] diff --git a/app/views/home/infoscreen.html.erb b/app/views/home/infoscreen.html.erb index 732abb8..6100f27 100644 --- a/app/views/home/infoscreen.html.erb +++ b/app/views/home/infoscreen.html.erb @@ -13,8 +13,8 @@ <% i=1 %> <% @neuigkeiten.each do |n| %> -
    <% @toolbar_elements=[];@questions=[] %> -
    +
    <% @toolbar_elements=[];@questions=[] %> +
    <% unless n.picture_robust.big_thumb.to_s.empty? %>


    <%= link_to image_tag(n.picture_robust.big_thumb),n.picture_robust.try(:url) %> @@ -54,7 +54,7 @@

    -
    +
    diff --git a/app/views/themes/blue2/neuigkeiten/_menu.html.erb b/app/views/themes/blue2/neuigkeiten/_menu.html.erb index 0b666b5..9b08917 100644 --- a/app/views/themes/blue2/neuigkeiten/_menu.html.erb +++ b/app/views/themes/blue2/neuigkeiten/_menu.html.erb @@ -14,6 +14,8 @@ <%= new_question_for(menu, fa_icon("question")) if can? :new, Survey::Question %> + <%= flag_link(menu, "infoscreen")%> + <%= link_to(fa_icon("globe"), publish_rubrik_neuigkeit_path(menu.rubrik,menu), title: I18n.t('neuigkeit.publish'), class: "btn") if can?(:publish, menu) && !menu.published? %> <%= link_to(fa_stack("globe","ban"), unpublish_rubrik_neuigkeit_path(menu.rubrik,menu), :remote=>true, class: "btn stacked") if can?(:unpublish, menu) && menu.published? diff --git a/config/routes.rb b/config/routes.rb index 456d3c9..aa8d6ae 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -184,7 +184,7 @@ end get 'publish_to_facebook' get 'mail_to_fet' get 'mail_preview' - + get 'flag' end collection do get 'newsletter_preview' diff --git a/db/migrate/20150913090628_add_infoscreen_to_neuigkeit.rb b/db/migrate/20150913090628_add_infoscreen_to_neuigkeit.rb new file mode 100644 index 0000000..de511c4 --- /dev/null +++ b/db/migrate/20150913090628_add_infoscreen_to_neuigkeit.rb @@ -0,0 +1,7 @@ +class AddInfoscreenToNeuigkeit < ActiveRecord::Migration + def change + add_column :neuigkeiten, :flag_infoscreen, :boolean, default: false + add_column :themen, :flag_infoscreen, :boolean, default: false + + end +end From a9c9b22a948259ea6fb2926cf863c534960868b1 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 13 Sep 2015 13:03:44 +0200 Subject: [PATCH 69/73] AutoCommit Son Sep 13 13:03:44 CEST 2015 --- app/models/neuigkeit.rb | 2 +- app/views/home/infoscreen.html.erb | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index a89812a..0f0b523 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -47,7 +47,7 @@ class Neuigkeit < ActiveRecord::Base acts_as_flagable - FLAG_ICONS={"infoscreen" => "fa fa-flag"} + FLAG_ICONS={"infoscreen" => "fa fa-desktop"} FLAG_CONFIRM={"infoscreen" => "Neuigkeit am Infoscreen anzeigen"} def globalize_fallbacks(locale) diff --git a/app/views/home/infoscreen.html.erb b/app/views/home/infoscreen.html.erb index 6100f27..ec873c1 100644 --- a/app/views/home/infoscreen.html.erb +++ b/app/views/home/infoscreen.html.erb @@ -53,8 +53,9 @@ <% end %>
    +
    -
    +