diff --git a/CHANGELOG.md b/CHANGELOG.md index e3d75a10b..77d349fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog Fab Manager - Refactored subscriptions to keep track of the previous ones +- Refactored settings to keep track of the previous values (notably VAT rate) - Improved automated tests suite -- Added Rubocop gem to the Gemfile +- Added Rubocop gem to the Gemfile (ruby syntax checking) - Fix a security update: dependency ActiveJob < 4.2.11 has a vulnerability as described in [CVE-2018-16476](https://nvd.nist.gov/vuln/detail/CVE-2018-16476) - [TODO DEPLOY] `rake db:migrate` - [TODO DEPLOY] `bundle install` diff --git a/README.md b/README.md index a7c4dea8f..9ffb2e03f 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ This can be achieved doing the following: - `app/controllers/api/members_controllers.rb@search` is using `f_unaccent()` (see above) and `regexp_replace()` - `db/migrate/20150604131525_add_meta_data_to_notifications.rb` is using [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html), a PostgreSQL 9.4+ datatype. - `db/migrate/20160915105234_add_transformation_to_o_auth2_mapping.rb` is using [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html), a PostgreSQL 9.4+ datatype. + - `db/migrate/20181217103441_migrate_settings_value_to_history_values.rb` is using `SELECT DISTINCT ON`. - If you intend to contribute to the project code, you will need to run the test suite with `rake test`. This also requires your user to have the _SUPERUSER_ role. Please see the [known issues](#known-issues) section for more information about this. @@ -520,14 +521,14 @@ Developers may find information on how to implement their own authentication pro Error: ... ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "..." violates foreign key constraint "fk_rails_..." - DETAIL: Key (group_id)=(1) is not present in table "groups". + DETAIL: Key (group_id)=(1) is not present in table "...". : ... test_after_commit (1.0.0) lib/test_after_commit/database_statements.rb:11:in `block in transaction' test_after_commit (1.0.0) lib/test_after_commit/database_statements.rb:5:in `transaction' This is due to an ActiveRecord behavior witch disable referential integrity in PostgreSQL to load the fixtures. PostgreSQL will prevent any users to disable referential integrity on the fly if they doesn't have the `SUPERUSER` role. - To fix that, logon as the `postgres` user and run the PostgreSQL shell (see [Setup the FabManager database in PostgreSQL](#setup-fabmanager-in-postgresql) for an example). + To fix that, logon as the `postgres` user and run the PostgreSQL shell (see [the dedicated section](#run-postgresql-cli) for instructions). Then, run the following command (replace `sleede` with your test database user, as specified in your database.yml): ALTER ROLE sleede WITH SUPERUSER; diff --git a/app/models/stylesheet.rb b/app/models/stylesheet.rb index f8aaeebd6..d3f1f62c7 100644 --- a/app/models/stylesheet.rb +++ b/app/models/stylesheet.rb @@ -2,6 +2,8 @@ class Stylesheet < ActiveRecord::Base validates_presence_of :contents def rebuild! + return unless Stylesheet.primary && Stylesheet.secondary + update(contents: Stylesheet.css) end diff --git a/db/migrate/20160830154719_migrate_event_reduced_amount_to_price_category.rb b/db/migrate/20160830154719_migrate_event_reduced_amount_to_price_category.rb index c323b3037..c919fd739 100644 --- a/db/migrate/20160830154719_migrate_event_reduced_amount_to_price_category.rb +++ b/db/migrate/20160830154719_migrate_event_reduced_amount_to_price_category.rb @@ -1,25 +1,25 @@ class MigrateEventReducedAmountToPriceCategory < ActiveRecord::Migration def up pc = PriceCategory.new( - name: I18n.t('price_category.reduced_fare'), - conditions: I18n.t('price_category.reduced_fare_if_you_are_under_25_student_or_unemployed') + name: I18n.t('price_category.reduced_fare'), + conditions: I18n.t('price_category.reduced_fare_if_you_are_under_25_student_or_unemployed') ) pc.save! Event.where.not(reduced_amount: nil).each do |event| - unless event.reduced_amount == 0 and event.amount == 0 + unless event.reduced_amount.zero? && event.amount.zero? epc = EventPriceCategory.new( - event: event, - price_category: pc, - amount: event.reduced_amount + event: event, + price_category: pc, + amount: event.reduced_amount ) epc.save! Reservation.where(reservable_type: 'Event', reservable_id: event.id).where('nb_reserve_reduced_places > 0').each do |r| t = Ticket.new( - reservation: r, - event_price_category: epc, - booked: r.nb_reserve_reduced_places + reservation: r, + event_price_category: epc, + booked: r.nb_reserve_reduced_places ) t.save! end diff --git a/db/migrate/20181217103441_migrate_settings_value_to_history_values.rb b/db/migrate/20181217103441_migrate_settings_value_to_history_values.rb index 20745eefb..3a833b3f7 100644 --- a/db/migrate/20181217103441_migrate_settings_value_to_history_values.rb +++ b/db/migrate/20181217103441_migrate_settings_value_to_history_values.rb @@ -2,21 +2,25 @@ class MigrateSettingsValueToHistoryValues < ActiveRecord::Migration def up user = User.admins.first Setting.all.each do |setting| - HistoryValue.create!( + hv = HistoryValue.new( setting: setting, user: user, - value: setting.value + value: setting['value'] ) + hv.save! end end def down - # PostgreSQL only + # PostgreSQL only (distinct on) values = execute("SELECT DISTINCT ON (setting_id) setting_id, value, created_at FROM #{HistoryValue.arel_table.name} ORDER BY setting_id, created_at DESC, value") values.each do |val| - Setting.find(val['setting_id']).update_attributes(value: val['value']) + value = val['value'] ? val['value'].tr("'", '"') : '' + execute("UPDATE settings + SET value = '#{value}' + WHERE id = #{val['setting_id']}") end end end