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

[1845] prevent assets from being registered multiple times #2139

Merged
merged 1 commit into from
Apr 26, 2013
Merged

[1845] prevent assets from being registered multiple times #2139

merged 1 commit into from
Apr 26, 2013

Conversation

seanlinsley
Copy link
Contributor

JavaScript and CSS registrations are now stored inside a Set and a
Hash, respectively, to ensure that no duplicates are created.

For #1845

end

it "should clear all existing stylesheets" do
MockRegistration.register_stylesheet "active_admin.css"
MockRegistration.stylesheets.length.should == 1
MockRegistration.clear_stylesheets!
MockRegistration.stylesheets.length.should == 0
MockRegistration.stylesheets.length.should be_empty
Copy link
Contributor

Choose a reason for hiding this comment

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

Think you want the following instead, as this spec fails:

MockRegistration.stylesheets.should be_empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, yes I did.

JavaScript and CSS registrations are now stored inside a Set and a
Hash, respectively, to ensure that no duplicates are created.
@seanlinsley
Copy link
Contributor Author

Okay, passing now. Look good to you @macfanatic?

@macfanatic
Copy link
Contributor

Love it. This was actually one of the first, if not the first, bits of code I contributed to AA. :)

macfanatic added a commit that referenced this pull request Apr 26, 2013
[1845] prevent assets from being registered multiple times
@macfanatic macfanatic merged commit e872ff1 into activeadmin:master Apr 26, 2013
@seanlinsley seanlinsley deleted the bugfix/1845-asset-registration branch April 26, 2013 00:21
@seanlinsley
Copy link
Contributor Author

Oh yeah how about that!

macfanatic_contrib

Have you used a Set before? I ❤️ them cause they give you performance and uniqueness.

A Set is stored as a Hash where for each element the key is your value, and the value is true

@macfanatic
Copy link
Contributor

I've seen set, but didn't know why you would use one over a Hash.

@seanlinsley
Copy link
Contributor Author

For practical purposes, a Set is an Array with guaranteed uniqueness. It behaves just like an Array, it's just that the back-end object that everything is stored in is a Hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants