Rails 3.1.1でcells-3.7.0 gemで継承を使用すると問題が発生します。バグのように見えますが、よくわかりません。さまざまなパラメーターに応じて表示されるかどうかに関係なく、一連のボタンを備えたサイドバーがあります。ビューからいくつかのロジックを取り出すためにセルを使用しようとしています。継承を除いて、正常に動作します。次のように、すべてのボタンにセルがあります。
class AddCompanyCell < Cell::Rails
def display
render
end
end
class CompanyJobsCell < Cell::Rails
def display(args)
@company = args[:company]
render
end
end
これらのセルの仕様は次のようになります。
describe AddCompanyCell do
context "cell rendering" do
context "rendering display" do
subject { render_cell(:add_company, :display) }
it { should have_link("Add Company", href: "/companies/new") }
end
end
context "cell instance" do
subject { cell(:add_company) }
it { should respond_to(:display) }
end
end
すべての仕様に合格。
明らかに、私は上記のような多くのクラスを持っています。メソッドは 1 つしかありませんdisplay
が、パラメーターの数は可変です。だから、私はそれらすべての親クラスを実装しようとしました:
class GeneralCell < Cell::Rails
def display(args)
args.each do |k,v|
eval("@#{k} = v")
end
render
end
end
すべての仕様は に合格しGeneralCell
ます。しかし、継承を適用しようとすると、次のようになります。
class AddCompanyCell < GeneralCell
end
render_cell を呼び出すと失敗します:
Failure/Error: subject { render_cell(:add_company, :display, opts: {}) }
AbstractController::ActionNotFound:
The action 'display' could not be found for AddCompanyCell
AddCompanyCell ( should respond_to(:display)
) の 2 番目のテストに合格することに注意してください。変。何か案は?