Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions app/models/concerns/binda/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

class ReadOnlyValidator < ActiveModel::Validator
def validate(record)
=begin
binding.pry
=end
=begin
get field setting of current record
return false if field setting has been set to read only
else true
=end

=begin
!record.read_only?
=end
field_setting = record.field_setting
unless !field_setting.read_only?
record.errors.add :base, "#{field_setting.name} can't be saved because is read only"
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# by default. You can change it below and use your own secret key.
# config.secret_key = 'a8395fa034e067da620d70f7f39ad4765d163e44ce05d5c243393e1bbfdc10f9a464aaf34fcac3291a6746424ea2b9f9564a01c31820e28bf1737c16d139cd5c'
# binda.hook.1
config.secret_key = 'b92bf46fe2bb9554025eaaa638e127a97958df22e965fbc4cc065e0b47abdcd63029442b5714b2824784f3149a585cf5c7bf5a6c73cbb2f5a167b75180ec0fe2'
config.secret_key = '313e57d2d67e59f42e491610d4593cbe30c791d460ad7f008c3196dfa1bcc6f0d93ca1033e406cf7e12cf7f8df15b5fe330622e0b917ff343616dd9dd52d1e65'

# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
Expand Down Expand Up @@ -114,7 +114,7 @@
# Set up a pepper to generate the hashed password.
# config.pepper = '124ef1b08a92f891a392a9594b868887c945ca8438bd7852f8ac4d91e51f2cc699b8b6c7b12057c0f0e6dc03d04f8ee4eab72278b0f948e2c1e43f8b449c2262'
# binda.hook.2
config.pepper = 'fb7dd6ba2c94638fdf2c4500f44788e7d491b9cb985be333f6c2c83514ce6759cab1e05ba9e02cb568231239f8054878984d1670bb269162f0139c402340de12'
config.pepper = 'c857c3157d1be8433dd0308964f567beed5b1a774fe0c587ed5579b2e8be0ed0eb7ad1f2722dcdc198a1ff344c4a1bdf2e0ebaac9e86ff936187b7756ccc5fca'

# Send a notification email when the user's password is changed
# config.send_password_change_notification = false
Expand Down
46 changes: 46 additions & 0 deletions spec/models/binda/audio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,51 @@ module Binda
expect(audio_record.content_type).to eq 'audio/mpeg'
expect(audio_record.file_size).to be_within(100000).of(400000) # audio is 300kb
end

describe "when is read only" do
it "blocks any upload" do
@audio_setting.read_only = true
@audio_setting.save!
expect(@audio_setting.reload.read_only).to be(true)
audio_name = 'test-audio.mp3'
audio_path = ::Binda::Engine.root.join('spec', 'support', audio_name)
audio_record = @component.reload.audios.first
audio_record.audio = audio_path.open
expect{ audio_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
describe "when there is already a image" do
it "avoid audio to be deleted" do
audio_name = 'test-audio.mp3'
audio_path = ::Binda::Engine.root.join('spec', 'support', audio_name)
audio_record = @component.reload.audios.first
audio_record.audio = audio_path.open
expect(audio_record.save!).to be_truthy
@audio_setting.read_only = true
@audio_setting.save!
expect(@audio_setting.reload.read_only).to be(true)
audio_name = 'test-audio.mp3'
audio_path = ::Binda::Engine.root.join('spec', 'support', audio_name)
audio_record = @component.reload.audios.first
audio_record.audio = audio_path.open
audio_record.remove_audio
expect{ audio_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
it "blocks any update" do
audio_name = 'test-audio.mp3'
audio_path = ::Binda::Engine.root.join('spec', 'support', audio_name)
audio_record = @component.reload.audios.first
audio_record.audio = audio_path.open
expect(audio_record.save!).to be_truthy
@audio_setting.read_only = true
@audio_setting.save!
expect(@audio_setting.reload.read_only).to be(true)
audio_name = 'test-audio.mp3'
audio_path = ::Binda::Engine.root.join('spec', 'support', audio_name)
audio_record = @component.reload.audios.first
audio_record.audio = audio_path.open
expect{ audio_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
end
end
end
end
25 changes: 15 additions & 10 deletions spec/models/binda/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,46 @@ module Binda

describe "when is read only" do
it "blocks any upload" do
@component = create(:component)
@image_setting = create(:image_setting, field_group_id: @component.structure.field_groups.first.id)
@image_setting.read_only = true
image_name = 'test-image.jpg'
image_path = ::Binda::Engine.root.join('spec', 'support', image_name)
image_record = @component.reload.images.first
image_record.image = image_path.open
expect(image_record.save!).to be(false)
@image_setting.read_only = true
@image_setting.save!
expect(@image_setting.reload.read_only).to be(true)
expect{ image_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
describe "when there is already a image" do
it "avoid image to be deleted" do
@component = create(:component)
@image_setting = create(:image_setting, field_group_id: @component.structure.field_groups.first.id)
image_name = 'test-image.jpg'
image_path = ::Binda::Engine.root.join('spec', 'support', image_name)
image_record = @component.reload.images.first
image_record.image = image_path.open
expect(image_record.save!).to be_truthy
@image_setting.read_only = true
expect(image_record.image.remove!).to be(false)
@image_setting.save!
expect(@image_setting.reload.read_only).to be(true)
image_name = 'test-image.jpg'
image_path = ::Binda::Engine.root.join('spec', 'support', image_name)
image_record = @component.reload.images.first
image_record.image = image_path.open
image_record.remove_image
expect{ image_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
it "blocks any update" do
@component = create(:component)
@image_setting = create(:image_setting, field_group_id: @component.structure.field_groups.first.id)
image_name = 'test-image.jpg'
image_path = ::Binda::Engine.root.join('spec', 'support', image_name)
image_record = @component.reload.images.first
image_record.image = image_path.open
expect(image_record.save!).to be_truthy
@image_setting.read_only = true
@image_setting.save!
expect(@image_setting.reload.read_only).to be(true)
image_name = 'test-image.jpg'
image_path = ::Binda::Engine.root.join('spec', 'support', image_name)
image_record = @component.reload.images.first
image_record.image = image_path.open
expect(image_record.save!).to be(false)
expect{ image_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/models/binda/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ module Binda
radio = @component.radios.first
radio.choices.clear
@radio_setting.read_only = true

@radio_setting.save!
expect(@radio_setting.reload.read_only).to be(true)
radio.choices << @radio_setting.choices.first
expect( radio.choices.first.id ).to be( nil )
expect{ radio.save! }.to raise_error ActiveRecord::RecordInvalid
end

end
Expand Down
88 changes: 68 additions & 20 deletions spec/models/binda/svg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,77 @@

module Binda
RSpec.describe Svg, type: :model do
include CarrierWave::Test::Matchers

before(:context) do
SvgUploader.enable_processing = true
end
include CarrierWave::Test::Matchers

before(:example) do
@component = create(:component)
@svg_setting = create(:svg_setting, field_group_id: @component.structure.field_groups.first.id)
end
before(:context) do
SvgUploader.enable_processing = true
end

after(:context) do
SvgUploader.enable_processing = false
end
before(:example) do
@component = create(:component)
@svg_setting = create(:svg_setting, field_group_id: @component.structure.field_groups.first.id)
end

after(:context) do
SvgUploader.enable_processing = false
end

it "stores content_type and file size" do
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
expect(svg_record.save!).to be_truthy
expect(svg_record.content_type).to eq 'svg/svg+xml'
expect(svg_record.file_size).to be_within(400).of(600) # audio is 300kb
end

describe "when is read only" do
it "blocks any upload" do
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
@svg_setting.read_only = true
@svg_setting.save!
expect(@svg_setting.reload.read_only).to be(true)
expect{ svg_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
describe "when there is already a svg" do
it "avoid svg to be deleted" do
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
expect(svg_record.save!).to be_truthy
@svg_setting.read_only = true
@svg_setting.save!
expect(@svg_setting.reload.read_only).to be(true)
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
svg_record.remove_svg
expect{ svg_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
it "blocks any update" do
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
expect(svg_record.save!).to be_truthy
@svg_setting.read_only = true
@svg_setting.save!
expect(@svg_setting.reload.read_only).to be(true)
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
expect{ svg_record.save! }.to raise_error ActiveRecord::RecordInvalid
end
end
end

it "stores content_type and file size" do
svg_name = 'test-svg.svg'
svg_path = ::Binda::Engine.root.join('spec', 'support', svg_name)
svg_record = @component.reload.svgs.first
svg_record.svg = svg_path.open
expect(svg_record.save!).to be_truthy
expect(svg_record.content_type).to eq 'image/svg+xml'
expect(svg_record.file_size).to be_within(400).of(600) # audio is 300kb
end
end
end