From 32c8b9cdcd2126a94cb4b1925e248d9a5dadb6fe Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 8 Aug 2014 10:54:10 +1000 Subject: [PATCH] Switch Taxons input over to category selection on BPE, clean up interface --- .../admin/bulk_product_update.js.coffee | 8 +- .../directives/taxon_autocomplete.js.coffee | 6 +- .../admin/services/taxons.js.coffee | 5 + .../stylesheets/admin/products.css.scss | 30 +++- .../spree/api/product_serializer.rb | 6 +- .../spree/admin/products/bulk_edit.html.haml | 42 ++--- .../admin/bulk_product_update_spec.rb | 143 ++++++++++-------- .../unit/admin/services/taxons_spec.js.coffee | 9 +- 8 files changed, 144 insertions(+), 105 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 155835a979..1f652a2264 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -11,7 +11,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ unit: {name: "Unit", visible: true} price: {name: "Price", visible: true} on_hand: {name: "On Hand", visible: true} - taxons: {name: "Taxons", visible: false} + category: {name: "Category", visible: false} available_on: {name: "Available On", visible: false} $scope.variant_unit_options = VariantUnitManager.variantUnitOptions() @@ -328,7 +328,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.displaySuccess = -> - $scope.setMessage $scope.updateStatusMessage, "Changes Saved.", + $scope.setMessage $scope.updateStatusMessage, "Changes saved.", color: "green" , 3000 @@ -394,8 +394,8 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("on_hand") and filteredVariants.length == 0 #only update if no variants present filteredProduct.on_hand = product.on_hand hasUpdatableProperty = true - if product.hasOwnProperty("taxon_ids") - filteredProduct.taxon_ids = product.taxon_ids + if product.hasOwnProperty("category") + filteredProduct.primary_taxon_id = product.category hasUpdatableProperty = true if product.hasOwnProperty("available_on") filteredProduct.available_on = product.available_on diff --git a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee index 0a1c01d38f..5f17a0d1dd 100644 --- a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee +++ b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee @@ -4,10 +4,10 @@ angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) -> link: (scope,element,attrs,ngModel) -> setTimeout -> element.select2 - placeholder: Spree.translations.taxon_placeholder - multiple: true + placeholder: "Category" + multiple: false initSelection: (element, callback) -> - callback Taxons.findByIDs(element.val()) + callback Taxons.findByID(scope.product.category) query: (query) -> query.callback { results: Taxons.findByTerm(query.term) } formatResult: (taxon) -> diff --git a/app/assets/javascripts/admin/services/taxons.js.coffee b/app/assets/javascripts/admin/services/taxons.js.coffee index 46a973713c..6944fe132f 100644 --- a/app/assets/javascripts/admin/services/taxons.js.coffee +++ b/app/assets/javascripts/admin/services/taxons.js.coffee @@ -3,6 +3,11 @@ angular.module("ofn.admin").factory "Taxons", (taxons, $filter) -> constructor: -> @taxons = taxons + # For finding a single Taxon + findByID: (id) -> + $filter('filter')(@taxons, {id: id}, true)[0] + + # For finding multiple Taxons represented by comma delimited string findByIDs: (ids) -> taxon for taxon in @taxons when taxon.id.toString() in ids.split(",") diff --git a/app/assets/stylesheets/admin/products.css.scss b/app/assets/stylesheets/admin/products.css.scss index 9071aee41e..17e9af224e 100644 --- a/app/assets/stylesheets/admin/products.css.scss +++ b/app/assets/stylesheets/admin/products.css.scss @@ -30,9 +30,33 @@ th.left-actions, td.left-actions { table#listing_products.bulk { clear: both; - td.supplier { - select { - width: 125px; + colgroup col { + &.producer { + width: 18%; + } + &.name { + width: 18%; + } + &.unit { + width: 14%; + } + &.display_as { + width: 12%; + } + &.price { + width: 10%; + } + &.on_hand { + width: 10%; + } + &.category { + width: 15%; + } + &.available_on { + width: 15%; + } + &.actions { + width: 3%; } } diff --git a/app/serializers/spree/api/product_serializer.rb b/app/serializers/spree/api/product_serializer.rb index cc48b30929..aa8919f8d6 100644 --- a/app/serializers/spree/api/product_serializer.rb +++ b/app/serializers/spree/api/product_serializer.rb @@ -1,17 +1,13 @@ class Spree::Api::ProductSerializer < ActiveModel::Serializer attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand - attributes :taxon_ids, :on_hand, :price, :available_on, :permalink_live + attributes :on_hand, :price, :available_on, :permalink_live has_one :supplier, key: :producer, embed: :id has_one :primary_taxon, key: :category, embed: :id has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids has_one :master, serializer: Spree::Api::VariantSerializer - def taxon_ids - object.taxons.map{ |t| t.id }.join(",") - end - def on_hand object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand" end diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index 4101109267..75c5040a3d 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -25,7 +25,7 @@ %br %select{ :class => "four columns alpha", :id => 'producer_filter', 'ofn-select2-min-search' => 5, 'ng-model' => 'producerFilter', 'ng-options' => 'producer.id as producer.name for producer in filterProducers' } .filter_select{ :class => "four columns" } - %label{ :for => 'taxon_filter' }Category + %label{ :for => 'category_filter' }Category %br %select{ :class => "four columns alpha", :id => 'category_filter', 'ofn-select2-min-search' => 5, 'ng-model' => 'categoryFilter', 'ng-options' => 'taxon.id as taxon.name for taxon in filterTaxons'} %div{ :class => "one column" }   @@ -34,12 +34,6 @@ %br %input.fullwidth{ :type => 'button', :id => 'clear_all_filters', :value => "Clear Filters", 'ng-click' => "resetSelectFilters()" } %hr.sixteen.columns.alpha - %div{ 'ng-show' => '!spree_api_key_ok' } - {{ api_error_msg }} - %div.sixteen.columns.alpha.loading{ 'ng-show' => 'loading' } - %h4 Loading Products... - %div.sixteen.columns.alpha{ 'ng-show' => '!loading && products.length == 0' } - %h4{ :style => 'color:red;' } No matching products found. %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 0', style: "margin-bottom: 10px" } %div.four.columns.alpha %input.four.columns.alpha{ :type => 'button', :value => 'Save Changes', 'ng-click' => 'submitProducts()'} @@ -54,18 +48,24 @@ %div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "column in columns", 'ofn-toggle-column' => true } %span{ :class => 'one column alpha', :style => 'text-align: center'} {{ column.visible && "✓" || !column.visible && " " }} %span{ :class => 'two columns omega' } {{column.name }} - %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 0' } + %div{ 'ng-show' => '!spree_api_key_ok' } + {{ api_error_msg }} + %div.sixteen.columns.alpha.loading{ 'ng-show' => 'loading' } + %h4 Loading Products... + %div.sixteen.columns.alpha{ 'ng-show' => '!loading && filteredProducts.length == 0' } + %h4{ :style => 'color:red;' } No products found. + %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || filteredProducts.length == 0' } %table.index#listing_products.bulk{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1" } %colgroup %col.actions - %col.producer{ 'style' => 'width: 14%;', 'ng-show' => 'columns.producer.visible' } - %col.name{ 'style' => 'width: 20%;', 'ng-show' => 'columns.name.visible' } - %col.unit{ 'style' => 'width: 14%;', 'ng-show' => 'columns.unit.visible' } - %col.display_as{ 'style' => 'width: 12%;', 'ng-show' => 'columns.unit.visible' } - %col.price{ 'style' => 'width: 10%;', 'ng-show' => 'columns.price.visible'} - %col.on_hand{ 'style' => 'width: 10%;', 'ng-show' => 'columns.on_hand.visible' } - %col.taxons{ 'ng-show' => 'columns.taxons.visible' } - %col.available_on{ 'ng-show' => 'columns.available_on.visible' } + %col.producer{ ng: { show: 'columns.producer.visible' } } + %col.name{ ng: { show: 'columns.name.visible' } } + %col.unit{ ng: { show: 'columns.unit.visible' } } + %col.display_as{ ng: { show: 'columns.unit.visible' } } + %col.price{ ng: { show: 'columns.price.visible'} } + %col.on_hand{ ng: { show: 'columns.on_hand.visible' } } + %col.category{ ng: { show: 'columns.category.visible' } } + %col.available_on{ ng: { show: 'columns.available_on.visible' } } %col.actions %col.actions %col.actions @@ -79,7 +79,7 @@ %th.display_as{ 'ng-show' => 'columns.unit.visible' } Display As %th.price{ 'ng-show' => 'columns.price.visible' } Price %th.on_hand{ 'ng-show' => 'columns.on_hand.visible' } On Hand - %th.taxons{ 'ng-show' => 'columns.taxons.visible' } Taxons + %th.category{ 'ng-show' => 'columns.category.visible' } Category %th.available_on{ 'ng-show' => 'columns.available_on.visible' } Av. On %th.actions %th.actions @@ -90,7 +90,7 @@ %a{ 'ofn-toggle-variants' => 'true', :class => "view-variants icon-chevron-right", 'ng-show' => 'hasVariants(product)' } %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "!hasVariants(product) && hasUnit(product)" } %td.producer{ 'ng-show' => 'columns.producer.visible' } - %select.select2{ 'ng-model' => 'product.producer', :name => 'producer', 'ofn-track-product' => 'producer', 'ng-options' => 'producer.id as producer.name for producer in producers' } + %select.select2.fullwidth{ 'ng-model' => 'product.producer', :name => 'producer', 'ofn-track-product' => 'producer', 'ng-options' => 'producer.id as producer.name for producer in producers' } %td.name{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => "product.name", :name => 'product_name', 'ofn-track-product' => 'name', :type => 'text' } %td.unit{ 'ng-show' => 'columns.unit.visible' } @@ -105,8 +105,8 @@ %td.on_hand{ 'ng-show' => 'columns.on_hand.visible' } %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } - %td{ 'ng-if' => 'columns.taxons.visible' } - %input.fullwidth{ :type => 'text', 'ng-model' => 'product.taxon_ids', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'taxon_ids' } + %td.category{ 'ng-if' => 'columns.category.visible' } + %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category", 'ng-model' => 'product.category', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category' } %td.available_on{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions @@ -131,7 +131,7 @@ %td{ 'ng-show' => 'columns.on_hand.visible' } %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-hide' => 'variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } %span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-show' => 'variant.on_demand' } - %td{ 'ng-show' => 'columns.taxons.visible' } + %td{ 'ng-show' => 'columns.category.visible' } %td{ 'ng-show' => 'columns.available_on.visible' } %td.actions %a{ 'ng-click' => 'editWarn(product,variant)', :class => "edit-variant icon-edit no-text", 'ng-show' => "variantSaved(variant)" } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 5beac13e0e..11c82eed58 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -25,7 +25,7 @@ feature %q{ it "displays a message when number of products is zero" do visit '/admin/products/bulk_edit' - expect(page).to have_text "No matching products found." + expect(page).to have_text "No products found." end it "displays a select box for suppliers, with the appropriate supplier selected" do @@ -266,8 +266,8 @@ feature %q{ fill_in "variant_display_as", with: "Case" fill_in "variant_price", with: "4.0" fill_in "variant_on_hand", with: "10" - click_button 'Update' - expect(page.find("span#update-status-message")).to have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." updated_variant = Spree::Variant.where(deleted_at: nil).last expect(updated_variant.display_name).to eq "Case of 12 Bottles" @@ -285,7 +285,9 @@ feature %q{ scenario "updating a product with no variants (except master)" do s1 = FactoryGirl.create(:supplier_enterprise) s2 = FactoryGirl.create(:supplier_enterprise) - p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1) + t1 = FactoryGirl.create(:taxon) + t2 = FactoryGirl.create(:taxon) + p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2) p.price = 10.0 p.on_hand = 6; p.save! @@ -296,24 +298,30 @@ feature %q{ first("div#columns_dropdown", :text => "COLUMNS").click first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click + first("div#columns_dropdown div.menu div.menu_item", text: "Category").click - expect(page).to have_field "product_name", with: p.name - expect(page).to have_select "producer", selected: s1.name - expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T") - expect(page).to have_field "price", with: "10.0" - expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" - expect(page).to have_field "on_hand", with: "6" + within "tr#p_#{p.id}" do + expect(page).to have_field "product_name", with: p.name + expect(page).to have_select "producer", selected: s1.name + expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T") + expect(page).to have_field "price", with: "10.0" + save_screenshot '/Users/rob/Desktop/ss.png' + expect(page).to have_selector "div#s2id_p#{p.id}_category a.select2-choice" + expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" + expect(page).to have_field "on_hand", with: "6" - fill_in "product_name", with: "Big Bag Of Potatoes" - select(s2.name, :from => 'producer') - fill_in "available_on", with: (Date.today-3).strftime("%F %T") - fill_in "price", with: "20" - select "Weight (kg)", from: "variant_unit_with_scale" - fill_in "on_hand", with: "18" - fill_in "display_as", with: "Big Bag" + fill_in "product_name", with: "Big Bag Of Potatoes" + select s2.name, :from => 'producer' + fill_in "available_on", with: (Date.today-3).strftime("%F %T") + fill_in "price", with: "20" + select "Weight (kg)", from: "variant_unit_with_scale" + select2_select t1.name, from: "p#{p.id}_category" + fill_in "on_hand", with: "18" + fill_in "display_as", with: "Big Bag" + end - click_button 'Update' - expect(page.find("span#update-status-message")).to have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload expect(p.name).to eq "Big Bag Of Potatoes" @@ -324,6 +332,7 @@ feature %q{ expect(p.master.display_as).to eq "Big Bag" expect(p.price).to eq 20.0 expect(p.on_hand).to eq 18 + expect(p.primary_taxon).to eq t1 end scenario "updating a product with a variant unit of 'items'" do @@ -338,13 +347,13 @@ feature %q{ select "Items", from: "variant_unit_with_scale" fill_in "variant_unit_name", with: "loaf" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.variant_unit.should == "items" - p.variant_unit_scale.should be_nil - p.variant_unit_name.should == "loaf" + expect(p.variant_unit).to eq "items" + expect(p.variant_unit_scale).to be_nil + expect(p.variant_unit_name).to eq "loaf" end scenario "setting a variant unit on a product that has none" do @@ -361,15 +370,15 @@ feature %q{ first("a.view-variants").trigger('click') fill_in "variant_unit_value_with_description", with: '123 abc' - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.variant_unit.should == "weight" - p.variant_unit_scale.should == 1000 # Kg + expect(p.variant_unit).to eq "weight" + expect(p.variant_unit_scale).to eq 1000 # Kg v.reload - v.unit_value.should == 123000 # 123 kg in g - v.unit_description.should == "abc" + expect(v.unit_value).to eq 123000 # 123 kg in g + expect(v.unit_description).to eq "abc" end describe "setting the master unit value for a product without variants" do @@ -386,14 +395,14 @@ feature %q{ select "Weight (kg)", from: "variant_unit_with_scale" fill_in "master_unit_value_with_description", with: '123 abc' - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.variant_unit.should == 'weight' - p.variant_unit_scale.should == 1000 - p.master.unit_value.should == 123000 - p.master.unit_description.should == 'abc' + expect(p.variant_unit).to eq 'weight' + expect(p.variant_unit_scale).to eq 1000 + expect(p.master.unit_value).to eq 123000 + expect(p.master.unit_description).to eq 'abc' end it "does not show the field when the product has variants" do @@ -434,14 +443,14 @@ feature %q{ expect(page).to have_selector "span[name='on_hand']", text: "10" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." v.reload - v.price.should == 4.0 - v.on_hand.should == 10 - v.unit_value.should == 2 # 2L in L - v.unit_description.should == "(8x250 mL bottles)" + expect(v.price).to eq 4.0 + expect(v.on_hand).to eq 10 + expect(v.unit_value).to eq 2 # 2L in L + expect(v.unit_description).to eq "(8x250 mL bottles)" end scenario "updating delegated attributes of variants in isolation" do @@ -458,11 +467,11 @@ feature %q{ fill_in "variant_price", with: "10.0" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." v.reload - v.price.should == 10.0 + expect(v.price).to eq 10.0 end scenario "updating a product mutiple times without refresh" do @@ -475,24 +484,24 @@ feature %q{ fill_in "product_name", with: "new name 1" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.name.should == "new name 1" + expect(p.name).to eq "new name 1" fill_in "product_name", with: "new name 2" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.name.should == "new name 2" + expect(p.name).to eq "new name 2" fill_in "product_name", with: "original name" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.name.should == "original name" + expect(p.name).to eq "original name" end scenario "updating a product after cloning a product" do @@ -505,10 +514,10 @@ feature %q{ fill_in "product_name", :with => "new product name" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload - p.name.should == "new product name" + expect(p.name).to eq "new product name" end scenario "updating when no changes have been made" do @@ -518,8 +527,8 @@ feature %q{ visit '/admin/products/bulk_edit' - click_button 'Update' - page.find("span#update-status-message").should have_content "No changes to update." + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "No changes to update." end end @@ -537,10 +546,10 @@ feature %q{ expect(page).to have_no_field "product_name", with: p2.name fill_in "product_name", :with => "new product1" - click_on 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p1.reload - p1.name.should == "new product1" + expect(p1.name).to eq "new product1" end describe "using action buttons" do @@ -607,7 +616,7 @@ feature %q{ first("a.edit-product").click end - URI.parse(current_url).path.should == "/admin/products/#{p1.permalink}/edit" + expect(URI.parse(current_url).path).to eq "/admin/products/#{p1.permalink}/edit" end it "shows an edit button for variants, which takes the user to the standard edit page for that variant" do @@ -626,7 +635,7 @@ feature %q{ first("a.edit-variant").click end - URI.parse(current_url).path.should == "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" + expect(URI.parse(current_url).path).to eq "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" end end @@ -710,7 +719,7 @@ feature %q{ expect(page).to have_no_field "product_name", with: p2.name # Clearing filters - click_button "Clear All" + click_button "Clear Filters" # All products are shown again expect(page).to have_field "product_name", with: p1.name @@ -781,8 +790,8 @@ feature %q{ fill_in "on_hand", with: "18" fill_in "display_as", with: "Big Bag" - click_button 'Update' - expect(page.find("span#update-status-message")).to have_content "Update complete" + click_button 'Save Changes' + expect(page.find("div#update-status-message")).to have_content "Changes saved." p.reload expect(p.name).to eq "Big Bag Of Potatoes" diff --git a/spec/javascripts/unit/admin/services/taxons_spec.js.coffee b/spec/javascripts/unit/admin/services/taxons_spec.js.coffee index 4c69052b38..9dd22935d5 100644 --- a/spec/javascripts/unit/admin/services/taxons_spec.js.coffee +++ b/spec/javascripts/unit/admin/services/taxons_spec.js.coffee @@ -12,7 +12,12 @@ describe "Taxons service", -> $resource = _$resource_ $httpBackend = _$httpBackend_ - describe "calling findByIDs", -> + describe "findByID", -> + it "returns the taxon with exactly matching id, ignoring ids which do not exactly match", -> + result = Taxons.findByID("1") + expect(result).toEqual {id: "1", name: "t1"} + + describe "findByIDs", -> it "returns taxons with exactly matching ids", -> result = Taxons.findByIDs("1,2") expect(result).toEqual [{id: "1", name: "t1"}, {id: "2", name: "t2"}] @@ -21,7 +26,7 @@ describe "Taxons service", -> result = Taxons.findByIDs("1,3") expect(result).toEqual [{id: "1", name: "t1"}] - describe "calling findByTerm", -> + describe "findByTerm", -> it "returns taxons which match partially", -> result = Taxons.findByTerm("t1") expect(result).toEqual [{id: "1", name: "t1"}, {id: "12", name: "t12"}] \ No newline at end of file