You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by al...@apache.org on 2015/08/24 13:42:12 UTC

[46/50] [abbrv] incubator-taverna-databundle-viewer git commit: Add validation on field name in data_bundle, write a few tests for it

Add validation on field name in data_bundle, write a few tests for it


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/commit/d4033058
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/tree/d4033058
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/diff/d4033058

Branch: refs/heads/master
Commit: d4033058ea5004e8ecea08298dba8d575370dbd5
Parents: 07b6647
Author: Denis Karyakin <sa...@gmail.com>
Authored: Thu Aug 20 16:33:18 2015 +0300
Committer: Denis Karyakin <sa...@gmail.com>
Committed: Thu Aug 20 16:33:18 2015 +0300

----------------------------------------------------------------------
 app/models/data_bundle.rb         |  2 +-
 spec/feature/data_bundles_spec.rb | 58 ++++++++++++++++++++++++----------
 2 files changed, 42 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/d4033058/app/models/data_bundle.rb
----------------------------------------------------------------------
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 @@ class DataBundle < ActiveRecord::Base
 
   belongs_to :user
 
-  validates :user_id, :file, presence: true
+  validates :name, :user_id, :file, presence: true
 
   after_create :extract_file
 

http://git-wip-us.apache.org/repos/asf/incubator-taverna-databundle-viewer/blob/d4033058/spec/feature/data_bundles_spec.rb
----------------------------------------------------------------------
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 @@ RSpec.describe 'DataBundles', type: :feature do
       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 @@ RSpec.describe 'DataBundles', type: :feature do
       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