Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #20995: Reject components from the same CV #6961

Merged
merged 1 commit into from Sep 25, 2017
Merged

Fixes #20995: Reject components from the same CV #6961

merged 1 commit into from Sep 25, 2017

Conversation

akofink
Copy link
Member

@akofink akofink commented Sep 20, 2017

Validate that components being added to a composite content view are
versions of distinct content views

@theforeman-bot
Copy link

Issues: #20995

{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }
let(:version2) { content_view_version.new(id = 4, content_view_id = 1) }
let(:version3) { content_view_version.new(id = 5, content_view_id = 2) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }
let(:version2) { content_view_version.new(id = 4, content_view_id = 1) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

describe "#check_component_content_views_unique" do
let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression at 12, 69 should be on its own line.


describe "#check_component_content_views_unique" do
let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.
Block body expression is on the same line as the block start.

describe ContentView do
describe "validation" do
let(:content_view) { ContentView.new }
let(:composite_content_view) { content_view.composite = true; content_view }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use semicolons to terminate expressions.

{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }
let(:version2) { content_view_version.new(id = 4, content_view_id = 1) }
let(:version3) { content_view_version.new(id = 5, content_view_id = 2) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }
let(:version2) { content_view_version.new(id = 4, content_view_id = 1) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }
let(:version1) { content_view_version.new(id = 3, content_view_id = 1) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - id.
Useless assignment to variable - content_view_id.

describe "#check_component_content_views_unique" do
let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},
{content_view_version_id: version2.id}] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression at 12, 69 should be on its own line.


describe "#check_component_content_views_unique" do
let(:content_view_version) { Struct.new(:id, :content_view_id) }
let(:components) { [{content_view_version_id: version1.id},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.
Block body expression is on the same line as the block start.

describe ContentView do
describe "validation" do
let(:content_view) { ContentView.new }
let(:composite_content_view) { content_view.composite = true; content_view }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use semicolons to terminate expressions.

@parthaa parthaa self-assigned this Sep 20, 2017
@parthaa
Copy link
Contributor

parthaa commented Sep 20, 2017

@akofink as per our earlier discussion I am wondering if this logic is better added in content view component instead of ContentView model itself. The reason I say this is because this validation is about the relationship between 2 content views. Can you figure out why this did not get triggered
https://github.com/Katello/katello/blob/master/app/models/katello/content_view_component.rb#L45
because that is the entire purpose of that check..

@parthaa
Copy link
Contributor

parthaa commented Sep 20, 2017

More over. This call should ve failed on master https://github.com/Katello/katello/blob/master/app/models/katello/content_view.rb#L104
Considering https://github.com/Katello/katello/blob/master/app/models/katello/content_view_component.rb#L45 specifically checks for it.. I am guessing we are doing something wrong here.

@akofink
Copy link
Member Author

akofink commented Sep 21, 2017

@parthaa I fixed the content view component validation. I'm still not convinced the component is the best place to put this validation, but it does work. One thing to note, when the error occurs, you always receive two error messages because there are two components with the same content view:

Could not update the content view:
  Validation failed: Content view components is invalid, Content view components is invalid

Also, as you can see, the error message is generic rather than the expected message of Duplicate Content View. Another component already includes this view

Validate that components being added to a composite content view are
versions of distinct content views
@akofink
Copy link
Member Author

akofink commented Sep 21, 2017

@parthaa I'm fine with merging as is after your review

@parthaa
Copy link
Contributor

parthaa commented Sep 22, 2017

@akofink ack to this. I am totally ok merging this. But if you have reservations.
PS:

  • Do you have a parallel branch with the previous version. If you prefer I can run that once more and give a green light.
  • Alternatively if liked this but wanted a better error message - (may be we can customize the message to include the name or id of the component)
    The above 2 options are optional ...

@akofink
Copy link
Member Author

akofink commented Sep 22, 2017

Let's merge as is.

@parthaa parthaa merged commit 30880d0 into Katello:master Sep 25, 2017
@akofink akofink deleted the 20995 branch September 25, 2017 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants