Skip to content

Commit

Permalink
Fix CWM::Table#value=
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Nov 29, 2017
1 parent 2192340 commit 8fa79c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/cwm/src/lib/cwm/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def value
# @param id [Object, Array<Object>] selected id, if multiselection? is true
# it require array of ids to select
def value=(id)
Yast::UI.ChangeWidget(Id(widget_id), :SelectedItems, Array[id])
Yast::UI.ChangeWidget(Id(widget_id), :SelectedItems, Array(id))
end

# Replaces content of single cell
Expand Down
19 changes: 18 additions & 1 deletion library/cwm/test/table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require "cwm/rspec"
require "cwm/table"
Yast.import "UI"

describe CWM::Table do
class MyTable < CWM::Table
Expand All @@ -18,8 +19,24 @@ def items
]
end
end
subject { MyTable.new }
subject(:table) { MyTable.new }

include_examples "CWM::Table"
include_examples "CWM::CustomWidget"

describe "#value=" do
context "when called with a single id" do
it "passes an array with only that id to UI.ChangeWidget" do
expect(Yast::UI).to receive(:ChangeWidget).with(anything, anything, [:id])
table.value = :id
end
end

context "when called with an array of ids" do
it "passes the same array to UI.ChangeWidget" do
expect(Yast::UI).to receive(:ChangeWidget).with(anything, anything, [:id1, :id2])
table.value = [:id1, :id2]
end
end
end
end

0 comments on commit 8fa79c3

Please sign in to comment.