Add validation on field name in data_bundle, write a few tests for it
diff --git a/app/models/data_bundle.rb b/app/models/data_bundle.rb
index 3fbd5c8..34a096d 100644
--- a/app/models/data_bundle.rb
+++ b/app/models/data_bundle.rb
@@ -23,7 +23,7 @@
belongs_to :user
- validates :user_id, :file, presence: true
+ validates :name, :user_id, :file, presence: true
after_create :extract_file
diff --git a/spec/feature/data_bundles_spec.rb b/spec/feature/data_bundles_spec.rb
index 52d6ac2..d6f29b6 100644
--- a/spec/feature/data_bundles_spec.rb
+++ b/spec/feature/data_bundles_spec.rb
@@ -30,15 +30,25 @@
visit data_bundles_path
end
- it 'can upload new databundles' do
- name = Faker::Lorem.sentence
- expect {
- fill_in 'data_bundle_name', with: name
- attach_file 'data_bundle_file', "#{Rails.root}/spec/fixtures/hello_anyone.zip"
- click_button 'save_data_bundle'
- }.to change(DataBundle, :count).by(1)
- visit data_bundles_path
- expect(page).to have_content name
+ context 'create' do
+ it 'with file and name - ok' do
+ name = Faker::Lorem.sentence
+ expect {
+ fill_in 'data_bundle_name', with: name
+ attach_file 'data_bundle_file', "#{Rails.root}/spec/fixtures/hello_anyone.zip"
+ click_button 'save_data_bundle'
+ }.to change(DataBundle, :count).by(1)
+ visit data_bundles_path
+ expect(page).to have_content name
+ end
+
+ it 'without file - error' do
+ expect {
+ click_button 'save_data_bundle'
+ }.not_to change(DataBundle, :count)
+ expect(current_path).to eq data_bundles_path
+ expect(page).to have_css 'div#error_explanation'
+ end
end
it 'can see the databundles' do
@@ -54,14 +64,28 @@
expect(page).to have_content data_bundle.name
end
- it 'edit databundle' do
- click_link "to_edit_#{data_bundle.id}"
- new_name = Faker::Lorem.sentence
- expect {
- fill_in 'data_bundle_name', with: new_name
- click_button 'save_data_bundle'
- }.not_to change(DataBundle, :count)
- expect(page).to have_content new_name
+ context 'edit' do
+ before do
+ click_link "to_edit_#{data_bundle.id}"
+ end
+
+ it 'change name - ok' do
+ new_name = Faker::Lorem.sentence
+ expect {
+ fill_in 'data_bundle_name', with: new_name
+ click_button 'save_data_bundle'
+ }.not_to change(DataBundle, :count)
+ expect(page).to have_content new_name
+ end
+
+ it 'with empty name - error' do
+ expect {
+ fill_in 'data_bundle_name', with: ''
+ click_button 'save_data_bundle'
+ }.not_to change(DataBundle, :count)
+ expect(page).to have_css 'div#error_explanation'
+ expect(current_path).to eq data_bundle_path(data_bundle.id)
+ end
end
it 'delete databundle', js: true do