diff --git a/Gemfile b/Gemfile index f80a6a4..79045eb 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,18 @@ gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby +# Integrate Paperclip into Mongoid. +gem "mongoid-paperclip" + +# To extend paperclip with locales +gem 'paperclip-i18n' + +# Amazon's S3 file hosting service +gem 'aws-sdk' + +# A fixtures replacement +gem 'factory_girl' + # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index d7822fd..e5d4282 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,14 @@ GEM arel (6.0.4) autoprefixer-rails (6.7.7.1) execjs + aws-sdk (2.9.7) + aws-sdk-resources (= 2.9.7) + aws-sdk-core (2.9.7) + aws-sigv4 (~> 1.0) + jmespath (~> 1.0) + aws-sdk-resources (2.9.7) + aws-sdk-core (= 2.9.7) + aws-sigv4 (1.0.0) bcrypt (3.1.11) benchmark-ips (2.7.2) binding_of_caller (0.7.2) @@ -59,6 +67,9 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + climate_control (0.1.0) + cocaine (0.5.8) + climate_control (>= 0.0.3, < 1.0) coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) @@ -94,6 +105,8 @@ GEM erubis (2.7.0) excon (0.55.0) execjs (2.7.0) + factory_girl (4.8.0) + activesupport (>= 3.0.0) faker (1.7.2) i18n (~> 0.5) font-awesome-rails (4.7.0.1) @@ -110,6 +123,7 @@ GEM jbuilder (2.6.3) activesupport (>= 3.0.0, < 5.2) multi_json (~> 1.2) + jmespath (1.3.1) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -139,6 +153,7 @@ GEM mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) + mimemagic (0.3.2) mini_portile2 (2.1.0) minitest (5.10.1) mongo (2.4.1) @@ -151,6 +166,9 @@ GEM mongoid-compatibility (0.4.1) activesupport mongoid (>= 2.0) + mongoid-paperclip (0.0.11) + mongoid + paperclip (>= 2.3.6, != 4.3.0) mongoid-rspec (3.0.0) mongoid (~> 5.0) rake @@ -164,6 +182,13 @@ GEM mini_portile2 (~> 2.1.0) origin (2.3.0) orm_adapter (0.5.0) + paperclip (5.1.0) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) + cocaine (~> 0.5.5) + mime-types + mimemagic (~> 0.3.0) + paperclip-i18n (4.3.0) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -312,6 +337,7 @@ PLATFORMS ruby DEPENDENCIES + aws-sdk bootstrap-sass (~> 3.3.5) byebug capybara @@ -320,6 +346,7 @@ DEPENDENCIES devise devise-i18n dotenv-rails + factory_girl faker geocoder jbuilder (~> 2.0) @@ -328,8 +355,10 @@ DEPENDENCIES kaminari-mongoid mailchimp-api mongoid (~> 5.0.0) + mongoid-paperclip mongoid-rspec (= 3.0.0) mongoid_paranoia + paperclip-i18n pry-rails puma rails (~> 4.2) diff --git a/app/controllers/publicities_controller.rb b/app/controllers/publicities_controller.rb new file mode 100644 index 0000000..5d47a56 --- /dev/null +++ b/app/controllers/publicities_controller.rb @@ -0,0 +1,29 @@ +class PublicitiesController < ApplicationController + before_action :authenticate_supporter! + + def new + @publicity = current_supporter.publicity || Publicity.new + end + + def create + @publicity = Publicity.new(publicity_params.merge(supporter: current_supporter, state: :pending)) + flash['success'] = t('.success') if @publicity.valid? + return redirect_to(root_path) if @publicity.save + render :new + end + + def update + create + end + + def destroy + current_supporter.publicity&.destroy + redirect_to(root_path) + end + + private + + def publicity_params + params.require(:publicity).permit(:organisation, :statement, :avatar) + end +end diff --git a/app/models/publicity.rb b/app/models/publicity.rb new file mode 100644 index 0000000..2c6253b --- /dev/null +++ b/app/models/publicity.rb @@ -0,0 +1,26 @@ +class Publicity + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Paperclip + + has_mongoid_attached_file :avatar, + path: ':attachment/:id/:style.:extension', + styles: { + original: ['1920x1680>', :jpg], + small: ['100x100#', :jpg], + medium: ['250x250', :jpg], + large: ['500x500>', :jpg] + }, + convert_options: { all: '-background white -flatten +matte' } + + embedded_in :supporter + + field :state, type: String, default: 'pending' # Possible states: pending, approved + field :organisation, type: String + field :statement, type: String + + validates :state, presence: true + validates :avatar, presence: true + validates :statement, presence: true + validates_attachment_content_type :avatar, content_type: /\Aimage/ +end diff --git a/app/models/supporter.rb b/app/models/supporter.rb index 80070e6..8c6a75e 100644 --- a/app/models/supporter.rb +++ b/app/models/supporter.rb @@ -1,5 +1,11 @@ class Supporter include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Paranoia + include Geocoder::Model::Mongoid + + COUNTER_START = 10_003 + # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, @@ -23,22 +29,6 @@ class Supporter field :current_sign_in_ip, type: String field :last_sign_in_ip, type: String - ## Confirmable - # field :confirmation_token, type: String - # field :confirmed_at, type: Time - # field :confirmation_sent_at, type: Time - # field :unconfirmed_email, type: String # Only if using reconfirmable - - ## Lockable - # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts - # field :unlock_token, type: String # Only if unlock strategy is :email or :both - # field :locked_at, type: Time - include Mongoid::Timestamps - include Mongoid::Paranoia - include Geocoder::Model::Mongoid - - COUNTER_START = 10_003 - geocoded_by :address after_validation :geocode # auto-fetch coordinates @@ -66,6 +56,8 @@ class Supporter validates :age_category, presence: true validates :language, presence: true + embeds_one :publicity + def self.counter actual = count.to_i actual > COUNTER_START ? actual : COUNTER_START diff --git a/app/views/publicities/_form.slim b/app/views/publicities/_form.slim new file mode 100644 index 0000000..14adb86 --- /dev/null +++ b/app/views/publicities/_form.slim @@ -0,0 +1,6 @@ +h1= title t('.title') += simple_form_for(@publicity, url: publicity_path) do |form| + = form.input :organisation, required: false, label: t('.organisation'), placeholder: t('.organisation_placeholder') + = form.input :statement, as: :text, required: false + = form.input :avatar, as: :file, label: t('.avatar'), required: false + = form.submit t('.save'), class: 'btn btn-primary' diff --git a/app/views/publicities/new.slim b/app/views/publicities/new.slim new file mode 100644 index 0000000..86842fe --- /dev/null +++ b/app/views/publicities/new.slim @@ -0,0 +1 @@ += render 'form' \ No newline at end of file diff --git a/app/views/supporters/_publicity.slim b/app/views/supporters/_publicity.slim new file mode 100644 index 0000000..8b52df5 --- /dev/null +++ b/app/views/supporters/_publicity.slim @@ -0,0 +1,28 @@ +- if current_supporter.publicity + .panel.panel-default + .panel-heading + h2.panel-title + = t '.title' + .panel-body + dl.dl-horizontal + dt = Publicity.human_attribute_name(:status) + - if current_supporter.publicity.state == 'pending' + dd.text-danger = t('.pending') + - if current_supporter.publicity.state == 'approved' + dd.text-success = t('.pending') + - unless current_supporter.publicity.organisation.blank? + dt = Publicity.human_attribute_name(:organisation) + dd = current_supporter.publicity.organisation + dt = Publicity.human_attribute_name(:statement) + dd = current_supporter.publicity.statement + dt = Publicity.human_attribute_name(:avatar) + dd = image_tag current_supporter.publicity.avatar.url(:small), alt: '' + + .pull-right + = link_to t(".renew"), new_publicity_path + br + = link_to t(".delete"), publicity_path, data: { confirm: t("shared.are_you_sure") }, method: :delete, class: 'text-danger' + +- else + .alert.alert-notice + = link_to t('.create_publicity'), new_publicity_path \ No newline at end of file diff --git a/app/views/supporters/new.slim b/app/views/supporters/new.slim index 7a937e3..ceec04c 100644 --- a/app/views/supporters/new.slim +++ b/app/views/supporters/new.slim @@ -29,7 +29,8 @@ p = link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right' - + = render 'publicity' + aside.col-md-5.col-xs-12 = render 'right_side' diff --git a/avatars/58ef8b5e2bc61f43d270dbec/large.jpg b/avatars/58ef8b5e2bc61f43d270dbec/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8b5e2bc61f43d270dbec/large.jpg differ diff --git a/avatars/58ef8b5e2bc61f43d270dbec/medium.jpg b/avatars/58ef8b5e2bc61f43d270dbec/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8b5e2bc61f43d270dbec/medium.jpg differ diff --git a/avatars/58ef8b5e2bc61f43d270dbec/original.jpg b/avatars/58ef8b5e2bc61f43d270dbec/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8b5e2bc61f43d270dbec/original.jpg differ diff --git a/avatars/58ef8b5e2bc61f43d270dbec/small.jpg b/avatars/58ef8b5e2bc61f43d270dbec/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8b5e2bc61f43d270dbec/small.jpg differ diff --git a/avatars/58ef8e082bc61f4612240e26/large.jpg b/avatars/58ef8e082bc61f4612240e26/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8e082bc61f4612240e26/large.jpg differ diff --git a/avatars/58ef8e082bc61f4612240e26/medium.jpg b/avatars/58ef8e082bc61f4612240e26/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8e082bc61f4612240e26/medium.jpg differ diff --git a/avatars/58ef8e082bc61f4612240e26/original.jpg b/avatars/58ef8e082bc61f4612240e26/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8e082bc61f4612240e26/original.jpg differ diff --git a/avatars/58ef8e082bc61f4612240e26/small.jpg b/avatars/58ef8e082bc61f4612240e26/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8e082bc61f4612240e26/small.jpg differ diff --git a/avatars/58ef8e2c2bc61f465a1ba13e/large.jpg b/avatars/58ef8e2c2bc61f465a1ba13e/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8e2c2bc61f465a1ba13e/large.jpg differ diff --git a/avatars/58ef8e2c2bc61f465a1ba13e/medium.jpg b/avatars/58ef8e2c2bc61f465a1ba13e/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8e2c2bc61f465a1ba13e/medium.jpg differ diff --git a/avatars/58ef8e2c2bc61f465a1ba13e/original.jpg b/avatars/58ef8e2c2bc61f465a1ba13e/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8e2c2bc61f465a1ba13e/original.jpg differ diff --git a/avatars/58ef8e2c2bc61f465a1ba13e/small.jpg b/avatars/58ef8e2c2bc61f465a1ba13e/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8e2c2bc61f465a1ba13e/small.jpg differ diff --git a/avatars/58ef8e902bc61f46f78a1d92/large.jpg b/avatars/58ef8e902bc61f46f78a1d92/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8e902bc61f46f78a1d92/large.jpg differ diff --git a/avatars/58ef8e902bc61f46f78a1d92/medium.jpg b/avatars/58ef8e902bc61f46f78a1d92/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8e902bc61f46f78a1d92/medium.jpg differ diff --git a/avatars/58ef8e902bc61f46f78a1d92/original.jpg b/avatars/58ef8e902bc61f46f78a1d92/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8e902bc61f46f78a1d92/original.jpg differ diff --git a/avatars/58ef8e902bc61f46f78a1d92/small.jpg b/avatars/58ef8e902bc61f46f78a1d92/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8e902bc61f46f78a1d92/small.jpg differ diff --git a/avatars/58ef8f282bc61f4762227810/large.jpg b/avatars/58ef8f282bc61f4762227810/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8f282bc61f4762227810/large.jpg differ diff --git a/avatars/58ef8f282bc61f4762227810/medium.jpg b/avatars/58ef8f282bc61f4762227810/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8f282bc61f4762227810/medium.jpg differ diff --git a/avatars/58ef8f282bc61f4762227810/original.jpg b/avatars/58ef8f282bc61f4762227810/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8f282bc61f4762227810/original.jpg differ diff --git a/avatars/58ef8f282bc61f4762227810/small.jpg b/avatars/58ef8f282bc61f4762227810/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8f282bc61f4762227810/small.jpg differ diff --git a/avatars/58ef8f292bc61f4762227812/large.jpg b/avatars/58ef8f292bc61f4762227812/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8f292bc61f4762227812/large.jpg differ diff --git a/avatars/58ef8f292bc61f4762227812/medium.jpg b/avatars/58ef8f292bc61f4762227812/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227812/medium.jpg differ diff --git a/avatars/58ef8f292bc61f4762227812/original.jpg b/avatars/58ef8f292bc61f4762227812/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227812/original.jpg differ diff --git a/avatars/58ef8f292bc61f4762227812/small.jpg b/avatars/58ef8f292bc61f4762227812/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227812/small.jpg differ diff --git a/avatars/58ef8f292bc61f4762227813/large.jpg b/avatars/58ef8f292bc61f4762227813/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef8f292bc61f4762227813/large.jpg differ diff --git a/avatars/58ef8f292bc61f4762227813/medium.jpg b/avatars/58ef8f292bc61f4762227813/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227813/medium.jpg differ diff --git a/avatars/58ef8f292bc61f4762227813/original.jpg b/avatars/58ef8f292bc61f4762227813/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227813/original.jpg differ diff --git a/avatars/58ef8f292bc61f4762227813/small.jpg b/avatars/58ef8f292bc61f4762227813/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef8f292bc61f4762227813/small.jpg differ diff --git a/avatars/58ef95cc2bc61f4b8bda7639/large.jpg b/avatars/58ef95cc2bc61f4b8bda7639/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef95cc2bc61f4b8bda7639/large.jpg differ diff --git a/avatars/58ef95cc2bc61f4b8bda7639/medium.jpg b/avatars/58ef95cc2bc61f4b8bda7639/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef95cc2bc61f4b8bda7639/medium.jpg differ diff --git a/avatars/58ef95cc2bc61f4b8bda7639/original.jpg b/avatars/58ef95cc2bc61f4b8bda7639/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef95cc2bc61f4b8bda7639/original.jpg differ diff --git a/avatars/58ef95cc2bc61f4b8bda7639/small.jpg b/avatars/58ef95cc2bc61f4b8bda7639/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef95cc2bc61f4b8bda7639/small.jpg differ diff --git a/avatars/58ef95cd2bc61f4b8bda763a/large.jpg b/avatars/58ef95cd2bc61f4b8bda763a/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef95cd2bc61f4b8bda763a/large.jpg differ diff --git a/avatars/58ef95cd2bc61f4b8bda763a/medium.jpg b/avatars/58ef95cd2bc61f4b8bda763a/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef95cd2bc61f4b8bda763a/medium.jpg differ diff --git a/avatars/58ef95cd2bc61f4b8bda763a/original.jpg b/avatars/58ef95cd2bc61f4b8bda763a/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef95cd2bc61f4b8bda763a/original.jpg differ diff --git a/avatars/58ef95cd2bc61f4b8bda763a/small.jpg b/avatars/58ef95cd2bc61f4b8bda763a/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef95cd2bc61f4b8bda763a/small.jpg differ diff --git a/avatars/58ef95ce2bc61f4b8bda763c/large.jpg b/avatars/58ef95ce2bc61f4b8bda763c/large.jpg new file mode 100644 index 0000000..597d41b Binary files /dev/null and b/avatars/58ef95ce2bc61f4b8bda763c/large.jpg differ diff --git a/avatars/58ef95ce2bc61f4b8bda763c/medium.jpg b/avatars/58ef95ce2bc61f4b8bda763c/medium.jpg new file mode 100644 index 0000000..80ea943 Binary files /dev/null and b/avatars/58ef95ce2bc61f4b8bda763c/medium.jpg differ diff --git a/avatars/58ef95ce2bc61f4b8bda763c/original.jpg b/avatars/58ef95ce2bc61f4b8bda763c/original.jpg new file mode 100644 index 0000000..71a5685 Binary files /dev/null and b/avatars/58ef95ce2bc61f4b8bda763c/original.jpg differ diff --git a/avatars/58ef95ce2bc61f4b8bda763c/small.jpg b/avatars/58ef95ce2bc61f4b8bda763c/small.jpg new file mode 100644 index 0000000..f6e50c2 Binary files /dev/null and b/avatars/58ef95ce2bc61f4b8bda763c/small.jpg differ diff --git a/config/application.rb b/config/application.rb index 0b5d054..f09e3a7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,7 +31,7 @@ module Ch420 # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] config.i18n.default_locale = :de - config.i18n.available_locales = [:de, :it, :fr] + config.i18n.available_locales = [:de, :it, :fr, :en] config.generators do |g| g.orm :mongoid diff --git a/config/environments/development.rb b/config/environments/development.rb index b0ea8ec..d3d93ef 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -41,4 +41,16 @@ Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } + + config.paperclip_defaults = { + storage: :s3, + s3_protocol: :https, + s3_region: ENV["S3_REGION"], + s3_host_name: ENV["S3_HOST_NAME"], + s3_credentials: { + bucket: "cannabis-initiative-development", + access_key_id: ENV["S3_ACCESS_KEY"], + secret_access_key: ENV["S3_ACCESS_SECRET"] + } + } end diff --git a/config/environments/production.rb b/config/environments/production.rb index c1b465f..4115eb1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -87,4 +87,16 @@ Rails.application.configure do authentication: :plain, enable_starttls_auto: true } + + config.paperclip_defaults = { + storage: :s3, + s3_protocol: :https, + s3_region: ENV["S3_REGION"], + s3_host_name: ENV["S3_HOST_NAME"], + s3_credentials: { + bucket: "cannabis-initiative-production", + access_key_id: ENV["S3_ACCESS_KEY"], + secret_access_key: ENV["S3_ACCESS_SECRET"] + } + } end diff --git a/config/initializers/slim.rb b/config/initializers/slim.rb index 3ff3422..b17cb2a 100644 --- a/config/initializers/slim.rb +++ b/config/initializers/slim.rb @@ -1 +1 @@ -Slim::Engine.set_default_options pretty: true \ No newline at end of file +Slim::Engine.set_options pretty: true \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index a313ba8..e3a38d5 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -15,6 +15,8 @@ de: faq: Fragen und Antworten sponsoring: Sponsoren & Spenden numbers: Zahlen + + are_you_sure: Bist du sicher? counter: supporters: "Unterstützer:" @@ -57,6 +59,14 @@ de: city: Hinterpfupfikon zip: "4200" email: hans.muster@hanflegal.ch + + publicity: + title: Mein Statement + renew: Statement neu einreichen + delete: Statement löschen + pending: Die Veröffentlichung wurde noch nicht genehmigt + approved: Das statement wurde Veröffentlicht + create_publicity: Deine Meinung zählt, darum bitten wir dir hier die Möglichkeit öffentlich deine Meinung zur Cannabis-Initiative kundzutun. Gib ein Starkes Statement ab und zeig dein Gesicht! Meine Unterstützung öffentlich kundtun ... create: timeout: Ihre Eingabe war zu schnell. @@ -66,6 +76,19 @@ de: edit: Meine Daten bearbeiten... my_data: Meine Daten + publicities: + form: + title: Meine Meinung zur Cannabis-Initiative veröffentlichen + organisation: Organisation (Optional) + organisation_placeholder: Parteizugehörigkeit, Verband oder sonstige Organisationen + avatar: Lade ein Bild von dir Hoch + save: Zur Überprüfung einsenden + + create: + success: Besten Dank die Daten werden überprüft. + update: + success: Besten Dank die Daten werden überprüft. + pages: show: not_found: Die Seite konnte nicht gefunden werden. @@ -101,3 +124,8 @@ de: unsubscribed: Kein Newsletter password_confirmation: Passwort bestätigen current_password: Aktuelles Passwort + publicity: + status: Status + organisation: Organisation + statement: Statement + avatar: Bild \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e72f301..2f5ee65 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -20,7 +20,9 @@ fr: faq: Questions et réponses (en allemand) sponsoring: Donation et Sponsors (en allemand) numbers: Chiffres (en allemand) - + + are_you_sure: Tu es sûre? + welcome_email: subject: Merci beaucoup pour ton soutien! @@ -40,7 +42,7 @@ fr: de: Deutsch fr: Français it: Italiano - + supporters: form: form: Formulaire @@ -54,7 +56,14 @@ fr: city: Hinterpfupfikon zip: "4200" email: hans.muster@hanflegal.ch - + publicity: + title: Ma déclaration + renew: resoumettre déclaration + delete: supprimer déclaration + pending: La publication n'a pas été approuvé + approved: La déclaration a été publiée + create_publicity: Votre opinion compte, nous vous demandons ici d'exprimer publiquement votre avis sur initiative de cannabis possible. Rendre public mon soutien ... + create: timeout: Ihre Eingabe war zu schnell. @@ -62,6 +71,19 @@ fr: title: Salut %{name} edit: Modifier mes données ... my_data: Mes données + + publicities: + form: + title: Donner mon avis sur l'initiative de cannabis + organisation: Organisation (Facultatif) + organisation_placeholder: Affiliation parti, une association ou d'autres organisations + avatar: Ajouter une photo + save: Envoyé pour examen + + create: + success: Merci, les données sont vérifiées. + update: + success: Merci, les données sont vérifiées. pages: show: @@ -98,3 +120,9 @@ fr: unsubscribed: pas de newslettre password_confirmation: confirmer le mot de passe current_password: Mot de passe actuel + + publicity: + status: Statu + organisation: Organisation + statement: Déclaration + avatar: Photo \ No newline at end of file diff --git a/config/locales/it.yml b/config/locales/it.yml index c46e884..f80f6a8 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -21,7 +21,8 @@ it: counter: supporters: "Sostenitore:" amount_of_supporters: Al momento abbiamo %{amount} sostenitori. - + + are_you_sure: Sei sicuro? welcome_email: subject: Grazie mille per il tuo sostegno! @@ -57,7 +58,15 @@ it: city: Hinterpfupfikon zip: "4200" email: hans.muster@hanflegal.ch - + + publicity: + title: La mia dichiarazione + renew: Ripresentare Statement + delete: Eliminare la dichiarazione + pending: La pubblicazione non è stato approvato + approved: La dichiarazione è stata rilasciata + create_publicity: La tua opinione conta, quindi vi chiediamo qui pubblicamente esprimere la tua opinione su iniziativa di cannabis possibile. Girare in una dichiarazione forte e mostrare il tuo volto! Il mio supporto rendere pubblico ... + create: timeout: Ihre Eingabe war zu schnell. @@ -65,6 +74,19 @@ it: title: Ciao %{name} edit: Modifica i miei dati ... my_data: Miei dati + + publicities: + form: + title: Lasciare un commento sull'iniziativa cannabis + organisation: Organizzazione (opzionale) + organisation_placeholder: Partito di appartenenza, di associazione o di altre organizzazioni + avatar: Carica una foto + save: Inviato per la revisione + + create: + success: Grazie, i dati vengono controllati. + update: + success: Grazie, i dati vengono controllati. pages: thanks: @@ -99,3 +121,8 @@ it: unsubscribed: No Newsletter password_confirmation: conferma password current_password: Password corrente + publicity: + status: Statu + organisation: Organizzazione + statement: Dichiarazione + avatar: Foto \ No newline at end of file diff --git a/config/locales/mongoid.de.yml b/config/locales/mongoid.de.yml new file mode 100644 index 0000000..91c8ecb --- /dev/null +++ b/config/locales/mongoid.de.yml @@ -0,0 +1,472 @@ +de: + mongoid: + errors: + messages: + blank_in_locale: + "can't be blank in %{location}" + message_title: "message" + summary_title: "summary" + resolution_title: "resolution" + ambiguous_relationship: + message: "Ambiguous relations %{candidates} defined on %{klass}." + summary: + "When Mongoid attempts to set an inverse document of a relation + in memory, it needs to know which relation it belongs to. When + setting %{name}, Mongoid looked on the class %{inverse} + for a matching relation, but multiples were found that could + potentially match: %{candidates}." + resolution: "On the %{name} relation on %{inverse} you must add an + :inverse_of option to specify the exact relationship on %{klass} + that is the opposite of %{name}." + callbacks: + message: "Calling %{method} on %{klass} resulted in a false return + from a callback." + summary: "If a before callback returns false when using Document.create!, + Document#save!, or Document#update_attributes! this error will get raised + since the document did not actually get saved." + resolution: "Double check all before callbacks to make sure they are + not unintentionally returning false." + calling_document_find_with_nil_is_invalid: + message: "Calling Document.find with nil is invalid." + summary: "Document.find expects the parameters to be 1 or more ids, and + will return a single document if 1 id is provided, otherwise an array + of documents if multiple ids are provided." + resolution: "Most likely this is caused by passing parameters directly + through to the find, and the parameter either is not present or the + key from which it is accessed is incorrect." + document_not_destroyed: + message: "%{klass} with id %{id} was not destroyed." + summary: "When calling %{klass}#destroy! and a callback halts the destroy + callback chain by returning a false value, the deletion will not + actually occur." + resolution: "Check the before/after destroy callbacks to ensure that the + return values are truthy for the chain to continue." + document_not_found: + message: "Document(s) not found for class %{klass} with id(s) %{missing}." + summary: "When calling %{klass}.find with an id or array of ids, each + parameter must match a document in the database or this error will be + raised. The search was for the id(s): %{searched} (%{total} total) + and the following ids were not found: %{missing}." + resolution: "Search for an id that is in the database or set + the Mongoid.raise_not_found_error configuration option to false, + which will cause a nil to be returned instead of raising this error when + searching for a single id, or only the matched documents when searching + for multiples." + document_with_attributes_not_found: + message: "Document not found for class %{klass} with attributes %{attributes}." + summary: "When calling %{klass}.find_by with a hash of attributes, all + attributes provided must match a document in the database or this error + will be raised." + resolution: "Search for attributes that are in the database or set + the Mongoid.raise_not_found_error configuration option to false, + which will cause a nil to be returned instead of raising this error." + eager_load: + message: "Eager loading :%{name} is not supported since it is a + polymorphic belongs_to relation." + summary: "Mongoid cannot currently determine the classes it needs to + eager load when the relation is polymorphic. The parents reside in + different collections so a simple id lookup is not sufficient enough." + resolution: "Don't attempt to perform this action and have patience, + maybe this will be supported in the future." + invalid_collection: + message: "Access to the collection for %{klass} is not allowed." + summary: "%{klass}.collection was called, and %{klass} is an embedded + document - it resides within the collection of the root document of + the hierarchy." + resolution: "For access to the collection that the embedded document is + in, use %{klass}#_root.collection, or do not attempt to persist an + embedded document without a parent set." + invalid_config_option: + message: "Invalid configuration option: %{name}." + summary: "A invalid configuration option was provided in your + mongoid.yml, or a typo is potentially present. The valid configuration + options are: %{options}." + resolution: "Remove the invalid option or fix the typo. If you were + expecting the option to be there, please consult the following page + with repect to Mongoid's configuration:\n\n + \_\_http://mongoid.org/en/mongoid/docs/installation.html" + invalid_field: + message: "Defining a field named '%{name}' is not allowed." + summary: "Defining this field would override the method '%{name}', + which would cause issues with expectations around the original + method and cause extremely hard to debug issues. The original + method was defined in:\n + \_\_Object: %{origin}\n + \_\_File: %{file}\n + \_\_Line: %{line}" + resolution: "Use Mongoid.destructive_fields to see what names are not + allowed, and don't use these names. These include names that also + conflict with core Ruby methods on Object, Module, Enumerable, or + included gems that inject methods into these or Mongoid internals." + invalid_field_option: + message: "Invalid option :%{option} provided for field :%{name}." + summary: "Mongoid requires that you only provide valid options on each + field definition in order to prevent unexpected behaviour later on." + resolution: "When defining the field :%{name} on '%{klass}', please provide + valid options for the field. These are currently: %{valid}. If you + meant to define a custom field option, please do so first like so:\n\n + \_\_Mongoid::Fields.option :%{option} do |model, field, value|\n + \_\_\_\_# Your logic here...\n + \_\_end\n + \_\_class %{klass}\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_field :%{name}, %{option}: true\n + \_\_end\n\n" + invalid_includes: + message: "Invalid includes directive: %{klass}.includes(%{args})" + summary: "Eager loading in Mongoid only supports providing arguments + to %{klass}.includes that are the names of relations on the %{klass} + model, and only supports one level of eager loading. (ie, eager loading + associations not on the %{klass} but one step away via another relation + is not allowed." + resolution: "Ensure that each parameter passed to %{klass}.includes is + a valid name of a relation on the %{klass} model. These are: %{relations}." + invalid_index: + message: "Invalid index specification on %{klass}: %{spec}, %{options}" + summary: "Indexes in Mongoid are defined as a hash of field name and + direction/2d pairs, with a hash for any additional options." + resolution: "Ensure that the index conforms to the correct syntax and + has the correct options.\n\n + Valid options are:\n + \_\_background: true|false\n + \_\_database: 'database_name'\n + \_\_drop_dups: true|false\n + \_\_name: 'index_name'\n + \_\_sparse: true|false\n + \_\_unique: true|false\n + \_\_min: 1\n + \_\_max: 1\n + \_\_bits: 26\n + \_\_bucket_size : 1\n + \_\_weights: { content: 1, title: 2 }\n + \_\_expire_after_seconds: number_of_seconds\n + Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n + Example:\n + \_\_class Band\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_index({ name: 1, label: -1 }, { sparse: true })\n + \_\_\_\_index({ location: '2d' }, { background: true })\n + \_\_end\n\n" + invalid_options: + message: "Invalid option :%{invalid} provided to relation :%{name}." + summary: "Mongoid checks the options that are passed to the relation + macros to ensure that no ill side effects occur by letting something + slip by." + resolution: "Valid options are: %{valid}, make sure these are the ones + you are using." + invalid_path: + message: "Having a root path assigned for %{klass} is invalid." + summary: "Mongoid has two different path objects for determining + the location of a document in the database, Root and Embedded. + This error is raised when an embedded document somehow gets a + root path assigned." + resolution: "Most likely your embedded model, %{klass} is also + referenced via a has_many from a root document in another + collection. Double check the relation definitions and fix any + instances where embedded documents are improperly referenced + from other collections." + invalid_scope: + message: "Defining a scope of value %{value} on %{klass} is not + allowed." + summary: "Scopes in Mongoid must be procs that wrap criteria objects." + resolution: "Change the scope to be a proc wrapped critera.\n\n + Example:\n + \_\_class Band\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_scope :inactive, ->{ where(active: false) }\n + \_\_end\n\n" + invalid_storage_options: + message: "Invalid options passed to %{klass}.store_in: %{options}." + summary: "The :store_in macro takes only a hash of parameters with + the keys :database, :collection, or :session." + resolution: "Change the options passed to store_in to match the + documented API, and ensure all keys in the options hash are + symbols.\n\n + Example:\n + \_\_class Band\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_store_in collection: 'artists', database: 'secondary'\n + \_\_end\n\n" + invalid_storage_parent: + message: "Invalid store_in call on class %{klass}." + summary: "The :store_in macro can only be called on a base Mongoid Document" + resolution: "Remove the store_in call on class %{klass}, as it will use its + parent store configuration. Or remove the hierarchy extension for this + class." + invalid_time: + message: "'%{value}' is not a valid Time." + summary: "Mongoid tries to serialize the values for Date, DateTime, and + Time into proper UTC times to store in the database. The provided + value could not be parsed." + resolution: "Make sure to pass parsable values to the field setter + for Date, DateTime, and Time objects. When this is a String it needs + to be valid for Time.parse. Other objects must be valid to pass to + Time.local." + inverse_not_found: + message: "When adding a(n) %{klass} to %{base}#%{name}, Mongoid could + not determine the inverse foreign key to set. The attempted key was + '%{inverse}'." + summary: "When adding a document to a relation, Mongoid attempts + to link the newly added document to the base of the relation in + memory, as well as set the foreign key to link them on the + database side. In this case Mongoid could not determine what the + inverse foreign key was." + resolution: "If an inverse is not required, like a belongs_to or + has_and_belongs_to_many, ensure that :inverse_of => nil is set + on the relation. If the inverse is needed, most likely the + inverse cannot be figured out from the names of the relations and + you will need to explicitly tell Mongoid on the relation what + the inverse is.\n\n + Example:\n + \_\_class Lush\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_has_one :whiskey, class_name: \"Drink\", inverse_of: :alcoholic\n + \_\_end\n\n + \_\_class Drink\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_belongs_to :alcoholic, class_name: \"Lush\", inverse_of: :whiskey\n + \_\_end" + invalid_set_polymorphic_relation: + message: "The %{name} attribute can't be set to an instance of + %{other_klass} as %{other_klass} has multiple relations referencing + %{klass} as %{name}." + summary: "If the parent class of a polymorphic relation has multiple + definitions for the same relation, the values must be set from the + parent side and not the child side since Mongoid cannot determine + from the child side which relation to go in." + resolution: "Set the values from the parent, or redefine the relation + with only a single definition in the parent." + invalid_value: + message: "Value of type %{value_class} cannot be written to a field of type %{field_class}" + summary: "Tried to set a value of type %{value_class} to a field of type %{field_class}" + resolution: "Verify if the value to be set correspond to field definition" + mixed_relations: + message: "Referencing a(n) %{embedded} document from the %{root} + document via a relational association is not allowed since the + %{embedded} is embedded." + summary: "In order to properly access a(n) %{embedded} from %{root} + the reference would need to go through the root document of + %{embedded}. In a simple case this would require Mongoid to store + an extra foreign key for the root, in more complex cases where + %{embedded} is multiple levels deep a key would need to be stored + for each parent up the hierarchy." + resolution: "Consider not embedding %{embedded}, or do the key + storage and access in a custom manner in the application code." + mixed_session_configuration: + message: "Both uri and standard configuration options defined for + session: '%{name}'." + summary: "Instead of simply giving uri or standard options a + preference order, Mongoid assumes that you have made a mistake in + your configuration and requires that you provide one or the other, + but not both. The options that were provided were: %{config}." + resolution: "Provide either only a uri as configuration or only + standard options." + nested_attributes_metadata_not_found: + message: "Could not find metadata for relation '%{name}' on model: + %{klass}." + summary: "When defining nested attributes for a relation, Mongoid + needs to access the metadata for the relation '%{name}' in order + if add autosave functionality to it, if applicable. Either no + relation named '%{name}' could be found, or the relation had not + been defined yet." + resolution: "Make sure that there is a relation defined named + '%{name}' on %{klass} or that the relation definition comes before + the accepts_nested_attributes_for macro in the model - order + matters so that Mongoid has access to the metadata.\n\n + Example:\n + \_\_class Band\n + \_\_\_\_include Mongoid::Document\n + \_\_\_\_has_many :albums\n + \_\_\_\_accepts_nested_attributes_for :albums\n + \_\_end\n\n" + no_default_session: + message: "No default session configuration is defined." + summary: "The configuration provided settings for: %{keys}, but + Mongoid requires a :default to be defined at minimum." + resolution: "If configuring via a mongoid.yml, ensure that within + your :sessions section a :default session is defined.\n\n + Example:\n + \_\_development:\n + \_\_\_\_sessions:\n + \_\_\_\_\_\_default:\n + \_\_\_\_\_\_\_\_hosts:\n + \_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n" + no_environment: + message: "Could not load the configuration since no environment + was defined." + summary: "Mongoid attempted to find the appropriate environment + but no Rails.env, Sinatra::Base.environment, RACK_ENV, or + MONGOID_ENV could be found." + resolution: "Make sure some environment is set from the mentioned + options. Mongoid cannot load configuration from the yaml without + knowing which environment it is in, and we have considered + defaulting to development an undesireable side effect of this not + being defined." + no_map_reduce_output: + message: "No output location was specified for the map/reduce + operation." + summary: "When executing a map/reduce, you must provide the output + location of the results. The attempted command was: %{command}." + resolution: "Provide the location that the output of the operation + is to go by chaining an #out call to the map/reduce.\n\n + Example:\n + \_\_Band.map_reduce(map, reduce).out(inline: 1)\n\n + Valid options for the out function are:\n + \_\_inline: 1\n + \_\_merge: 'collection-name'\n + \_\_replace: 'collection-name'\n + \_\_reduce: 'collection-name'\n\n" + no_metadata: + message: "Metadata not found for document of type %{klass}." + summary: "Mongoid sets the metadata of a relation on the document + when it is either loaded from within the relation, or added to + one. The presence of the metadata is required in order to + provide various functionality around relations. Most likely you + are getting this error because the document is embedded and was + attempted to be persisted without being associated with a parent, + or the relation was not properly defined." + resolution: "Ensure that your relations on the %{klass} model + are all properly defined, and that the inverse relations + are also properly defined. Embedded relations must have both the + parent (embeds_one/embeds_many) and the inverse (embedded_in) + present in order to work properly." + no_parent: + message: "Cannot persist embedded document %{klass} without a + parent document." + summary: "If the document is embedded, in order to be persisted it + must always have a reference to its parent document. This is + most likely caused by either calling %{klass}.create or + %{klass}.create! without setting the parent document as an + attribute." + resolution: "Ensure that you've set the parent relation if + instantiating the embedded document directly, or always create new + embedded documents via the parent relation." + no_session_config: + message: "No configuration could be found for a session named + '%{name}'." + summary: "When attempting to create the new session, Mongoid could + not find a session configuration for the name: '%{name}'. This is + necessary in order to know the host, port, and options needed + to connect." + resolution: "Double check your mongoid.yml to make sure under the + sessions key that a configuration exists for '%{name}'. If you + have set the configuration programatically, ensure that '%{name}' + exists in the configuration hash." + no_sessions_config: + message: "No sessions configuration provided." + summary: "Mongoid's configuration requires that you provide details + about each session that can be connected to, and requires in + the sessions config at least 1 default session to exist." + resolution: "Double check your mongoid.yml to make sure that you + have a top-level sessions key with at least 1 default session + configuration for it. You can regenerate a new mongoid.yml for + assistance via `rails g mongoid:config`.\n\n + Example:\n + \_\_development:\n + \_\_\_\_sessions:\n + \_\_\_\_\_\_default:\n + \_\_\_\_\_\_\_\_database: mongoid_dev\n + \_\_\_\_\_\_\_\_hosts:\n + \_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n" + no_session_database: + message: "No database provided for session configuration: :%{name}." + summary: "Each session configuration must provide a database so Mongoid + knows where the default database to persist to. What was provided + was: %{config}." + resolution: "If configuring via a mongoid.yml, ensure that within + your :%{name} section a :database value for the session's default + database is defined.\n\n + Example:\n + \_\_development:\n + \_\_\_\_sessions:\n + \_\_\_\_\_\_%{name}:\n + \_\_\_\_\_\_\_\_database: my_app_db\n + \_\_\_\_\_\_\_\_hosts:\n + \_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n" + no_session_hosts: + message: "No hosts provided for session configuration: :%{name}." + summary: "Each session configuration must provide hosts so Mongoid + knows where the database server is located. What was provided + was: %{config}." + resolution: "If configuring via a mongoid.yml, ensure that within + your :%{name} section a :hosts value for the session hosts is + defined.\n\n + Example:\n + \_\_development:\n + \_\_\_\_sessions:\n + \_\_\_\_\_\_%{name}:\n + \_\_\_\_\_\_\_\_database: my_app_db\n + \_\_\_\_\_\_\_\_hosts:\n + \_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n" + readonly_attribute: + message: "Attempted to set the readonly attribute '%{name}' with + the value: %{value}." + summary: "Attributes flagged as readonly via Model.attr_readonly + can only have values set when the document is a new record." + resolution: "Don't define '%{name}' as readonly, or do not attempt + to update its value after the document is persisted." + readonly_document: + message: "Attempted to persist the readonly document '%{klass}'." + summary: "Documents loaded from the database using #only + cannot be persisted." + resolution: "Don't attempt to persist documents that are flagged as + readonly." + scope_overwrite: + message: "Cannot create scope :%{scope_name}, because of existing + method %{model_name}.%{scope_name}." + summary: "When defining a scope that conflicts with a method that + already exists on the model, this error will get raised if + Mongoid.scope_overwrite_exception is set to true." + resolution: "Change the name of the scope so it does not conflict + with the already defined method %{model_name}, or set the + configuration option Mongoid.scope_overwrite_exception to false, + which is its default. In this case a warning will be logged." + taken: + "exisitert bereits" + too_many_nested_attribute_records: + message: "Accepting nested attributes for %{association} is limited + to %{limit} records." + summary: "More documents were sent to be processed than the allowed + limit." + resolution: "The limit is set as an option to the macro, for example: + accepts_nested_attributes_for :%{association}, limit: %{limit}. + Consider raising this limit or making sure no more are sent than + the set value." + unknown_attribute: + message: "Attempted to set a value for '%{name}' which is not + allowed on the model %{klass}." + summary: "Without including Mongoid::Attributes::Dynamic in your model + and the attribute does not already exist in the attributes hash, + attempting to call %{klass}#%{name}= for it is not allowed. This is + also triggered by passing the attribute to any method that accepts an + attributes hash, and is raised instead of getting a NoMethodError." + resolution: "You can include Mongoid::Attributes::Dynamic if you + expect to be writing values for undefined fields often." + unsaved_document: + message: "Attempted to save %{document} before the parent %{base}." + summary: "You cannot call create or create! through the + relation (%{document}) who's parent (%{base}) is + not already saved. This would case the database to be out of sync + since the child could potentially reference a nonexistant parent." + resolution: "Make sure to only use create or create! when the parent + document %{base} is persisted." + unsupported_javascript: + message: "Executing Javascript $where selector on an embedded criteria + is not supported." + summary: "Mongoid only supports providing a hash of arguments to + #where criterion on embedded documents. Since %{klass} is embedded, + the expression %{javascript} is not allowed." + resolution: "Please provide a standard hash to #where when the criteria + is for an embedded relation." + validations: + message: "Validation of %{document} failed." + summary: "The following errors were found: %{errors}" + resolution: "Try persisting the document with valid data or remove + the validations." + delete_restriction: + message: "Cannot delete %{document} because of dependent '%{relation}'." + summary: "When defining '%{relation}' with a :dependent => :restrict, + Mongoid will raise an error when attempting to delete the + %{document} when the child '%{relation}' still has documents in it." + resolution: "Don't attempt to delete the parent %{document} when + it has children, or change the dependent option on the relation." diff --git a/config/routes.rb b/config/routes.rb index 699a23b..b2c600a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ Rails.application.routes.draw do scope '/:locale' do get '/', to: 'supporters#new' resources :supporters + resource :publicity get '/thanks', to: 'pages#thanks', as: :thanks get '/spenden', to: 'pages#spenden', as: :spenden end diff --git a/spec/factories/publicities.rb b/spec/factories/publicities.rb new file mode 100644 index 0000000..ce64e52 --- /dev/null +++ b/spec/factories/publicities.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :publicity do + organisation { Faker::Company.name } + statement { Faker::Lorem.paragraph } + avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") } + end +end \ No newline at end of file diff --git a/spec/factories/supporters.rb b/spec/factories/supporters.rb new file mode 100644 index 0000000..3945f77 --- /dev/null +++ b/spec/factories/supporters.rb @@ -0,0 +1,14 @@ +FactoryGirl.define do + factory :supporter do + email { Faker::Internet.email } + password { Faker::Lorem.words(8).join } + first_name { Faker::Name.first_name } + last_name { Faker::Name.last_name } + street { Faker::Address.street_name } + zip { Faker::Address.zip } + city { Faker::Address.city } + support { %w(signer supporter).sample } + age_category { %w(underage young middle retired).sample } + language { %w(de fr it).sample } + end +end \ No newline at end of file diff --git a/spec/features/publicity_spec.rb b/spec/features/publicity_spec.rb new file mode 100644 index 0000000..d924069 --- /dev/null +++ b/spec/features/publicity_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +feature 'Publicity' do + let(:supporter) { create :supporter } + + before { sign_in(supporter) } + + scenario 'User makes his announcement public' do + visit root_path + + click_link 'Meine Unterstützung öffentlich kundtun ...' + + fill_in 'Organisation', with: 'Schweizer Volkspartei' + fill_in 'Statement', with: 'Wir wollen ja eigentlich nur das Volk verarschen ;)' + + attach_file('publicity_avatar', "#{Rails.root}/spec/support/fixtures/image.jpg") + + click_button 'Zur Überprüfung einsenden' + + expect(page).to have_content 'Besten Dank die Daten werden überprüft.' + end + + scenario 'User makes changes announcement' do + + create :publicity, supporter: supporter + + visit root_path + + click_link 'Statement neu einreichen' + + fill_in 'Organisation', with: 'Schweizer Volkspartei' + fill_in 'Statement', with: 'Wir wollen ja eigentlich nur das Volk verarschen ;)' + + attach_file('publicity_avatar', "#{Rails.root}/spec/support/fixtures/image.jpg") + + click_button 'Zur Überprüfung einsenden' + + expect(page).to have_content 'Besten Dank die Daten werden überprüft.' + expect(page).to have_content 'Die Veröffentlichung wurde noch nicht genehmigt' + end +end \ No newline at end of file diff --git a/spec/features/support_spec.rb b/spec/features/support_spec.rb index c1bee31..93eacc0 100644 --- a/spec/features/support_spec.rb +++ b/spec/features/support_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Support announcement' do +feature 'Support' do scenario 'User announces support' do visit root_path diff --git a/spec/models/publicity_spec.rb b/spec/models/publicity_spec.rb new file mode 100644 index 0000000..a2c8107 --- /dev/null +++ b/spec/models/publicity_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +describe Publicity do + it { is_expected.to be_embedded_in(:supporter) } + + it { is_expected.to validate_presence_of(:state) } + it { is_expected.to validate_presence_of(:statement) } + it { is_expected.to validate_presence_of(:avatar) } +end diff --git a/spec/models/supporter_spec.rb b/spec/models/supporter_spec.rb index 22d84c1..5701bd1 100644 --- a/spec/models/supporter_spec.rb +++ b/spec/models/supporter_spec.rb @@ -12,6 +12,8 @@ describe Supporter do it { is_expected.to validate_presence_of(:age_category) } it { is_expected.to validate_presence_of(:language) } + it { is_expected.to embed_one(:publicity) } + describe '.counter' do it 'counts only from a certain number on' do allow(Supporter).to receive(:count) { 12 } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e2cc4a..e138af6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,16 @@ Bundler.require(*Rails.groups) RSpec.configure do |config| config.include Mongoid::Matchers, type: :model + config.include FactoryGirl::Syntax::Methods + + config.before(:suite) do + FactoryGirl.find_definitions + end + + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::ControllerHelpers, type: :view + config.include Devise::Test::IntegrationHelpers, type: :feature + # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/fixtures/image.jpg b/spec/support/fixtures/image.jpg new file mode 100644 index 0000000..0d3db6e Binary files /dev/null and b/spec/support/fixtures/image.jpg differ