Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
ADD tests for preview, require and read only
Browse files Browse the repository at this point in the history
  • Loading branch information
marco panzeri committed Aug 29, 2018
1 parent bff62e5 commit 06804e3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
54 changes: 34 additions & 20 deletions spec/models/binda/field_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,31 +263,45 @@ module Binda
expect(first_field_setting.reload.position).to eq 2
end

it "isn't read only by default" do
pending("not implemented yet")
end

it "can be read only" do
pending("not implemented yet")
end

FieldSetting.get_field_classes.each do |field_class|
it "#{field_class} isn't read only by default" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
expect(first_field_setting.read_only?).to be(false)
end

it "hasn't a preview by default" do
pending("not implemented yet")
end
it "#{field_class} can be read only" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
first_field_setting.read_only = true
expect(first_field_setting.save).to be true
end

it "can have a preview" do
pending("not implemented yet")
end
it "#{field_class} hasn't a preview by default" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
expect(first_field_setting.has_preview?).to be(false)
end

it "#{field_class} can have a preview" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
first_field_setting.has_preview = true
expect(first_field_setting.save).to be true
end

it "isn't required by default" do
pending("not implemented yet")
end
it "#{field_class} isn't required by default" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
expect(first_field_setting.required?).to be(false)
end

it "can be required" do
pending("not implemented yet")
it "#{field_class} can be required" do
first_field_setting = create(:field_setting,
field_type: field_class.underscore)
first_field_setting.required = true
expect(first_field_setting.save).to be true
end
end

end
end
41 changes: 41 additions & 0 deletions spec/models/binda/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,46 @@ module Binda
it "registers details if you call register_details method (also in rake task)" do
skip("don't know how to test it")
end

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)
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)
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_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)
end
end
end
end
end

1 comment on commit 06804e3

@a-barbieri
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Marco @thauma9, fai un fork di Binda e di questo branch piuttosto che lavorare sul repo ufficiale.

Una volta pronto il codice puoi fare una pull request e se tutto è ok lo mettiamo sul questo repo.

Meno cose sono presenti sul repo ufficiale più è semplice tenerlo ordinato.

Please sign in to comment.