bit_core 1.2.2 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dc65a6336c3fbf1b6f52e199fcabba11d8de689
4
- data.tar.gz: 0bce9de93ebeca1748aabfe663f81c154b3c807e
3
+ metadata.gz: 991b3c0c91e0767d75b53eedd8651564d1052b34
4
+ data.tar.gz: 03a383080f938a4e459e05c82b88eaf59d9e75d0
5
5
  SHA512:
6
- metadata.gz: b75787f8d115b7b5e00407dca882948b6b4679dd3e48797c694921d073ee9f65d94b3b55d8bf1f003de8a3f3aee5105e5efb6bbe87b3b492d66b19104b69dec8
7
- data.tar.gz: 39b70d596a1d230bd64d1242a6d48519e747257a3c45b451c3afa4aed09795eaaaf3e438468d47893c03679049f5bdaf4d9533bb3abe8a94009bcdd8dd8eec78
6
+ metadata.gz: 70d02c6df793095ae7d65b2da1b6f90d107f56cbdd068313726d4d126b96e7c9cd5aafa451406ac6f586a5be81b29c36ec304eddee07928b5cff29f5acdedc54
7
+ data.tar.gz: b2e710249bf82545686a53772e23d435ddcfa380fdcc625bdd3776079492a6dadb7692927eee04d701c1919bffe3ec3e98945b4427a258778bca0aa7329b82c9
data/README.md CHANGED
@@ -1,4 +1,22 @@
1
- Run specs
1
+ ## Installation
2
2
 
3
- bin/rake app:db:drop app:db:create app:db:migrate RAILS_ENV=test
4
- bin/rspec
3
+ In order to run migrations, you will need to create a 'schema.rb' file (it is in the .gitignore).
4
+ ```console
5
+ touch spec/dummy/db/schema.rb
6
+ ```
7
+
8
+ ## Dependencies
9
+ The host application will need to specify an Arm class 'app/models/arm.rb'
10
+ ```ruby
11
+ # app/models/arm.rb
12
+ class Arm
13
+ ...
14
+ end
15
+ ```
16
+
17
+ ## Running Specs
18
+
19
+ ```console
20
+ bin/rake app:db:drop app:db:create app:db:migrate RAILS_ENV=test
21
+ bin/rspec
22
+ ```
data/Rakefile CHANGED
@@ -16,6 +16,6 @@ require "rspec/core"
16
16
  require "rspec/core/rake_task"
17
17
 
18
18
  desc "Run all specs in spec directory (excluding plugin specs)"
19
- RSpec::Core::RakeTask.new(:spec => "app:db:test:prepare")
19
+ RSpec::Core::RakeTask.new(:spec)
20
20
 
21
21
  task default: :spec
@@ -0,0 +1,6 @@
1
+ module BitCore
2
+ # A Slide with audio content.
3
+ class AudioSlide < Slide
4
+ serialize :options
5
+ end
6
+ end
@@ -62,6 +62,7 @@ module BitCore
62
62
  "unable to find class '#{ data_class_name }'")
63
63
  end
64
64
 
65
+ # rubocop:disable Metrics/AbcSize
65
66
  def data_attributes_exist
66
67
  return unless data_attributes
67
68
  attr_names = data_class.try(:attribute_names) || []
@@ -71,7 +72,8 @@ module BitCore
71
72
  return if unknown_attrs.count == 0
72
73
 
73
74
  errors.add(:data_attributes, "must be attributes on the model class " \
74
- "(unrecognized: #{ unknown_attrs.join(", ") })")
75
+ "(unrecognized: #{ unknown_attrs.join(', ') })")
75
76
  end
77
+ # rubocop:enable Metrics/AbcSize
76
78
  end
77
79
  end
@@ -3,7 +3,7 @@ module BitCore
3
3
  # Defines presentation logic for a Slideshow.
4
4
  class SlideshowProvider < BitCore::ContentProvider
5
5
  def slideshow
6
- source_content
6
+ source_content || Slideshow.new
7
7
  end
8
8
 
9
9
  def render_current(options)
@@ -28,11 +28,11 @@ module BitCore
28
28
  true
29
29
  end
30
30
 
31
- def add_or_update_slideshow(title)
31
+ def add_or_update_slideshow(title, arm_id = nil)
32
32
  if source_content
33
33
  source_content.update(title: title)
34
34
  else
35
- slideshow = BitCore::Slideshow.create(title: title)
35
+ slideshow = BitCore::Slideshow.create(arm_id: arm_id, title: title)
36
36
  update(source_content: slideshow)
37
37
  end
38
38
 
@@ -12,6 +12,8 @@ module BitCore
12
12
  validates :position, numericality: { greater_than_or_equal_to: 1 }
13
13
  validates :position, uniqueness: { scope: :bit_core_slideshow_id }
14
14
 
15
+ after_destroy :update_slide_positions
16
+
15
17
  def render_body
16
18
  return "" if body.nil?
17
19
 
@@ -23,5 +25,12 @@ module BitCore
23
25
  space_after_headers: true
24
26
  ).render(body).html_safe
25
27
  end
28
+
29
+ private
30
+
31
+ def update_slide_positions
32
+ slideshow.reload
33
+ .sort(slideshow.slide_ids)
34
+ end
26
35
  end
27
36
  end
@@ -3,6 +3,8 @@ require "redcarpet"
3
3
  module BitCore
4
4
  # A collection of ordered Slides.
5
5
  class Slideshow < ActiveRecord::Base
6
+ belongs_to :arm
7
+
6
8
  has_many :slides,
7
9
  -> { order "position" },
8
10
  class_name: "BitCore::Slide",
@@ -13,7 +15,7 @@ module BitCore
13
15
  as: :source_content,
14
16
  dependent: :nullify
15
17
 
16
- validates :title, presence: true
18
+ validates :arm_id, :title, presence: true
17
19
 
18
20
  accepts_nested_attributes_for :slides
19
21
 
@@ -1,16 +1,18 @@
1
1
  module BitCore
2
2
  # A section of an application.
3
3
  class Tool < ActiveRecord::Base
4
+ belongs_to :arm
5
+
4
6
  has_many :content_modules,
5
7
  class_name: "BitCore::ContentModule",
6
8
  foreign_key: :bit_core_tool_id,
7
9
  inverse_of: :tool,
8
10
  dependent: :destroy
9
11
 
10
- validates :title, :position, presence: true
12
+ validates :arm, :position, :title, presence: true
11
13
  validates :position,
12
- uniqueness: true,
13
- numericality: { greater_than_or_equal_to: 0 }
14
+ numericality: { greater_than_or_equal_to: 0 },
15
+ uniqueness: { scope: :arm_id }
14
16
 
15
17
  def add_module(title_or_module)
16
18
  if title_or_module.class == String
@@ -0,0 +1,10 @@
1
+ class CreateBitCoreArms < ActiveRecord::Migration
2
+ def change
3
+ create_table :arms do |t|
4
+ t.string :title
5
+ t.boolean :is_social
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ class AddArmIdToBitCoreSlideshows < ActiveRecord::Migration
2
+ def change
3
+ add_column :bit_core_slideshows, :arm_id, :integer, null: false
4
+
5
+ reversible do |dir|
6
+ dir.up do
7
+ # add foreign key constaint
8
+ execute <<-SQL
9
+ ALTER TABLE bit_core_slideshows
10
+ ADD CONSTRAINT fk_bit_core_slideshows_arms
11
+ FOREIGN KEY (arm_id)
12
+ REFERENCES arms(id)
13
+ SQL
14
+ end
15
+
16
+ dir.down do
17
+ # remove foreign key constaint
18
+ execute <<-SQL
19
+ ALTER TABLE bit_core_slideshows
20
+ DROP CONSTRAINT fk_bit_core_slideshows_arms
21
+ SQL
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ class AddArmIdToBitCoreTools < ActiveRecord::Migration
2
+ def change
3
+ add_column :bit_core_tools, :arm_id, :integer, null: false
4
+
5
+ reversible do |dir|
6
+ dir.up do
7
+ # add foreign key constaint
8
+ execute <<-SQL
9
+ ALTER TABLE bit_core_tools
10
+ ADD CONSTRAINT fk_bit_core_tools_arms
11
+ FOREIGN KEY (arm_id)
12
+ REFERENCES arms(id)
13
+ SQL
14
+ end
15
+
16
+ dir.down do
17
+ # remove foreign key constaint
18
+ execute <<-SQL
19
+ ALTER TABLE bit_core_tools
20
+ DROP CONSTRAINT fk_bit_core_tools_arms
21
+ SQL
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class AddTypeToTools < ActiveRecord::Migration
2
+ def change
3
+ add_column :bit_core_tools, :type, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddIsVizToContentModules < ActiveRecord::Migration
2
+ def change
3
+ add_column :bit_core_content_modules, :is_viz, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ class AddToolConstraint < ActiveRecord::Migration
2
+ def change
3
+ BitCore::Tool.all.each do |t|
4
+ t.destroy! if t.arm.nil?
5
+ end
6
+
7
+ reversible do |dir|
8
+ dir.up do
9
+ execute <<-SQL
10
+ ALTER TABLE bit_core_tools
11
+ ADD CONSTRAINT fk_tools_arms
12
+ FOREIGN KEY (arm_id)
13
+ REFERENCES arms(id)
14
+ SQL
15
+ end
16
+
17
+ dir.down do
18
+ execute <<-SQL
19
+ ALTER TABLE bit_core_tools
20
+ DROP CONSTRAINT IF EXISTS fk_tools_arms
21
+ SQL
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,4 @@
1
1
  # nodoc
2
2
  module BitCore
3
- VERSION = "1.2.2"
3
+ VERSION = "1.4.5"
4
4
  end
@@ -58,7 +58,6 @@ development:
58
58
  test:
59
59
  <<: *default
60
60
  database: dummy_test
61
- username: postgres
62
61
 
63
62
  # As with config/secrets.yml, you never want to store sensitive information,
64
63
  # like your database password, in your source code. If your source code is