add scenic gem, teams datatables sql view

This commit is contained in:
zmagod 2017-10-26 16:59:00 +02:00
parent be2c3b807f
commit 3d22a5404d
13 changed files with 693 additions and 649 deletions

View file

@ -66,6 +66,7 @@ gem 'delayed_paperclip',
gem 'rubyzip'
gem 'jbuilder' # JSON structures via a Builder-style DSL
gem 'activerecord-import'
gem 'scenic', '~> 1.4'
gem 'paperclip', '~> 5.1' # File attachment, image attachment library
gem 'aws-sdk', '~> 2'

View file

@ -415,6 +415,9 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
scenic (1.4.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
scss_lint (0.55.0)
rake (>= 0.9, < 13)
sass (~> 3.4.20)
@ -562,6 +565,7 @@ DEPENDENCIES
rubyzip
sanitize (~> 4.4)
sass-rails (~> 5.0.6)
scenic (~> 1.4)
scss_lint
sdoc (~> 0.4.0)
selenium-webdriver

View file

@ -4,8 +4,9 @@ module ClientApi
include ClientApi::Users::UserTeamsHelper
def index
teams = current_user.datatables_teams
success_response(template: '/client_api/teams/index',
locals: { teams: current_user.teams_data })
locals: { teams: teams })
end
def create

View file

@ -0,0 +1,12 @@
module Datatables
class DatatablesTeam < ApplicationRecord
belongs_to :user
private
# this isn't strictly necessary, but it will prevent
# rails from calling save, which would fail anyway.
def readonly?
true
end
end
end

View file

@ -198,6 +198,7 @@ class User < ApplicationRecord
has_many :user_notifications, inverse_of: :user
has_many :notifications, through: :user_notifications
has_many :zip_exports, inverse_of: :user, dependent: :destroy
has_many :datatables_teams, class_name: '::Datatables::DatatablesTeam'
# If other errors besides parameter "avatar" exist,
# they will propagate to "avatar" also, so remove them

View file

@ -1,11 +1,10 @@
json.teams do
json.collection teams do |team|
json.id team.fetch('id')
json.name team.fetch('name')
json.members team.fetch('members')
json.role retrive_role_name(team.fetch('role') { nil })
json.current_team team.fetch('current_team')
json.can_be_leaved team.fetch('can_be_leaved')
json.user_team_id team.fetch('user_team_id')
json.array teams do |team|
json.id team.id
json.name team.name
json.members team.members
json.role retrive_role_name(team.role)
json.can_be_leaved team.can_be_leaved
json.user_team_id team.user_team_id
end
end

View file

@ -0,0 +1,5 @@
class CreateDatatablesTeams < ActiveRecord::Migration[5.0]
def change
create_view :datatables_teams
end
end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
SELECT
teams.id AS id,
teams.name AS name,
user_teams.role AS role,
(
SELECT COUNT(*)
FROM user_teams
WHERE user_teams.team_id = teams.id
) AS members,
CASE WHEN teams.created_by_id = user_teams.user_id THEN false ELSE true END AS can_be_leaved,
user_teams.id AS user_team_id,
user_teams.user_id AS user_id
FROM teams INNER JOIN user_teams ON teams.id=user_teams.team_id

View file

@ -1,6 +1,5 @@
FactoryGirl.define do
factory :my_module_group do
name Faker::Name.unique.name
experiment { Experiment.first || create(:experiment_two) }
end
end

View file

@ -0,0 +1,22 @@
require 'rails_helper'
RSpec.describe Datatables::DatatablesTeam, type: :model do
describe 'Database table' do
it { should have_db_column :id }
it { should have_db_column :name }
it { should have_db_column :members }
it { should have_db_column :role }
it { should have_db_column :user_team_id }
it { should have_db_column :user_id }
end
describe 'is readonly' do
let(:user) { create :user }
it do
expect {
Datatables::DatatablesTeam.create!(user_id: user.id)
}.to raise_error(ActiveRecord::ReadOnlyRecord,
'Datatables::DatatablesTeam is marked as readonly')
end
end
end

View file

@ -7,7 +7,6 @@ describe MyModuleGroup, type: :model do
describe 'Database table' do
it { should have_db_column :id }
it { should have_db_column :name }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
it { should have_db_column :created_by_id }
@ -21,8 +20,6 @@ describe MyModuleGroup, type: :model do
end
describe 'Should be a valid object' do
it { should validate_presence_of :name }
it { should validate_presence_of :experiment }
it { should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
end
end

View file

@ -18,6 +18,7 @@ require 'simplecov'
require 'faker'
require 'active_record'
require 'bullet'
require 'json_matchers/rspec'
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate